diff --git a/.gitignore b/.gitignore index 779e19d..7ea08c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea .vscode +.phpintel /vendor/ +out.csv \ No newline at end of file diff --git a/composer.json b/composer.json index 09d467d..5e046e5 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,10 @@ "homepage": "https://github.com/ProtonMail/php-coding-standard", "minimum-stability": "dev", "prefer-stable": true, + "scripts": { + "test-print": "phpcs --standard=Proton/ruleset.xml --report=summary tests", + "test": "phpcs --standard=Proton/ruleset.xml --report=csv tests | sort -r | cut -f 2,3,4,6 -d ',' > tests/out.csv; diff tests/expected_csv.txt tests/out.csv" + }, "require": { "php": "^7.1", "slevomat/coding-standard": "^5.0|^6.0", diff --git a/tests/correct/ClassOk.php b/tests/correct/ClassOk.php new file mode 100644 index 0000000..cfb7964 --- /dev/null +++ b/tests/correct/ClassOk.php @@ -0,0 +1,44 @@ +foo = $config + [ + 'foo' => 'bar', + ]; + } + + public function ping(Request $request) + { + return $request->query->get('test'); + } + + public function foo(string $a, string $b) + { + $a = $a . 'test'; + + if ( + $a === 'a' + || $b === 'b' + ) { + return $a; + } + + return false; + } +} diff --git a/tests/expected.txt b/tests/expected.txt new file mode 100644 index 0000000..b6011c2 --- /dev/null +++ b/tests/expected.txt @@ -0,0 +1,13 @@ + +PHP CODE SNIFFER REPORT SUMMARY +------------------------------------------------------------------------------------------------ +FILE ERRORS WARNINGS +------------------------------------------------------------------------------------------------ +/Users/Username/dev/Proton/php-coding-standard/tests/wrong/Class1.php 30 0 +/Users/Username/dev/Proton/php-coding-standard/tests/wrong/ClassMetrics.php 4 0 +/Users/Username/dev/Proton/php-coding-standard/tests/wrong/file.php 2 0 +------------------------------------------------------------------------------------------------ +A TOTAL OF 36 ERRORS AND 0 WARNINGS WERE FOUND IN 3 FILES +------------------------------------------------------------------------------------------------ +PHPCBF CAN FIX 28 OF THESE SNIFF VIOLATIONS AUTOMATICALLY +------------------------------------------------------------------------------------------------ \ No newline at end of file diff --git a/tests/expected_csv.txt b/tests/expected_csv.txt new file mode 100644 index 0000000..15b7fe0 --- /dev/null +++ b/tests/expected_csv.txt @@ -0,0 +1,42 @@ +Line,Column,Type,Source +4,10,error,PSR2.Files.EndFileNewline.NoneFound +1,1,error,SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing +6,12,warning,Generic.Metrics.NestingLevel.TooHigh +5,20,error,PSR2.Classes.ClassDeclaration.OpenBraceNewLine +21,11,error, found 10" +20,9,warning,Generic.CodeAnalysis.UnconditionalIfStatement.Found +20,9,error,SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn.UselessIfCondition +1,1,error,SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing +8,1,error, found 1." +6,18,error,PSR12.Files.FileHeader.SpacingInsideBlock +40,1,error,PSR2.Files.EndFileNewline.NoneFound +4,1,error, found 2." +38,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed +37,13,warning,Squiz.PHP.NonExecutableCode.Unreachable +37,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed +36,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed +35,9,error,Generic.PHP.LowerCaseKeyword.Found +35,9,error,Squiz.ControlStructures.LowercaseDeclaration.FoundUppercase +35,9,error,Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword +35,12,error,Squiz.NamingConventions.ValidVariableName.NotCamelCaps +35,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed +33,9,error,Squiz.NamingConventions.ValidVariableName.NotCamelCaps +33,24,warning,Generic.CodeAnalysis.EmptyPHPStatement.SemicolonWithoutCodeDetected +33,24,error,SlevomatCodingStandard.PHP.UselessSemicolon.UselessSemicolon +33,24,error,Generic.Formatting.DisallowMultipleStatements.SameLine +33,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed +31,31,error,Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine +31,13,error,SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod +27,27,error,PSR12.Classes.AnonClassDeclaration.SpaceAfterKeyword +24,13,error,SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma +20,19,error,Generic.PHP.BacktickOperator.Found +20,14,error,Generic.PHP.BacktickOperator.Found +16,5,error,PSR12.Traits.UseDeclaration.UseAfterBrace +16,16,error,PSR12.Traits.UseDeclaration.MultipleImport +14,5,warning,PSR12.Properties.ConstantVisibility.NotFound +12,13,error,Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps +12,13,error,SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty +12,1,error,Generic.WhiteSpace.DisallowTabIndent.TabsUsed +10,27,error,SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces.IncorrectEmptyLinesAfterOpeningBrace +10,27,error,PSR2.Classes.ClassDeclaration.OpenBraceNewLine +1,1,error,SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing diff --git a/tests/wrong/Class1.php b/tests/wrong/Class1.php new file mode 100644 index 0000000..c9d7d5b --- /dev/null +++ b/tests/wrong/Class1.php @@ -0,0 +1,40 @@ +test = new class() { + }; + } + + private function unused() { + $fooBar = 1; + $foo_bar = '1';; + + IF($foo_bar == '1') { + return true; + return true; + } + } +} \ No newline at end of file diff --git a/tests/wrong/ClassMetrics.php b/tests/wrong/ClassMetrics.php new file mode 100644 index 0000000..d4390dd --- /dev/null +++ b/tests/wrong/ClassMetrics.php @@ -0,0 +1,26 @@ +