Closed PonchoPowers closed 1 year ago
PHPCS is often used within IDEs during live coding, so, generally speaking, it will ignore parse errors. Along the same lines, something which may be a parse error in one PHP version, may not be on another PHP version.
If you want parse errors to be reported, you can add the Generic.PHP.Syntax
sniff to your ruleset, though be aware that it will report based on the PHP version used during the PHPCS scan.
Alternatively, use a dedicated linting tool like PHP Parallel Lint or PHPLint.
I tried adding <rule ref="Generic.PHP.Syntax"/>
and the output didn't change.
This is my config file:
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PSR12" xsi:noNamespaceSchemaLocation="../../../phpcs.xsd">
<description>A custom ruleset based on the PSR-12 coding standard.</description>
<arg name="tab-width" value="4"/>
<rule ref="Generic.PHP.Syntax"/>
<rule ref="PSR1"/>
<rule ref="Generic.Files.LineEndings">
<properties>
<property name="eolChar" value="\n"/>
</properties>
</rule>
<rule ref="PSR2.Files.EndFileNewline"/>
<rule ref="PSR2.Files.ClosingTag"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile">
<severity>0</severity>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile">
<severity>0</severity>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
<severity>0</severity>
</rule>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="ignoreIndentationTokens" type="array">
<element value="T_COMMENT"/>
<element value="T_DOC_COMMENT_OPEN_TAG"/>
</property>
</properties>
</rule>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.PHP.LowerCaseConstant"/>
<rule ref="Generic.PHP.LowerCaseType"/>
<rule ref="PSR2.Classes.ClassDeclaration"/>
<rule ref="PSR2.Classes.PropertyDeclaration"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<type>error</type>
<message>Method name "%s" must not be prefixed with an underscore to indicate visibility</message>
</rule>
<rule ref="PSR2.Methods.FunctionClosingBrace"/>
<rule ref="Squiz.Functions.FunctionDeclaration"/>
<rule ref="Squiz.Functions.LowercaseFunctionKeywords"/>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
</properties>
</rule>
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="PSR2.Methods.FunctionCallSignature"/>
<rule ref="PSR2.Methods.FunctionCallSignature.SpaceAfterCloseBracket">
<severity>0</severity>
</rule>
<rule ref="PSR2.Methods.FunctionCallSignature.OpeningIndent">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration">
<properties>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.LowercaseDeclaration"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.AsNotLower">
<severity>0</severity>
</rule>
<rule ref="PSR2.ControlStructures.ElseIfDeclaration"/>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose">
<severity>0</severity>
</rule>
<rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
</ruleset>
I'm using PHP 8.1 too if it helps.
There must be something wrong with how you're calling PHPCS in that case, as on PHP 8.1 (and other PHP versions), I get the expected error with your code sample:
# phpcs phpcs-3491.php --standard=Generic --sniffs=generic.php.syntax
PHP 8.1.0 (cli) (built: Nov 23 2021 21:48:28) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
PHP_CodeSniffer version 3.6.2 (stable) by Squiz (http://www.squiz.net)
FILE: phpcs-3491.php
-------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------
3 | ERROR | PHP syntax error: syntax error, unexpected identifier "Class2", expecting "{"
-------------------------------------------------------------------------------------------
Also tested with your ruleset:
# phpcs phpcs-3491.php --standard=phpcs-3491.xml
PHP 8.1.0 (cli) (built: Nov 23 2021 21:48:28) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
PHP_CodeSniffer version 3.6.2 (stable) by Squiz (http://www.squiz.net)
FILE: phpcs-3491.php
---------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------
3 | ERROR | [ ] PHP syntax error: syntax error, unexpected identifier "Class2", expecting "{"
3 | ERROR | [ ] Each class must be in a namespace of at least one level (a top-level vendor name)
3 | ERROR | [x] Opening brace of a class must be on the line after the definition
---------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------
I'm calling it from a php script via the command line like so:
php lint.php
The lint.php file is:
function shutdown()
{
echo "Finished static code analysis." . PHP_EOL;
}
register_shutdown_function("shutdown");
if (count($_SERVER["argv"]) < 1)
{
$_SERVER["argv"][] = "../src/";
}
echo "Running static code analysis." . PHP_EOL;
require_once("phpcs.phar");
I've just realised since I added the option to specify the file to lint, the config file is no longer being picked up, my bad sorry, I'll see what is going on there and let you know how I get on thanks.
There must be something up with running it through a PHP script:
C:\Users\Test\source\repos\phpnet\tools>php lint.php ..\src\AMultiClassAndNSTests.php --sniffs=generic.php.syntax3 Running static code analysis. ERROR: No sniffs were registered
Run "phpcs --help" for usage information
Finished static code analysis.
C:\Users\Test\source\repos\phpnet\tools>php lint.php ..\src\AMultiClassAndNSTests.php --sniffs=generic.php.syntax Running static code analysis. Finished static code analysis.
C:\Users\Test\source\repos\phpnet\tools>php lint.php ..\src\AMultiClassAndNSTests.php1 --sniffs=generic.php.syntax Running static code analysis. ERROR: The file "..\src\AMultiClassAndNSTests.php1" does not exist.
Run "phpcs --help" for usage information
Finished static code analysis.
It appears to recognise the sniff and the file, as per the test to pass in an incorrect sniff and file and getting different output. It turned out the config file was working as it should too, so I'm going to have a look at the PHP code to see if I can work out what is going on.
I'm using version 3.6.1 and you are using version 3.6.2, could that be the difference? I'm running on Windows too, not sure if that makes a difference or not?
When I looked at the verbose output, I can see the rulset is listed, the correct file is being parsed, and I can see it was tokenized correctly, but the error messages don't match up with what you get.
Running static code analysis. Processing ruleset C:\Users\Test\source\repos\phpnet\tools\phpcs.xml Processing rule "Generic.PHP.Syntax" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\PHP\SyntaxSniff.php Processing rule "PSR1" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR1\ruleset.xml
- rule is referencing a standard using ruleset path; processing * Processing ruleset phar://C:/php/includes/phpcs.phar\src\Standards\PSR1\ruleset.xml Adding sniff files from phar://C:/php/includes/phpcs.phar\src\Standards\PSR1\Sniffs directory => phar://C:/php/includes/phpcs.phar\src\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff.php => phar://C:/php/includes/phpcs.phar\src\Standards\PSR1\Sniffs\Files\SideEffectsSniff.php => phar://C:/php/includes/phpcs.phar\src\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff.php Processing rule "Generic.PHP.DisallowAlternativePHPTags" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\PHP\DisallowAlternativePHPTagsSniff.php Processing rule "Generic.PHP.DisallowShortOpenTag" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\PHP\DisallowShortOpenTagSniff.php Processing rule "Generic.PHP.DisallowShortOpenTag.EchoFound" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\PHP\DisallowShortOpenTagSniff.php => severity set to 0 Processing rule "Generic.Files.ByteOrderMark" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\Files\ByteOrderMarkSniff.php Processing rule "Squiz.Classes.ValidClassName" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\Classes\ValidClassNameSniff.php Processing rule "Generic.NamingConventions.UpperCaseConstantName" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff.php => Ruleset processing complete; included 8 sniffs and excluded 0 Processing rule "Generic.Files.LineEndings" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\Files\LineEndingsSniff.php => property "eolChar" set to "\n" Processing rule "PSR2.Files.EndFileNewline" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\Files\EndFileNewlineSniff.php Processing rule "PSR2.Files.ClosingTag" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\Files\ClosingTagSniff.php Processing rule "Generic.Files.LineLength" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\Files\LineLengthSniff.php => property "lineLimit" set to "120" => property "absoluteLineLimit" set to "0" Processing rule "Squiz.WhiteSpace.SuperfluousWhitespace" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff.php Processing rule "Squiz.WhiteSpace.SuperfluousWhitespace.StartFile" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff.php => severity set to 0 Processing rule "Squiz.WhiteSpace.SuperfluousWhitespace.EndFile" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff.php => severity set to 0 Processing rule "Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff.php => severity set to 0 Processing rule "Generic.WhiteSpace.ScopeIndent" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\WhiteSpace\ScopeIndentSniff.php => array property "ignoreIndentationTokens" set to "T_COMMENT,T_DOC_COMMENT_OPEN_TAG" Processing rule "Generic.WhiteSpace.DisallowTabIndent" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\WhiteSpace\DisallowTabIndentSniff.php Processing rule "Generic.PHP.LowerCaseKeyword" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\PHP\LowerCaseKeywordSniff.php Processing rule "Generic.PHP.LowerCaseConstant" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\PHP\LowerCaseConstantSniff.php Processing rule "Generic.PHP.LowerCaseType" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\PHP\LowerCaseTypeSniff.php Processing rule "PSR2.Classes.ClassDeclaration" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff.php Processing rule "PSR2.Classes.PropertyDeclaration" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\Classes\PropertyDeclarationSniff.php Processing rule "Squiz.Scope.MethodScope" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\Scope\MethodScopeSniff.php Processing rule "Squiz.WhiteSpace.ScopeKeywordSpacing" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\WhiteSpace\ScopeKeywordSpacingSniff.php Processing rule "PSR2.Methods.MethodDeclaration.Underscore" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\Methods\MethodDeclarationSniff.php Excluding sniff "PSR2.Methods.MethodDeclaration" except for "Underscore" => message type set to error => message set to Method name "%s" must not be prefixed with an underscore to indicate visibility Processing rule "PSR2.Methods.FunctionClosingBrace" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\Methods\FunctionClosingBraceSniff.php Processing rule "Squiz.Functions.FunctionDeclaration" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\Functions\FunctionDeclarationSniff.php Processing rule "Squiz.Functions.LowercaseFunctionKeywords" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\Functions\LowercaseFunctionKeywordsSniff.php Processing rule "Squiz.Functions.FunctionDeclarationArgumentSpacing" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\Functions\FunctionDeclarationArgumentSpacingSniff.php => property "equalsSpacing" set to "1" Processing rule "PEAR.Functions.ValidDefaultValue" => phar://C:/php/includes/phpcs.phar\src\Standards\PEAR\Sniffs\Functions\ValidDefaultValueSniff.php Processing rule "Generic.Functions.FunctionCallArgumentSpacing" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\Functions\FunctionCallArgumentSpacingSniff.php Processing rule "PSR2.Methods.FunctionCallSignature" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff.php Processing rule "PSR2.Methods.FunctionCallSignature.SpaceAfterCloseBracket" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff.php => severity set to 0 Processing rule "PSR2.Methods.FunctionCallSignature.OpeningIndent" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff.php => severity set to 0 Processing rule "Squiz.ControlStructures.ForEachLoopDeclaration" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\ControlStructures\ForEachLoopDeclarationSniff.php Processing rule "Squiz.ControlStructures.ForLoopDeclaration" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\ControlStructures\ForLoopDeclarationSniff.php => property "ignoreNewlines" set to "true" Processing rule "Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\ControlStructures\ForLoopDeclarationSniff.php => severity set to 0 Processing rule "Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\ControlStructures\ForLoopDeclarationSniff.php => severity set to 0 Processing rule "Squiz.ControlStructures.LowercaseDeclaration" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\ControlStructures\LowercaseDeclarationSniff.php Processing rule "Generic.ControlStructures.InlineControlStructure" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\ControlStructures\InlineControlStructureSniff.php Processing rule "Squiz.ControlStructures.ForEachLoopDeclaration.AsNotLower" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\ControlStructures\ForEachLoopDeclarationSniff.php => severity set to 0 Processing rule "PSR2.ControlStructures.ElseIfDeclaration" => phar://C:/php/includes/phpcs.phar\src\Standards\PSR2\Sniffs\ControlStructures\ElseIfDeclarationSniff.php Processing rule "Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\ControlStructures\ForEachLoopDeclarationSniff.php => severity set to 0 Processing rule "Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\ControlStructures\ForEachLoopDeclarationSniff.php => severity set to 0 Processing rule "Generic.WhiteSpace.IncrementDecrementSpacing" => phar://C:/php/includes/phpcs.phar\src\Standards\Generic\Sniffs\WhiteSpace\IncrementDecrementSpacingSniff.php Processing rule "Squiz.WhiteSpace.CastSpacing" => phar://C:/php/includes/phpcs.phar\src\Standards\Squiz\Sniffs\WhiteSpace\CastSpacingSniff.php => set command line value --tab-width=4 => Ruleset processing complete; included 38 sniffs and excluded 0 Registered PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\SyntaxSniff Registered PHP_CodeSniffer\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff Registered PHP_CodeSniffer\Standards\PSR1\Sniffs\Files\SideEffectsSniff Registered PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowAlternativePHPTagsSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowShortOpenTagSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\Files\ByteOrderMarkSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ValidClassNameSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineEndingsSniff Registered PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\EndFileNewlineSniff Registered PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\ClosingTagSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\ScopeIndentSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\DisallowTabIndentSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseKeywordSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseConstantSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseTypeSniff Registered PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff Registered PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\PropertyDeclarationSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope\MethodScopeSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ScopeKeywordSpacingSniff Registered PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\MethodDeclarationSniff Registered PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionClosingBraceSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\FunctionDeclarationSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\LowercaseFunctionKeywordsSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\FunctionDeclarationArgumentSpacingSniff Registered PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions\ValidDefaultValueSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\FunctionCallArgumentSpacingSniff Registered PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\ForEachLoopDeclarationSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\ForLoopDeclarationSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\LowercaseDeclarationSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\ControlStructures\InlineControlStructureSniff Registered PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\ElseIfDeclarationSniff Registered PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\IncrementDecrementSpacingSniff Registered PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\CastSpacingSniff START PHP TOKENIZING Process token [0]: T_OPEN_TAG => <?php Process token [1]: T_FUNCTION => function
- token 3 changed from T_CLOSE_TAG to T_STRING Process token [2]: T_WHITESPACE =>
Process token [3]: T_STRING => ?> END PHP TOKENIZING START PHP TOKENIZING Process token [0]: T_OPEN_TAG => <?php Process token 1 : T_OPEN_PARENTHESIS => ( Process token [2]: T_CLOSE_TAG => ?> END PHP TOKENIZING START PHP TOKENIZING Process token [0]: T_OPEN_TAG => <?php Process token 1 : T_SEMICOLON => ; Process token [2]: T_CLOSE_TAG => ?> END PHP TOKENIZING START PHP TOKENIZING Process token [0]: T_OPEN_TAG => <?php Process token [1]: T_FUNCTION => function- token 3 changed from T_CLOSE_TAG to T_STRING Process token [2]: T_WHITESPACE =>
Process token [3]: T_STRING => ?> END PHP TOKENIZING START PHP TOKENIZING Process token [0]: T_OPEN_TAG => <?php Process token 1 : T_OPEN_PARENTHESIS => ( Process token [2]: T_CLOSE_TAG => ?> END PHP TOKENIZING START PHP TOKENIZING Process token [0]: T_OPEN_TAG => <?php Process token [1]: T_ABSTRACT => abstract Process token [2]: T_WHITESPACE =>
Process token [3]: T_FUNCTION => function- token 5 changed from T_CLOSE_TAG to T_STRING Process token [4]: T_WHITESPACE =>
Process token [5]: T_STRING => ?> END PHP TOKENIZING START PHP TOKENIZING Process token [0]: T_OPEN_TAG => <?php Process token 1 : T_OPEN_PARENTHESIS => ( Process token [2]: T_CLOSE_TAG => ?> END PHP TOKENIZING START PHP TOKENIZING Process token [0]: T_OPEN_TAG => <?php Process token 1 : T_SEMICOLON => ; Process token [2]: T_CLOSE_TAG => ?> END PHP TOKENIZING Creating file list... DONE (1 files in queue) Changing into directory C:\Users\Test\source\repos\phpnet\src Processing AMultiClassAndNSTests.php START PHP TOKENIZING Process token [0]: T_OPEN_TAG => <?php\r\n Process token [1]: T_WHITESPACE => \r\n Process token [2]: T_CLASS => class Process token [3]: T_WHITESPACE =>
Process token [4]: T_STRING => FirstNS Process token [5]: T_WHITESPACE =>
Process token [6]: T_STRING => Class2 Process token [7]: T_WHITESPACE =>
Process token [8]: T_IMPLEMENTS => implements Process token [9]: T_WHITESPACE =>
Process token [10]: T_STRING => ThisIsAnInterface Process token [11]: T_WHITESPACE =>
Process token 12 : T_OPEN_CURLY_BRACKET => { Process token 13 : T_CLOSE_CURLY_BRACKET => } Process token [14]: T_WHITESPACE => \r\n\r\n Process token [15]: T_COMMENT => //namespace First_NS;- stripped first newline after comment and added it to comment token 15 Process token [16]: T_WHITESPACE => \r\n Process token [17]: T_COMMENT => ////namespace First_NS
- merged newline after comment into comment token 17 Process token [19]: T_COMMENT => //// \PartOfFirstNS;
- stripped first newline after comment and added it to comment token 19 Process token [20]: T_WHITESPACE => \r\n Process token [21]: T_COMMENT => //interface ThisIsAnInterface {}
- stripped first newline after comment and added it to comment token 21 Process token [22]: T_WHITESPACE => \r\n Process token [23]: T_COMMENT => //class FirstNS Class implements ThisIsAnInterface {}
- merged newline after comment into comment token 23 Process token [25]: T_COMMENT => //class FirstNSClass2 {}
- stripped first newline after comment and added it to comment token 25 Process token [26]: T_WHITESPACE => \r\n Process token [27]: T_COMMENT => //namespace SecondNS;
- stripped first newline after comment and added it to comment token 27 Process token [28]: T_WHITESPACE => \r\n Process token [29]: T_COMMENT => //class SecondNSClass {}
- stripped first newline after comment and added it to comment token 29 Process token [30]: T_WHITESPACE => \r\n Process token [31]: T_COMMENT => //namespace SecondNS;
- stripped first newline after comment and added it to comment token 31 Process token [32]: T_WHITESPACE => \r\n Process token [33]: T_COMMENT => //class SecondNSClass2 {}
- merged newline after comment into comment token 33 END PHP TOKENIZING START TOKEN MAP => Found curly bracket opener at 12 => Found curly bracket closer at 13 for 12 END TOKEN MAP START SCOPE MAP Start scope map at 2:T_CLASS => class => Begin scope map recursion at token 2 with depth 1 Process token 3 on line 3 []: T_WHITESPACE =>
Process token 4 on line 3 []: T_STRING => FirstNS Process token 5 on line 3 []: T_WHITESPACE =>
Process token 6 on line 3 []: T_STRING => Class2 Process token 7 on line 3 []: T_WHITESPACE =>
Process token 8 on line 3 []: T_IMPLEMENTS => implements Process token 9 on line 3 []: T_WHITESPACE =>
Process token 10 on line 3 []: T_STRING => ThisIsAnInterface Process token 11 on line 3 []: T_WHITESPACE =>
Process token 12 on line 3 []: T_OPEN_CURLY_BRACKET => { => Found scope opener for 2:T_CLASS Process token 13 on line 3 [opener:12;]: T_CLOSE_CURLY_BRACKET => } => Found scope closer (13:T_CLOSE_CURLY_BRACKET) for 2:T_CLASS END SCOPE MAP START LEVEL MAP Process token 0 on line 1 [col:1;len:5;lvl:0;]: T_OPEN_TAG => <?php\r\n Process token 1 on line 2 [col:1;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 2 on line 3 [col:1;len:5;lvl:0;]: T_CLASS => class Process token 3 on line 3 [col:6;len:1;lvl:0;]: T_WHITESPACE =>
Process token 4 on line 3 [col:7;len:7;lvl:0;]: T_STRING => FirstNS Process token 5 on line 3 [col:14;len:1;lvl:0;]: T_WHITESPACE =>
Process token 6 on line 3 [col:15;len:6;lvl:0;]: T_STRING => Class2 Process token 7 on line 3 [col:21;len:1;lvl:0;]: T_WHITESPACE =>
Process token 8 on line 3 [col:22;len:10;lvl:0;]: T_IMPLEMENTS => implements Process token 9 on line 3 [col:32;len:1;lvl:0;]: T_WHITESPACE =>
Process token 10 on line 3 [col:33;len:17;lvl:0;]: T_STRING => ThisIsAnInterface Process token 11 on line 3 [col:50;len:1;lvl:0;]: T_WHITESPACE =>
Process token 12 on line 3 [col:51;len:1;lvl:0;]: T_OPEN_CURLY_BRACKET => { => Found scope opener for 2:T_CLASS- level increased *
- token 2:T_CLASS added to conditions array * Process token 13 on line 3 [col:52;len:1;lvl:1;conds;T_CLASS;]: T_CLOSE_CURLY_BRACKET => } => Found scope closer for 12:T_OPEN_CURLY_BRACKET
- token T_CLASS removed from conditions array *
- level decreased * Process token 14 on line 3 [col:53;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 15 on line 4 [col:1;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 16 on line 5 [col:1;len:21;lvl:0;]: T_COMMENT => //namespace First_NS;\r\n Process token 17 on line 6 [col:1;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 18 on line 7 [col:1;len:22;lvl:0;]: T_COMMENT => ////namespace First_NS\r\n Process token 19 on line 8 [col:1;len:23;lvl:0;]: T_COMMENT => //// \PartOfFirstNS;\r\n Process token 20 on line 9 [col:1;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 21 on line 10 [col:1;len:32;lvl:0;]: T_COMMENT => //interface ThisIsAnInterface {}\r\n Process token 22 on line 11 [col:1;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 23 on line 12 [col:1;len:53;lvl:0;]: T_COMMENT => //class FirstNS Class implements ThisIsAnInterface {}\r\n Process token 24 on line 13 [col:1;len:24;lvl:0;]: T_COMMENT => //class FirstNSClass2 {}\r\n Process token 25 on line 14 [col:1;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 26 on line 15 [col:1;len:21;lvl:0;]: T_COMMENT => //namespace SecondNS;\r\n Process token 27 on line 16 [col:1;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 28 on line 17 [col:1;len:24;lvl:0;]: T_COMMENT => //class SecondNSClass {}\r\n Process token 29 on line 18 [col:1;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 30 on line 19 [col:1;len:21;lvl:0;]: T_COMMENT => //namespace SecondNS;\r\n Process token 31 on line 20 [col:1;len:0;lvl:0;]: T_WHITESPACE => \r\n Process token 32 on line 21 [col:1;len:25;lvl:0;]: T_COMMENT => //class SecondNSClass2 {}\r\n END LEVEL MAP START ADDITIONAL PHP PROCESSING END ADDITIONAL PHP PROCESSING [PHP => 33 tokens in 21 lines]... START TOKEN PROCESSING Process token 0: T_OPEN_TAG => <?php\r\n Processing PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\SyntaxSniff... DONE in 0.0827 seconds Processing PHP_CodeSniffer\Standards\PSR1\Sniffs\Files\SideEffectsSniff... DONE in 0.0001 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowAlternativePHPTagsSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowShortOpenTagSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineEndingsSniff... DONE in 0.0001 seconds Processing PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\EndFileNewlineSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\ClosingTagSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff... DONE in 0.0001 seconds Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\ScopeIndentSniff... DONE in 0.0002 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\DisallowTabIndentSniff... DONE in 0.0001 seconds Process token 1: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 2: T_CLASS => class Processing PHP_CodeSniffer\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ValidClassNameSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseKeywordSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff... DONE in 0.0001 seconds Process token 3: T_WHITESPACE =>
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 4: T_STRING => FirstNS Processing PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\FunctionCallArgumentSpacingSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff... DONE in 0 seconds Process token 5: T_WHITESPACE =>
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 6: T_STRING => Class2 Processing PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\FunctionCallArgumentSpacingSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff... DONE in 0 seconds Process token 7: T_WHITESPACE =>
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 8: T_IMPLEMENTS => implements Processing PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseKeywordSniff... DONE in 0 seconds Process token 9: T_WHITESPACE =>
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 10: T_STRING => ThisIsAnInterface Processing PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\FunctionCallArgumentSpacingSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff... DONE in 0 seconds Process token 11: T_WHITESPACE =>
Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 12: T_OPEN_CURLY_BRACKET => { Process token 13: T_CLOSE_CURLY_BRACKET => } Processing PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\FunctionCallArgumentSpacingSniff... DONE in 0 seconds Processing PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff... DONE in 0 seconds Process token 14: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 15: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 16: T_COMMENT => //namespace First_NS;\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 17: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 18: T_COMMENT => ////namespace First_NS\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 19: T_COMMENT => //// \PartOfFirstNS;\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 20: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 21: T_COMMENT => //interface ThisIsAnInterface {}\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 22: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 23: T_COMMENT => //class FirstNS Class implements ThisIsAnInterface {}\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 24: T_COMMENT => //class FirstNSClass2 {}\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 25: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 26: T_COMMENT => //namespace SecondNS;\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 27: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 28: T_COMMENT => //class SecondNSClass {}\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 29: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 30: T_COMMENT => //namespace SecondNS;\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 31: T_WHITESPACE => \r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds Process token 32: T_COMMENT => //class SecondNSClass2 {}\r\n Processing PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff... DONE in 0 seconds END TOKEN PROCESSING START SNIFF PROCESSING REPORT PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\SyntaxSniff: 0.0827 secs PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff: 0.0003 secs PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\ScopeIndentSniff: 0.0002 secs PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff: 0.0001 secs PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff: 0.0001 secs PHP_CodeSniffer\Standards\PSR1\Sniffs\Files\SideEffectsSniff: 0.0001 secs PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\DisallowTabIndentSniff: 0.0001 secs PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineEndingsSniff: 0.0001 secs PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\FunctionCallArgumentSpacingSniff: 0.0001 secs PHP_CodeSniffer\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff: 0 secs PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff: 0 secs PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ValidClassNameSniff: 0 secs PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\EndFileNewlineSniff: 0 secs PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff: 0 secs PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseKeywordSniff: 0 secs PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowAlternativePHPTagsSniff: 0 secs PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\ClosingTagSniff: 0 secs PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowShortOpenTagSniff: 0 secs END SNIFF PROCESSING REPORT DONE in 88ms (3 errors, 0 warnings)FILE: C:\Users\Test\source\repos\phpnet\src\AMultiClassAndNSTests.php
FOUND 3 ERRORS AFFECTING 2 LINES
1 | ERROR | [x] End of line character is invalid; expected "\n" but | | found "\r\n" 3 | ERROR | [ ] Each class must be in a namespace of at least one | | level (a top-level vendor name) 3 | ERROR | [x] Opening brace of a class must be on the line after | | the definition
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
Time: 184ms; Memory: 6MB
Finished static code analysis.
I'm using version 3.6.1 and you are using version 3.6.2, could that be the difference? I'm running on Windows too, not sure if that makes a difference or not?
No, that doesn't make a difference. There's only a few commits between 3.6.1
and master
(3.6.2), but just to be sure, I re-ran the same test with the 3.6.1 tag checked out and got the same results.
I'm also on Windows, so that's not the issue either.
The problem is how you call PHPCS with your custom script, but that's not a PHPCS problem.
Not sure why you're running things that way, but heck, each to their own. Might work better if you use a Windows .bat
file though.
set PHPBIN=C:\path\to\php\php8.1.0\php.exe
"%PHPBIN%" -v
ECHO "Running static code analysis."
"%PHPBIN%" "path/to/phpcs.phar" %*
ECHO "Finished static code analysis."
I just ran the command without the batch file like so and I got the same results as before:
php C:\php\includes\phpcs.phar ../src/AMultiClassAndNSTests.php
I agree I'm running it in a way that isn't documented and therefore unlikely to be supported either, I'm going to grab the source code and debug it that way as in doing so I should be able to work out what is going on.
Thanks for your help and suggestions so far.
Describe the bug Using PSR-12, linting the following, I don't get an error about the space within the class name.
Code sample
To reproduce Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior I would expect the phpcs to stop due to the PHP code being invalid.