This repository was archived by the owner on Nov 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Use statements must be used #14
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
db9c8b0
Use statements must be used
thewilkybarkid cad6ebe
Use namespaced reference
thewilkybarkid e91a530
Update minimum slevomat/coding-standard
thewilkybarkid 4f4141c
Heh, had missed one
thewilkybarkid a0a9a48
Merge branch 'master' into require-use
thewilkybarkid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| ---DESCRIPTION--- | ||
| No global fallbacks | ||
| ---CONTENTS--- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Vendor; | ||
|
|
||
| date(DATE_ATOM); | ||
|
|
||
| ---FIXED--- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Vendor; | ||
|
|
||
| use function date; | ||
| use const DATE_ATOM; | ||
|
|
||
| date(DATE_ATOM); | ||
|
|
||
| --- | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| ---DESCRIPTION--- | ||
| Use statements must be used | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for classes, this is expected |
||
| ---CONTENTS--- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Vendor; | ||
|
|
||
| new \Foo(\bar(\BAZ)); | ||
| new \Qux\Quux(\Qux\quuz(\Qux\CORGE)); | ||
| new \Vendor\Grault(\Vendor\garply(\Vendor\WALDO)); | ||
|
|
||
| ---FIXED--- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Vendor; | ||
|
|
||
| use Foo; | ||
| use Qux\Quux; | ||
| use function bar; | ||
| use function Qux\quuz; | ||
| use const BAZ; | ||
| use const Qux\CORGE; | ||
|
|
||
| new Foo(bar(BAZ)); | ||
| new Quux(quuz(CORGE)); | ||
| new Grault(garply(WALDO)); | ||
|
|
||
| --- | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| ---DESCRIPTION--- | ||
| Use statements must not be from the same namespace | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good practice |
||
| ---CONTENTS--- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Foo; | ||
|
|
||
| use Foo\Bar; | ||
| use function Foo\baz; | ||
| use const Foo\QUX; | ||
|
|
||
| new Bar(baz(QUX)); | ||
|
|
||
| ---FIXED--- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Foo; | ||
|
|
||
| new Bar(baz(QUX)); | ||
|
|
||
| --- | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see this becoming annoying for many PHP functions e.g. all
strlenand similar which gets used everywhere. Even Java auto-importjava.langto avoid too many imports. PHP provides the fallback too for functions (but not for classes IIRC).If anything I would forbid defining a
strlenthat is not\strlen, which tries to avoid the ambiguity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some functions get a very-minor performance boost by not checking the fallback. But more importantly prevents https://www.giorgiosironi.com/2010/09/monkey-patching-in-php.html (as used by Symfony's
ClockMock).Might be annoying when not using an IDE though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try it out, we can always reverse it if needed.
(It's in use at https://github.com/doctrine/doctrine2/blob/b40c2c6b7893c929f754150d480c20f9b22e0afe/lib/Doctrine/ORM/Mapping/Factory/Strategy/FileWriterClassMetadataGeneratorStrategy.php#L9-L17 if you want to try your editor.)