- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2
 
Use statements must be used #14
Changes from 1 commit
db9c8b0
              cad6ebe
              e91a530
              4f4141c
              a0a9a48
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
| 
     | 
||
| --- | ||
| 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)); | ||
| 
     | 
||
| --- | ||
| 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)); | ||
| 
     | 
||
| --- | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -11,6 +11,13 @@ namespace Vendor; | |
| 
     | 
||
| new Foo(); | ||
| 
     | 
||
| ---MESSAGES--- | ||
| 5:1 PSR2.Namespaces.UseDeclaration.UseBeforeNamespace | ||
| ---FIXED--- | ||
| <?php | ||
| 
     | 
||
| declare(strict_types=1); | ||
| 
     | 
||
| namespace Vendor; | ||
| 
     | 
||
| new Foo(); | ||
                
       | 
||
| 
     | 
||
| --- | ||
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.)