[PEAR-BUG] Bug #20330 [Fbk->Csd]: Invalid scope spacing rule for PSR-2

[email protected]
Newsgroups php.pear.bugs
Message-ID <[email protected]>
Edit report at https://pear.php.net/bugs/bug.php?id=20330&edit=1

 ID:               20330
 Updated by:       [email protected]
 Reported By:      git at duncanc dot co dot uk
 Summary:          Invalid scope spacing rule for PSR-2
-Status:           Feedback
+Status:           Closed
 Type:             Bug
 Package:          PHP_CodeSniffer
 Package Version:  1.5.3
 PHP Version:      5.5.11
 Assigned To:      squiz
 Roadmap Versions: 
 New Comment:

-Status: Feedback
+Status: Closed



Previous Comments:
------------------------------------------------------------------------

[2014-07-07 11:20:13] squiz

-Status: Wont fix
+Status: Feedback
PHPCS only infers rules from the examples because that's what the
standard 
specifically asks for. Yes, it would have been nicer if the standard
listed every point 
out in text, but using examples is not that uncommon.

Even so, I'm not involved with the PHP FIG in official capacity and I
don't speak on 
their behalf. If you think I am incorrect interpreting the standard, or
you just want 
clarification, you can ask on the mailing list here: 
https://groups.google.com/forum/#!forum/php-fig-cs

They may be able to clarify the intention of the standard there, or even
produce 
some errata to make things easier to understand.

If you do post, feel free to point people here, where I've described why
PHPCS acts 
as it does. If not, you can always create a custom standard based on
PSR2 that 
mutes the specific errors that you do not want. If you'd like to do that
and need 
help, let me know.

------------------------------------------------------------------------

[2014-07-07 10:47:04] duncan3dc

-Status: Feedback
+Status: Wont fix
I'd prefer phpcs didn't infer rules from examples, and only followed
explicit rules, but I see where you are coming from. Thanks for the
quick response

------------------------------------------------------------------------

[2014-07-07 08:38:05] squiz

-Status:      Open
+Status:      Feedback
-Assigned To:
+Assigned To: squiz
The PSR2 standard uses examples in places to define some of its rules.
The 
relevant section in this case is the example in 4.3 Methods
(https://github.com/php-
fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md#43-
methods).

The example shows how a method should be defined. Notice that the text
says 
(emphasis is mine):

"A method declaration looks like the following. Note the placement of
parentheses, 
commas, *spaces*, and braces"

So in this case, you are absolutely write that the standard doesn't list
the "single 
space after visibility keyword" as a rule somewhere. But it does use the
example 
code to cover a range of formatting rules that are also supposed to be
enforced. 
The use of the language "looks like the following" also turns these
rules into errors 
instead of warnings as they are strict requirements instead of optional.

------------------------------------------------------------------------

[2014-07-04 16:32:41] duncan3dc

Description:
------------
When using the PSR-2 standard, the following ERROR is reported:
Scope keyword "public" must be followed by a single space
But I cannot find any mention of this in the PSR-2 standard below:
http://www.php-fig.org/psr/psr-2/

Test script:
---------------
<?php

namespace Test\Example;

class ExampleClass
{
    public  $property;
}


Expected result:
----------------
No warnings or errors reported

Actual result:
--------------
FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 7 | ERROR | Scope keyword "public" must be followed by a single space
--------------------------------------------------------------------------------

------------------------------------------------------------------------


-- 
Edit this bug report at https://pear.php.net/bugs/bug.php?id=20330&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.