Hi Greg,
I would interpret the standard as requiring one blank line after the last use statement.
I would find it too restrictive to forbid blank lines between use statements.
Nico
>
> --
> You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
> To post to this group, send email to php...@googlegroups.com.
> To unsubscribe from this group, send email to php-fig+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/wV6iafUrH2YJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
I would interpret the standard as requiring one blank line after the last use statement.
I'm finishing off the PSR-2 coding standard for PHP_CodeSniffer but have come across something a little ambiguous. I'm not sure exactly what errors to report for one of the namespace rules, so I'm hoping others can help with a decision.
The PSR-2 standard says "There MUST be one blank line after the use block". This, along with the sample code, seems to indiciate that all USE statements must be together in a single block of code with no spacing between each.
But PSR-2 does not specifically say this or define what a "USE block" is. It also doesn't say to refer to the sample code for spacing, as it does with some other code samples.
When present, there MUST be one blank line after the namespace declaration.
When present, all use declarations MUST go after the namespace declaration.
There MUST be one use keyword per declaration.
There MUST be one blank line after the use block.
For example:
<?php namespace Vendor\Package; use FooClass; use BarClass as Bar; use OtherVendor\OtherPackage\BazClass; // ... additional PHP code ...
So, taking a code sample from the PHP manual, is this valid code or should it generate errors on lines 3 and 6 for having additional lines between USE statements?1. <?php
2. namespace foo;
3. use My\Full\Classname as Another;
4.
5. // this is the same as use My\Full\NSname as NSname
6. use My\Full\NSname;
7.
8. // importing a global class
9. use ArrayObject;
You could also have something like this, where USE statements are grouped and commented on together. Is this valid or should it generate an error on line 6 for having additional lines between USE statements?
1. <?php
2. namespace foo;3.4. // Comment here.5. use My\Full\Classname as Another;6. use My\Full\NSname;7.8. // importing a global class
9. use ArrayObject;Both these would be valid if the standard was interpreted as "USE statements must be followed by another USE statement or a single blank line" but I'm not sure if this is what the standard intends.
Any help greatly appreciated.
I would interpret the standard as requiring one blank line after the last use statement.
use block.Thanks for replying. If that's the case, I wonder if there are any restrictions on the spacing between use statements. Is this valid?5. use My\Full\NSname;1. <?php
2. namespace foo;
3. use My\Full\Classname as Another;
4.
6.7. use ArrayObject;And is this valid?
1. <?php
2. namespace foo;
3. use My\Full\Classname as Another;
4.5.
6. use My\Full\NSname;
7.8.9. use ArrayObject;Sorry if this all looks a bit silly. It's just that there are no grey areas in an automated tool, so I need to think about all the different bits of code that PHP_CodeSniffer might come across and make sure I have a clear goal of what the code should look like.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group, send email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/DytviBB2Z10J.
You can define have as many use statements as you want in the same
block, you can put as many fancy comments in it, they don't count as
actual code.
"
<?php
namespace foo;
use Something;
use SomethingElse;
// Comments here
use AnotherThing;
[ important space after the _last_ use statement, defining the end of
the _use block_ ]
class Foo {
}
use block.">> > php-fig+unsubscribe@googlegroups.com.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/php-fig/-/VwJTXISMykEJ.
>> >
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "PHP Framework Interoperability Group" group.
> To post to this group, send email to php...@googlegroups.com.
> To unsubscribe from this group, send email to
> php-fig+unsubscribe@googlegroups.com.
>> php-fig+unsubscribe@googlegroups.com.