From dd6621e7c410321f817ba8e5347fd56e28fecebd Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Fri, 16 Jun 2017 20:55:18 +0200 Subject: [PATCH 1/4] [tests] use AbstractSniffRunner, no custom; bumpt to CodeSniffer 3.0 --- composer.json | 6 +- tests/CodeSnifferRunner.php | 33 --- tests/FileFactory.php | 70 ------ tests/Sniffs/AbstractSniffTestCase.php | 52 +++- tests/Sniffs/Classes/wrong/wrong.php.inc | 6 - tests/Sniffs/Classes/wrong/wrong2.php.inc | 6 + .../OneObjectOperatorPerLineSniffTest.php | 24 +- .../wrong.php.inc} | 0 .../wrong2.php.inc} | 0 .../ControlStructures/NoElseSniffTest.inc | 17 -- .../ControlStructures/NoElseSniffTest.php | 13 +- .../ControlStructures/wrong/wrong.php.inc | 5 + .../ControlStructures/wrong/wrong2.php.inc | 6 + .../ControlStructures/wrong/wrong3.php.inc | 6 + .../ClassTraitAndInterfaceLengthSniffTest.php | 14 ++ .../wrong/wrong.php.inc} | 0 .../wrong/wrong2.php.inc} | 0 .../wrong/wrong3.php.inc} | 0 .../ClassTraitAndInterfaceLengthSniffTest.php | 50 ---- .../FunctionLengthSniffTest.php | 14 ++ .../Files/FunctionLength/wrong/wrong.php.inc | 26 ++ .../wrong/wrong2.php.inc} | 24 -- .../Sniffs/Files/FunctionLengthSniffTest.php | 21 -- .../MaxNestingLevelSniffTest.php | 14 ++ .../wrong/wrong.php.inc} | 0 .../Metrics/MaxNestingLevelSniffTest.php | 21 -- .../MethodPerClassLimitSniffTest.php | 14 ++ .../MethodPerClassLimit/wrong/wrong.php.inc | 62 +++++ .../MethodPerClassLimit/wrong/wrong2.php.inc | 84 +++++++ .../MethodPerClassLimit/wrong/wrong3.php.inc | 85 +++++++ .../Metrics/MethodPerClassLimitSniffTest.inc | 229 ------------------ .../Metrics/MethodPerClassLimitSniffTest.php | 21 -- .../PropertyPerClassLimitSniffTest.php | 14 ++ .../correct/correct.php.inc | 14 ++ .../wrong/wrong.php.inc} | 14 -- .../PropertyPerClassLimitSniffTest.php | 21 -- .../ElementNameMinimalLengthSniffTest.php | 14 ++ .../correct/correct.php.inc | 5 + .../correct/correct2.php.inc | 6 + .../correct/correct3.php.inc | 5 + .../wrong/wrong.php.inc | 8 + .../wrong/wrong2.php.inc | 8 + .../wrong/wrong3.php.inc | 5 + .../wrong/wrong4.php.inc | 5 + .../wrong/wrong5.php.inc | 5 + .../wrong/wrong6.php.inc | 8 + .../wrong/wrong7.php.inc | 9 + .../wrong/wrong8.php.inc | 11 + .../wrong/wrong9.php.inc | 8 + .../ElementNameMinimalLengthSniffTest.inc | 55 ----- .../ElementNameMinimalLengthSniffTest.php | 21 -- .../NoSetter/NoSetterSniffTest.php | 14 ++ .../NoSetter/correct/correct.php.inc | 9 + .../wrong/wrong.php.inc} | 5 - .../NamingConventions/NoSetterSniffTest.php | 21 -- tests/Sniffs/SniffRunner.php | 110 --------- tests/bootstrap.php | 10 +- 57 files changed, 539 insertions(+), 789 deletions(-) delete mode 100644 tests/CodeSnifferRunner.php delete mode 100644 tests/FileFactory.php create mode 100644 tests/Sniffs/Classes/wrong/wrong2.php.inc rename tests/Sniffs/CodeAnalysis/{OneObjectOperatorPerLineSniffTest.inc => wrong/wrong.php.inc} (100%) rename tests/Sniffs/CodeAnalysis/{OneObjectOperatorPerLineSniffTestFluentInterface.inc => wrong/wrong2.php.inc} (100%) delete mode 100644 tests/Sniffs/ControlStructures/NoElseSniffTest.inc create mode 100644 tests/Sniffs/ControlStructures/wrong/wrong.php.inc create mode 100644 tests/Sniffs/ControlStructures/wrong/wrong2.php.inc create mode 100644 tests/Sniffs/ControlStructures/wrong/wrong3.php.inc create mode 100644 tests/Sniffs/Files/ClassTraitAndInterfaceLength/ClassTraitAndInterfaceLengthSniffTest.php rename tests/Sniffs/Files/{ClassTraitAndInterfaceLengthSniffTest.inc => ClassTraitAndInterfaceLength/wrong/wrong.php.inc} (100%) rename tests/Sniffs/Files/{ClassTraitAndInterfaceLengthSniffTest2.inc => ClassTraitAndInterfaceLength/wrong/wrong2.php.inc} (100%) rename tests/Sniffs/Files/{ClassTraitAndInterfaceLengthSniffTest3.inc => ClassTraitAndInterfaceLength/wrong/wrong3.php.inc} (100%) delete mode 100644 tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest.php create mode 100644 tests/Sniffs/Files/FunctionLength/FunctionLengthSniffTest.php create mode 100644 tests/Sniffs/Files/FunctionLength/wrong/wrong.php.inc rename tests/Sniffs/Files/{FunctionLengthSniffTest.inc => FunctionLength/wrong/wrong2.php.inc} (62%) delete mode 100644 tests/Sniffs/Files/FunctionLengthSniffTest.php create mode 100644 tests/Sniffs/Metrics/MaxNestingLevel/MaxNestingLevelSniffTest.php rename tests/Sniffs/Metrics/{MaxNestingLevelSniffTest.inc => MaxNestingLevel/wrong/wrong.php.inc} (100%) delete mode 100644 tests/Sniffs/Metrics/MaxNestingLevelSniffTest.php create mode 100644 tests/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php create mode 100644 tests/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc create mode 100644 tests/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong2.php.inc create mode 100644 tests/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong3.php.inc delete mode 100644 tests/Sniffs/Metrics/MethodPerClassLimitSniffTest.inc delete mode 100644 tests/Sniffs/Metrics/MethodPerClassLimitSniffTest.php create mode 100644 tests/Sniffs/Metrics/PropertyPerClassLimit/PropertyPerClassLimitSniffTest.php create mode 100644 tests/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc rename tests/Sniffs/Metrics/{PropertyPerClassLimitSniffTest.inc => PropertyPerClassLimit/wrong/wrong.php.inc} (81%) delete mode 100644 tests/Sniffs/Metrics/PropertyPerClassLimitSniffTest.php create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/ElementNameMinimalLengthSniffTest.php create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/correct/correct.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/correct/correct2.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/correct/correct3.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/wrong/wrong.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/wrong/wrong2.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/wrong/wrong3.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/wrong/wrong4.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/wrong/wrong5.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/wrong/wrong6.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/wrong/wrong7.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/wrong/wrong8.php.inc create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/wrong/wrong9.php.inc delete mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLengthSniffTest.inc delete mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLengthSniffTest.php create mode 100644 tests/Sniffs/NamingConventions/NoSetter/NoSetterSniffTest.php create mode 100644 tests/Sniffs/NamingConventions/NoSetter/correct/correct.php.inc rename tests/Sniffs/NamingConventions/{NoSetterSniffTest.inc => NoSetter/wrong/wrong.php.inc} (62%) delete mode 100644 tests/Sniffs/NamingConventions/NoSetterSniffTest.php delete mode 100644 tests/Sniffs/SniffRunner.php diff --git a/composer.json b/composer.json index 6a2e9bb..ed48e4b 100644 --- a/composer.json +++ b/composer.json @@ -5,15 +5,15 @@ "type": "phpcodesniffer-standard", "require": { "php": "^7.1", - "squizlabs/php_codesniffer": "dev-master", + "squizlabs/php_codesniffer": "^3.0.1", "nette/utils": "^2.4" }, "require-dev": { "phpunit/phpunit": "^6.0", "phpstan/phpstan": "^0.6", "tracy/tracy": "^2.4", - "symplify/easy-coding-standard": "dev-master", - "slevomat/coding-standard": "dev-phpcs3" + "symplify/easy-coding-standard": "^2.0", + "slevomat/coding-standard": "^3.0" }, "autoload": { "psr-4": { diff --git a/tests/CodeSnifferRunner.php b/tests/CodeSnifferRunner.php deleted file mode 100644 index 8427204..0000000 --- a/tests/CodeSnifferRunner.php +++ /dev/null @@ -1,33 +0,0 @@ -fileFactory = new FileFactory; - } - - public function detectErrorCountInFileForSniff(string $testedFile, string $sniffName): int - { - $file = $this->processCodeSniffer($testedFile, $sniffName); - - return $file->getErrorCount(); - } - - private function processCodeSniffer(string $testedFile, string $sniffClass): File - { - $file = $this->fileFactory->createFileWithSniffClass($testedFile, $sniffClass); - $file->process(); - - return $file; - } -} diff --git a/tests/FileFactory.php b/tests/FileFactory.php deleted file mode 100644 index 6d32108..0000000 --- a/tests/FileFactory.php +++ /dev/null @@ -1,70 +0,0 @@ -createConfig(); - $ruleset = new Ruleset($config); - - $file = new File($filePath, $ruleset, $config); - $file->setContent(file_get_contents($filePath)); - $file->parse(); - - return $file; - } - - public function createFileWithSniffClass(string $filePath, string $sniffClass): File - { - $config = $this->createConfig(); - $ruleset = $this->createRulesetWithConfigAndSniffClass($sniffClass, $config); - - $file = new File($filePath, $ruleset, $config); - $file->setContent(file_get_contents($filePath)); - $file->parse(); - - return $file; - } - - private function createRulesetWithConfigAndSniffClass(string $sniffClass, Config $config): Ruleset - { - $config->sniffs = [$sniffClass]; - $config->standards = ['ObjectCalisthenics']; - - $ruleset = new Ruleset($config); -// $ruleset->populateTokenListeners(); - - return $ruleset; - } - - private function createConfig(): Config - { - $config = new Config(); - // nulling required, because PEAR Standard is on by default -// $config->standards = []; - - return $config; - } -} diff --git a/tests/Sniffs/AbstractSniffTestCase.php b/tests/Sniffs/AbstractSniffTestCase.php index e03c442..cf3e70e 100644 --- a/tests/Sniffs/AbstractSniffTestCase.php +++ b/tests/Sniffs/AbstractSniffTestCase.php @@ -6,14 +6,35 @@ use Nette\Utils\Strings; use PHPUnit\Framework\TestCase; use SplFileInfo; +use Symplify\EasyCodingStandard\DependencyInjection\ContainerFactory; +use Symplify\EasyCodingStandard\Error\ErrorCollector; +use Symplify\EasyCodingStandard\SniffRunner\Application\SniffFileProcessor; +use Symplify\EasyCodingStandard\SniffRunner\Fixer\Fixer; -/** - * See https://github.com/Symplify/Symplify/blob/master/packages/CodingStandard/tests/Sniffs/AbstractSniffTestCase.php - */ abstract class AbstractSniffTestCase extends TestCase { + /** + * @var SniffFileProcessor + */ + private $sniffFileProcessor; + + /** + * @var ErrorCollector + */ + private $errorCollector; + + /** + * @var Fixer + */ + private $fixer; + protected function runSniffTestForDirectory(string $sniffClass, string $directory): void { + $container = (new ContainerFactory)->createWithoutConfig(); + $this->sniffFileProcessor = $container->get(SniffFileProcessor::class); + $this->errorCollector = $container->get(ErrorCollector::class); + $this->fixer = $container->get(Fixer::class); + foreach ($this->findFilesInDirectory($directory) as $file) { if (Strings::startsWith($file->getFilename(), 'correct')) { $this->runSniffTestForCorrectFile($sniffClass, $file); @@ -27,18 +48,20 @@ protected function runSniffTestForDirectory(string $sniffClass, string $director private function runSniffTestForCorrectFile(string $sniffClass, SplFileInfo $fileInfo): void { - $errorCount = SniffRunner::getErrorCountForSniffInFile($sniffClass, $fileInfo); - $this->assertSame(0, $errorCount, sprintf( + $this->processFileWithSniff($sniffClass, $fileInfo); + + $this->assertSame(0, $this->errorCollector->getErrorCount(), sprintf( 'File "%s" should have no errors. %s found.', $fileInfo->getPathname(), - $errorCount + $this->errorCollector->getErrorCount() )); } private function runSniffTestForWrongFile(string $sniffClass, SplFileInfo $fileInfo): void { - $errorCount = SniffRunner::getErrorCountForSniffInFile($sniffClass, $fileInfo); - $this->assertSame(1, $errorCount, sprintf( + $this->processFileWithSniff($sniffClass, $fileInfo); + + $this->assertSame(1, $this->errorCollector->getErrorCount(), sprintf( 'File "%s" should have at least 1 error.', $fileInfo->getPathname() )); @@ -48,12 +71,11 @@ private function runSniffTestForWrongFile(string $sniffClass, SplFileInfo $fileI return; } - $fixedContent = SniffRunner::getFixedContentForSniffInFile($sniffClass, $fileInfo); - $this->assertStringEqualsFile($fixedFileName, $fixedContent, sprintf( + $this->assertStringEqualsFile($fixedFileName, $this->fixer->getContents(), sprintf( 'File "%s" was not fixed properly. "%s" expected, "%s" given.', $fileInfo->getPathname(), file_get_contents($fixedFileName), - $fixedContent + $this->fixer->getContents() )); } @@ -74,4 +96,12 @@ private function getFixedFileName(SplFileInfo $fileInfo): string { return dirname($fileInfo->getPathname()) . '/' . $fileInfo->getBasename('.php.inc') . '-fixed.php.inc'; } + + private function processFileWithSniff(string $sniffClass, SplFileInfo $fileInfo): void + { + $this->errorCollector->resetCounters(); + $this->sniffFileProcessor->setIsFixer(true); // to test changed content of file + $this->sniffFileProcessor->setSingleSniff(new $sniffClass); + $this->sniffFileProcessor->processFile($fileInfo, true); + } } diff --git a/tests/Sniffs/Classes/wrong/wrong.php.inc b/tests/Sniffs/Classes/wrong/wrong.php.inc index 6958451..16ec1f4 100644 --- a/tests/Sniffs/Classes/wrong/wrong.php.inc +++ b/tests/Sniffs/Classes/wrong/wrong.php.inc @@ -2,11 +2,5 @@ class Test { - public $public; - - protected $protected; - - private $private; - private $one, $two; } diff --git a/tests/Sniffs/Classes/wrong/wrong2.php.inc b/tests/Sniffs/Classes/wrong/wrong2.php.inc new file mode 100644 index 0000000..c74d54c --- /dev/null +++ b/tests/Sniffs/Classes/wrong/wrong2.php.inc @@ -0,0 +1,6 @@ +detectErrorCountInFileForSniff( - __DIR__ . '/OneObjectOperatorPerLineSniffTest.inc', - OneObjectOperatorPerLineSniff::class - ); - - $this->assertSame(2, $errorCount); - } - - public function testFluentInterfaces(): void - { - $codeSnifferRunner = new CodeSnifferRunner(); - $errorCount = $codeSnifferRunner->detectErrorCountInFileForSniff( - __DIR__ . '/OneObjectOperatorPerLineSniffTestFluentInterface.inc', - OneObjectOperatorPerLineSniff::class - ); - - $this->assertSame(1, $errorCount); + $this->runSniffTestForDirectory(OneObjectOperatorPerLineSniff::class, __DIR__); } } diff --git a/tests/Sniffs/CodeAnalysis/OneObjectOperatorPerLineSniffTest.inc b/tests/Sniffs/CodeAnalysis/wrong/wrong.php.inc similarity index 100% rename from tests/Sniffs/CodeAnalysis/OneObjectOperatorPerLineSniffTest.inc rename to tests/Sniffs/CodeAnalysis/wrong/wrong.php.inc diff --git a/tests/Sniffs/CodeAnalysis/OneObjectOperatorPerLineSniffTestFluentInterface.inc b/tests/Sniffs/CodeAnalysis/wrong/wrong2.php.inc similarity index 100% rename from tests/Sniffs/CodeAnalysis/OneObjectOperatorPerLineSniffTestFluentInterface.inc rename to tests/Sniffs/CodeAnalysis/wrong/wrong2.php.inc diff --git a/tests/Sniffs/ControlStructures/NoElseSniffTest.inc b/tests/Sniffs/ControlStructures/NoElseSniffTest.inc deleted file mode 100644 index a3c99b7..0000000 --- a/tests/Sniffs/ControlStructures/NoElseSniffTest.inc +++ /dev/null @@ -1,17 +0,0 @@ - diff --git a/tests/Sniffs/ControlStructures/NoElseSniffTest.php b/tests/Sniffs/ControlStructures/NoElseSniffTest.php index b29f682..cfd0f02 100644 --- a/tests/Sniffs/ControlStructures/NoElseSniffTest.php +++ b/tests/Sniffs/ControlStructures/NoElseSniffTest.php @@ -3,19 +3,12 @@ namespace ObjectCalisthenics\Tests\Sniffs\ControlStructures; use ObjectCalisthenics\Sniffs\ControlStructures\NoElseSniff; -use ObjectCalisthenics\Tests\CodeSnifferRunner; -use PHPUnit\Framework\TestCase; +use ObjectCalisthenics\Tests\Sniffs\AbstractSniffTestCase; -final class NoElseSniffTest extends TestCase +final class NoElseSniffTest extends AbstractSniffTestCase { public function test(): void { - $codeSnifferRunner = new CodeSnifferRunner(); - $errorCount = $codeSnifferRunner->detectErrorCountInFileForSniff( - __DIR__ . '/NoElseSniffTest.inc', - NoElseSniff::class - ); - - $this->assertSame(5, $errorCount); + $this->runSniffTestForDirectory(NoElseSniff::class, __DIR__); } } diff --git a/tests/Sniffs/ControlStructures/wrong/wrong.php.inc b/tests/Sniffs/ControlStructures/wrong/wrong.php.inc new file mode 100644 index 0000000..35ac8c6 --- /dev/null +++ b/tests/Sniffs/ControlStructures/wrong/wrong.php.inc @@ -0,0 +1,5 @@ +runSniffTestForDirectory(ClassTraitAndInterfaceLengthSniff::class, __DIR__); + } +} diff --git a/tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest.inc b/tests/Sniffs/Files/ClassTraitAndInterfaceLength/wrong/wrong.php.inc similarity index 100% rename from tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest.inc rename to tests/Sniffs/Files/ClassTraitAndInterfaceLength/wrong/wrong.php.inc diff --git a/tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest2.inc b/tests/Sniffs/Files/ClassTraitAndInterfaceLength/wrong/wrong2.php.inc similarity index 100% rename from tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest2.inc rename to tests/Sniffs/Files/ClassTraitAndInterfaceLength/wrong/wrong2.php.inc diff --git a/tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest3.inc b/tests/Sniffs/Files/ClassTraitAndInterfaceLength/wrong/wrong3.php.inc similarity index 100% rename from tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest3.inc rename to tests/Sniffs/Files/ClassTraitAndInterfaceLength/wrong/wrong3.php.inc diff --git a/tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest.php b/tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest.php deleted file mode 100644 index 5cff71c..0000000 --- a/tests/Sniffs/Files/ClassTraitAndInterfaceLengthSniffTest.php +++ /dev/null @@ -1,50 +0,0 @@ -codeSnifferRunner = new CodeSnifferRunner(); - } - - public function testClassLengthSniff(): void - { - $errorCount = $this->codeSnifferRunner->detectErrorCountInFileForSniff( - __DIR__ . '/ClassTraitAndInterfaceLengthSniffTest.inc', - ClassTraitAndInterfaceLengthSniff::class - ); - - $this->assertSame(1, $errorCount); - } - - public function testInterfaceLengthSniff(): void - { - $errorCount = $this->codeSnifferRunner->detectErrorCountInFileForSniff( - __DIR__ . '/ClassTraitAndInterfaceLengthSniffTest2.inc', - ClassTraitAndInterfaceLengthSniff::class - ); - - $this->assertSame(1, $errorCount); - } - - public function testTraitLengthSniff(): void - { - $errorCount = $this->codeSnifferRunner->detectErrorCountInFileForSniff( - __DIR__ . '/ClassTraitAndInterfaceLengthSniffTest3.inc', - ClassTraitAndInterfaceLengthSniff::class - ); - - $this->assertSame(1, $errorCount); - } -} diff --git a/tests/Sniffs/Files/FunctionLength/FunctionLengthSniffTest.php b/tests/Sniffs/Files/FunctionLength/FunctionLengthSniffTest.php new file mode 100644 index 0000000..3bb47ea --- /dev/null +++ b/tests/Sniffs/Files/FunctionLength/FunctionLengthSniffTest.php @@ -0,0 +1,14 @@ +runSniffTestForDirectory(FunctionLengthSniff::class, __DIR__); + } +} diff --git a/tests/Sniffs/Files/FunctionLength/wrong/wrong.php.inc b/tests/Sniffs/Files/FunctionLength/wrong/wrong.php.inc new file mode 100644 index 0000000..c0477ae --- /dev/null +++ b/tests/Sniffs/Files/FunctionLength/wrong/wrong.php.inc @@ -0,0 +1,26 @@ +detectErrorCountInFileForSniff( - __DIR__ . '/FunctionLengthSniffTest.inc', - FunctionLengthSniff::class - ); - - $this->assertSame(2, $errorCount); - } -} diff --git a/tests/Sniffs/Metrics/MaxNestingLevel/MaxNestingLevelSniffTest.php b/tests/Sniffs/Metrics/MaxNestingLevel/MaxNestingLevelSniffTest.php new file mode 100644 index 0000000..3af5510 --- /dev/null +++ b/tests/Sniffs/Metrics/MaxNestingLevel/MaxNestingLevelSniffTest.php @@ -0,0 +1,14 @@ +runSniffTestForDirectory(MaxNestingLevelSniff::class, __DIR__); + } +} diff --git a/tests/Sniffs/Metrics/MaxNestingLevelSniffTest.inc b/tests/Sniffs/Metrics/MaxNestingLevel/wrong/wrong.php.inc similarity index 100% rename from tests/Sniffs/Metrics/MaxNestingLevelSniffTest.inc rename to tests/Sniffs/Metrics/MaxNestingLevel/wrong/wrong.php.inc diff --git a/tests/Sniffs/Metrics/MaxNestingLevelSniffTest.php b/tests/Sniffs/Metrics/MaxNestingLevelSniffTest.php deleted file mode 100644 index aab3f01..0000000 --- a/tests/Sniffs/Metrics/MaxNestingLevelSniffTest.php +++ /dev/null @@ -1,21 +0,0 @@ -detectErrorCountInFileForSniff( - __DIR__ . '/MaxNestingLevelSniffTest.inc', - MaxNestingLevelSniff::class - ); - - $this->assertSame(1, $errorCount); - } -} diff --git a/tests/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php b/tests/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php new file mode 100644 index 0000000..8de7f43 --- /dev/null +++ b/tests/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php @@ -0,0 +1,14 @@ +runSniffTestForDirectory(MethodPerClassLimitSniff::class, __DIR__); + } +} diff --git a/tests/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc b/tests/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc new file mode 100644 index 0000000..9591914 --- /dev/null +++ b/tests/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc @@ -0,0 +1,62 @@ +detectErrorCountInFileForSniff( - __DIR__ . '/MethodPerClassLimitSniffTest.inc', - MethodPerClassLimitSniff::class - ); - - $this->assertSame(3, $errorCount); - } -} diff --git a/tests/Sniffs/Metrics/PropertyPerClassLimit/PropertyPerClassLimitSniffTest.php b/tests/Sniffs/Metrics/PropertyPerClassLimit/PropertyPerClassLimitSniffTest.php new file mode 100644 index 0000000..3ca5cd6 --- /dev/null +++ b/tests/Sniffs/Metrics/PropertyPerClassLimit/PropertyPerClassLimitSniffTest.php @@ -0,0 +1,14 @@ +runSniffTestForDirectory(PropertyPerClassLimitSniff::class, __DIR__); + } +} diff --git a/tests/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc b/tests/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc new file mode 100644 index 0000000..50d10ae --- /dev/null +++ b/tests/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc @@ -0,0 +1,14 @@ +detectErrorCountInFileForSniff( - __DIR__ . '/PropertyPerClassLimitSniffTest.inc', - PropertyPerClassLimitSniff::class - ); - - $this->assertSame(1, $errorCount); - } -} diff --git a/tests/Sniffs/NamingConventions/ElementNameMinimalLength/ElementNameMinimalLengthSniffTest.php b/tests/Sniffs/NamingConventions/ElementNameMinimalLength/ElementNameMinimalLengthSniffTest.php new file mode 100644 index 0000000..5f9bd24 --- /dev/null +++ b/tests/Sniffs/NamingConventions/ElementNameMinimalLength/ElementNameMinimalLengthSniffTest.php @@ -0,0 +1,14 @@ +runSniffTestForDirectory(ElementNameMinimalLengthSniff::class, __DIR__); + } +} diff --git a/tests/Sniffs/NamingConventions/ElementNameMinimalLength/correct/correct.php.inc b/tests/Sniffs/NamingConventions/ElementNameMinimalLength/correct/correct.php.inc new file mode 100644 index 0000000..34d0d6c --- /dev/null +++ b/tests/Sniffs/NamingConventions/ElementNameMinimalLength/correct/correct.php.inc @@ -0,0 +1,5 @@ +te = $t; - } - - public function testing() - { - $bl = 2; - - for ($i = 0; $i < range(0, 9); $i++) { - echo $i; - } - $veryLongPropertyNameVeryLongPropertyName = 3; - } -} diff --git a/tests/Sniffs/NamingConventions/ElementNameMinimalLengthSniffTest.php b/tests/Sniffs/NamingConventions/ElementNameMinimalLengthSniffTest.php deleted file mode 100644 index 45bfe0f..0000000 --- a/tests/Sniffs/NamingConventions/ElementNameMinimalLengthSniffTest.php +++ /dev/null @@ -1,21 +0,0 @@ -detectErrorCountInFileForSniff( - __DIR__ . '/ElementNameMinimalLengthSniffTest.inc', - ElementNameMinimalLengthSniff::class - ); - - $this->assertSame(9, $errorCount); - } -} diff --git a/tests/Sniffs/NamingConventions/NoSetter/NoSetterSniffTest.php b/tests/Sniffs/NamingConventions/NoSetter/NoSetterSniffTest.php new file mode 100644 index 0000000..7f8a010 --- /dev/null +++ b/tests/Sniffs/NamingConventions/NoSetter/NoSetterSniffTest.php @@ -0,0 +1,14 @@ +runSniffTestForDirectory(NoSetterSniff::class, __DIR__); + } +} diff --git a/tests/Sniffs/NamingConventions/NoSetter/correct/correct.php.inc b/tests/Sniffs/NamingConventions/NoSetter/correct/correct.php.inc new file mode 100644 index 0000000..5728a15 --- /dev/null +++ b/tests/Sniffs/NamingConventions/NoSetter/correct/correct.php.inc @@ -0,0 +1,9 @@ +detectErrorCountInFileForSniff( - __DIR__ . '/NoSetterSniffTest.inc', - NoSetterSniff::class - ); - - $this->assertSame(1, $errorCount); - } -} diff --git a/tests/Sniffs/SniffRunner.php b/tests/Sniffs/SniffRunner.php deleted file mode 100644 index d682bc7..0000000 --- a/tests/Sniffs/SniffRunner.php +++ /dev/null @@ -1,110 +0,0 @@ -getPathname(), $errorDataCollector); - foreach ($file->getTokens() as $stackPointer => $token) { - $sniffDispatcher->dispatchToken( - $token['code'], - new FileTokenEvent($file, $stackPointer) - ); - } - return $errorDataCollector->getErrorCount(); - } - - public static function getFixedContentForSniffInFile(string $sniffClass, SplFileInfo $fileInfo): string - { - $sniffDispatcher = self::createSniffDispatcherWithSniff($sniffClass); - $file = self::createFileFromFilePath($fileInfo->getPathname()); - foreach ($file->getTokens() as $stackPointer => $token) { - $sniffDispatcher->dispatchToken( - $token['code'], - new FileTokenEvent($file, $stackPointer) - ); - } - $fixer = $file->fixer; - return $fixer->getContents(); - } - - private static function createSniffDispatcherWithSniff(string $sniffClass): TokenDispatcher - { - $sniffDispatcher = new TokenDispatcher(self::createSkipper()); - $sniffDispatcher->addSniffListeners([new $sniffClass]); - return $sniffDispatcher; - } - - private static function createErrorDataCollector(): ErrorCollector - { - $dummyChangedFilesDetector = self::createDummyChangedFilesDetector(); - return new ErrorCollector(new ErrorSorter, $dummyChangedFilesDetector); - } - - private static function createFileFromFilePath( - string $filePath, - ?ErrorCollector $errorDataCollector = null - ): File { - $fileToTokenParser = new FileToTokensParser; - $errorDataCollector = $errorDataCollector ?: self::createErrorDataCollector(); - $tokens = $fileToTokenParser->parseFromFilePath($filePath); - $fixer = new Fixer; - $file = new File($filePath, $tokens, $fixer, $errorDataCollector, true); - $fixer = $file->fixer; - $fixer->startFile($file); - return $file; - } - - private static function createDummyChangedFilesDetector(): ChangedFilesDetectorInterface - { - return new class implements ChangedFilesDetectorInterface { - public function addFile(string $filePath): void - { - } - public function invalidateFile(string $filePath): void - { - } - public function hasFileChanged(string $filePath): bool - { - return true; - } - public function clearCache(): void - { - } - }; - } - - private static function createSkipper(): SkipperInterface - { - return new class implements SkipperInterface - { - /** - * @param Sniff|FixerInterface|string $checker - */ - public function shouldSkipCheckerAndFile($checker, string $relativeFilePath): bool - { - return false; - } - }; - } -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 86add34..5cd8002 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,8 +3,8 @@ require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/squizlabs/php_codesniffer/autoload.php'; -new PHP_CodeSniffer\Util\Tokens; - -if (! defined('PHP_CODESNIFFER_VERBOSITY')) { - define('PHP_CODESNIFFER_VERBOSITY', 0); -} +//new PHP_CodeSniffer\Util\Tokens; +// +//if (! defined('PHP_CODESNIFFER_VERBOSITY')) { +// define('PHP_CODESNIFFER_VERBOSITY', 0); +//} From aac08583d5519408b12c37496e29dfafdad05001 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 17 Jun 2017 10:12:05 +0200 Subject: [PATCH 2/4] fix tests --- tests/Sniffs/Classes/correct/correct.php.inc | 6 +++ tests/Sniffs/Classes/wrong/wrong.php.inc | 2 +- tests/Sniffs/Classes/wrong/wrong2.php.inc | 6 --- .../CodeAnalysis/correct/correct.php.inc | 31 +++++++++++++ tests/Sniffs/CodeAnalysis/wrong/wrong.php.inc | 45 ------------------- .../Sniffs/CodeAnalysis/wrong/wrong3.php.inc | 16 +++++++ tests/bootstrap.php | 6 --- 7 files changed, 54 insertions(+), 58 deletions(-) create mode 100644 tests/Sniffs/Classes/correct/correct.php.inc delete mode 100644 tests/Sniffs/Classes/wrong/wrong2.php.inc create mode 100644 tests/Sniffs/CodeAnalysis/correct/correct.php.inc create mode 100644 tests/Sniffs/CodeAnalysis/wrong/wrong3.php.inc diff --git a/tests/Sniffs/Classes/correct/correct.php.inc b/tests/Sniffs/Classes/correct/correct.php.inc new file mode 100644 index 0000000..16ec1f4 --- /dev/null +++ b/tests/Sniffs/Classes/correct/correct.php.inc @@ -0,0 +1,6 @@ +sessionStorage = new MySessionStorage(); + + $this->getSessionStorage()->start(); + $this->create(); + } + + public function create() + { + $this->sessionStorage->start(); + $this->sessionStorage->start()->start(); + $this->getSessionStorage()->start()->start(); + } + + private function getSessionStorage() + { + return $this->sessionStorage; + } + + public function getSessionStorageName() + { + return $this->sessionStorage->name; + } +} diff --git a/tests/Sniffs/CodeAnalysis/wrong/wrong.php.inc b/tests/Sniffs/CodeAnalysis/wrong/wrong.php.inc index 93462c3..1e96762 100644 --- a/tests/Sniffs/CodeAnalysis/wrong/wrong.php.inc +++ b/tests/Sniffs/CodeAnalysis/wrong/wrong.php.inc @@ -1,50 +1,5 @@ sessionStorage = new MySessionStorage(); - - $this->getSessionStorage()->start(); - $this->create(); - } - - public function create() - { - $this->sessionStorage->start(); - $this->sessionStorage->start()->start(); - $this->getSessionStorage()->start()->start(); - } - - private function getSessionStorage() - { - return $this->sessionStorage; - } - - public function getSessionStorageName() - { - return $this->sessionStorage->name; - } -} - -class MySessionStorage -{ - public $name = 'mySessionStorage'; - - public function __construct() - { - $this->driver = new NativeSessionStorage(); - } - - public function start() - { - $this->driver->getInternal()->start(); - } -} - class NativeSessionStorage { public function getInternal() diff --git a/tests/Sniffs/CodeAnalysis/wrong/wrong3.php.inc b/tests/Sniffs/CodeAnalysis/wrong/wrong3.php.inc new file mode 100644 index 0000000..a78bf99 --- /dev/null +++ b/tests/Sniffs/CodeAnalysis/wrong/wrong3.php.inc @@ -0,0 +1,16 @@ +driver = new NativeSessionStorage(); + } + + public function start() + { + $this->driver->getInternal()->start(); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5cd8002..8d7430e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,9 +2,3 @@ require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/squizlabs/php_codesniffer/autoload.php'; - -//new PHP_CodeSniffer\Util\Tokens; -// -//if (! defined('PHP_CODESNIFFER_VERBOSITY')) { -// define('PHP_CODESNIFFER_VERBOSITY', 0); -//} From 5ef50338a9d768484e64f242d7657a22171fe041 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 17 Jun 2017 10:17:49 +0200 Subject: [PATCH 3/4] test and cs fixes --- easy-coding-standard.neon | 4 -- .../Classes/ForbiddenPublicPropertySniff.php | 2 +- tests/FileFactory.php | 70 +++++++++++++++++++ .../ElementNameMinimalLengthSniffTest.inc | 55 +++++++++++++++ 4 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 tests/FileFactory.php create mode 100644 tests/Sniffs/NamingConventions/ElementNameMinimalLength/ElementNameMinimalLengthSniffTest.inc diff --git a/easy-coding-standard.neon b/easy-coding-standard.neon index 54c6a7b..ad39f0e 100644 --- a/easy-coding-standard.neon +++ b/easy-coding-standard.neon @@ -112,7 +112,6 @@ checkers: - Symplify\CodingStandard\Sniffs\Namespaces\ClassNamesWithoutPreSlashSniff - PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer - - PhpCsFixer\Fixer\NamespaceNotation\BlankLineAfterNamespaceFixer # Symplify: Naming - Symplify\CodingStandard\Sniffs\Naming\AbstractClassNameSniff @@ -177,7 +176,6 @@ checkers: - PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer - PhpCsFixer\Fixer\ControlStructure\ElseifFixer - PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer - - PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer - PhpCsFixer\Fixer\Whitespace\IndentationTypeFixer - PhpCsFixer\Fixer\Whitespace\LineEndingFixer - PhpCsFixer\Fixer\Casing\LowercaseKeywordsFixer @@ -203,8 +201,6 @@ checkers: PhpCsFixer\Fixer\Basic\BracesFixer: allow_single_line_closure: true - PhpCsFixer\Fixer\CastNotation\CastSpacesFixer - PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer: - singleLine: true - PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer - PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer - PhpCsFixer\Fixer\Comment\HashToSlashCommentFixer diff --git a/src/ObjectCalisthenics/Sniffs/Classes/ForbiddenPublicPropertySniff.php b/src/ObjectCalisthenics/Sniffs/Classes/ForbiddenPublicPropertySniff.php index 33f9ef3..f068b2d 100644 --- a/src/ObjectCalisthenics/Sniffs/Classes/ForbiddenPublicPropertySniff.php +++ b/src/ObjectCalisthenics/Sniffs/Classes/ForbiddenPublicPropertySniff.php @@ -46,7 +46,7 @@ public function process(File $file, $position): void private function isSniffClass(File $file, int $position): bool { - $classTokenPosition = $file->findPrevious(T_CLASS, $position); + $classTokenPosition = (int) $file->findPrevious(T_CLASS, $position); $classNameTokenPosition = $file->findNext(T_STRING, $classTokenPosition); $classNameToken = $file->getTokens()[$classNameTokenPosition]; diff --git a/tests/FileFactory.php b/tests/FileFactory.php new file mode 100644 index 0000000..6d32108 --- /dev/null +++ b/tests/FileFactory.php @@ -0,0 +1,70 @@ +createConfig(); + $ruleset = new Ruleset($config); + + $file = new File($filePath, $ruleset, $config); + $file->setContent(file_get_contents($filePath)); + $file->parse(); + + return $file; + } + + public function createFileWithSniffClass(string $filePath, string $sniffClass): File + { + $config = $this->createConfig(); + $ruleset = $this->createRulesetWithConfigAndSniffClass($sniffClass, $config); + + $file = new File($filePath, $ruleset, $config); + $file->setContent(file_get_contents($filePath)); + $file->parse(); + + return $file; + } + + private function createRulesetWithConfigAndSniffClass(string $sniffClass, Config $config): Ruleset + { + $config->sniffs = [$sniffClass]; + $config->standards = ['ObjectCalisthenics']; + + $ruleset = new Ruleset($config); +// $ruleset->populateTokenListeners(); + + return $ruleset; + } + + private function createConfig(): Config + { + $config = new Config(); + // nulling required, because PEAR Standard is on by default +// $config->standards = []; + + return $config; + } +} diff --git a/tests/Sniffs/NamingConventions/ElementNameMinimalLength/ElementNameMinimalLengthSniffTest.inc b/tests/Sniffs/NamingConventions/ElementNameMinimalLength/ElementNameMinimalLengthSniffTest.inc new file mode 100644 index 0000000..b48dbf5 --- /dev/null +++ b/tests/Sniffs/NamingConventions/ElementNameMinimalLength/ElementNameMinimalLengthSniffTest.inc @@ -0,0 +1,55 @@ +te = $t; + } + + public function testing() + { + $bl = 2; + + for ($i = 0; $i < range(0, 9); $i++) { + echo $i; + } + $veryLongPropertyNameVeryLongPropertyName = 3; + } +} From e6538692d4ff7c9b8164723a978f4506027673e9 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 17 Jun 2017 10:28:35 +0200 Subject: [PATCH 4/4] cs fixes --- composer.json | 7 ++-- easy-coding-standard.neon | 38 +++++-------------- .../Helper/NonClassTypeTokenTypeException.php | 1 - .../Classes/ForbiddenPublicPropertySniff.php | 1 + 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/composer.json b/composer.json index ed48e4b..5370ec1 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,10 @@ }, "require-dev": { "phpunit/phpunit": "^6.0", - "phpstan/phpstan": "^0.6", + "phpstan/phpstan": "^0.7", "tracy/tracy": "^2.4", "symplify/easy-coding-standard": "^2.0", + "symplify/coding-standard": "^2.0", "slevomat/coding-standard": "^3.0" }, "autoload": { @@ -28,7 +29,7 @@ "scripts": { "complete-check": ["@phpstan", "@check-cs", "phpunit"], "phpstan": "phpstan analyze src --level 5 --configuration phpstan.neon", - "check-cs": "vendor/bin/easy-coding-standard check src tests", - "fix-cs": "vendor/bin/easy-coding-standard check src tests --fix" + "check-cs": "easy-coding-standard check src tests", + "fix-cs": "easy-coding-standard check src tests --fix" } } diff --git a/easy-coding-standard.neon b/easy-coding-standard.neon index ad39f0e..ecc9e1e 100644 --- a/easy-coding-standard.neon +++ b/easy-coding-standard.neon @@ -20,18 +20,17 @@ checkers: allowedShortNames: ["i", "id", "to", "up"] # Rule 7: Keep your classes small (with default values) - ObjectCalisthenics\Sniffs\Metrics\ClassTraitAndInterfaceLength: + ObjectCalisthenics\Sniffs\Files\ClassTraitAndInterfaceLengthSniff: maxLength: 200 - ObjectCalisthenics\Sniffs\Files\FunctionLength: + ObjectCalisthenics\Sniffs\Files\FunctionLengthSniff: maxLength: 20 - ObjectCalisthenics\Sniffs\Files\PropertyPerClassLimit: + ObjectCalisthenics\Sniffs\Metrics\PropertyPerClassLimitSniff: maxCount: 10 - ObjectCalisthenics\Sniffs\Metrics\MethodPerClassLimit: + ObjectCalisthenics\Sniffs\Metrics\MethodPerClassLimitSniff: maxCount: 10 # Rule 9: Do not Use Getters and Setters - # disable for temp bug in Symplify\EasyCodingStandard - # - ObjectCalisthenics\Sniffs\Classes\ForbiddenPublicPropertySniff + - ObjectCalisthenics\Sniffs\Classes\ForbiddenPublicPropertySniff - ObjectCalisthenics\Sniffs\NamingConventions\NoSetterSniff # Classes @@ -70,8 +69,7 @@ checkers: - PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\FunctionCallArgumentSpacingSniff - PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions\ValidDefaultValueSniff - PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\FunctionDeclarationSniff: - equalsSpacing: 1 + - PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\FunctionDeclarationSniff - PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\MultiLineFunctionDeclarationSniff - PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\LowercaseFunctionKeywordsSniff @@ -97,20 +95,13 @@ checkers: ignoreBlankLines: false # Symplify: Commenting - - Symplify\CodingStandard\Sniffs\Commenting\BlockPropertyCommentSniff - - Symplify\CodingStandard\Sniffs\Commenting\MethodReturnTypeSniff - - Symplify\CodingStandard\Sniffs\Commenting\MethodCommentSniff - Symplify\CodingStandard\Sniffs\Commenting\VarPropertyCommentSniff - # Symplify: Control Structures - - Symplify\CodingStandard\Sniffs\ControlStructures\NewClassSniff - # Symplify: Debug - Symplify\CodingStandard\Sniffs\Debug\DebugFunctionCallSniff # Namespaces - Symplify\CodingStandard\Sniffs\Namespaces\ClassNamesWithoutPreSlashSniff - - PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer # Symplify: Naming @@ -186,8 +177,6 @@ checkers: - PhpCsFixer\Fixer\Whitespace\NoTrailingWhitespaceFixer - PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer - PhpCsFixer\Fixer\Whitespace\SingleBlankLineAtEofFixer - PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer: - - property - PhpCsFixer\Fixer\Import\SingleImportPerStatementFixer - PhpCsFixer\Fixer\Import\SingleLineAfterImportsFixer - PhpCsFixer\Fixer\ControlStructure\SwitchCaseSemicolonToColonFixer @@ -242,7 +231,6 @@ checkers: - PhpCsFixer\Fixer\Phpdoc\PhpdocNoAccessFixer - PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer - PhpCsFixer\Fixer\Phpdoc\PhpdocNoPackageFixer - - PhpCsFixer\Fixer\Phpdoc\PhpdocNoUselessInheritdocFixer - PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer - PhpCsFixer\Fixer\Phpdoc\PhpdocScalarFixer - PhpCsFixer\Fixer\Phpdoc\PhpdocSingleLineVarSpacingFixer @@ -255,7 +243,6 @@ checkers: - PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer - PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer - PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer - - PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer - PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer - PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer - PhpCsFixer\Fixer\Semicolon\SpaceAfterSemicolonFixer @@ -275,17 +262,12 @@ checkers: - method # new since PhpCsFixer 2.1/2.2 - - PhpCsFixer\Fixer\Phpdoc\PhpdocNoUselessInheritdocFixer - - PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer - PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer - PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer - PhpCsFixer\Fixer\Basic\NonPrintableCharacterFixer - PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer -skip: - # bugged in Symplify, to be fixed soon - SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff: - - src/ObjetCalisthenics/Sniffs/*/*Sniff.php - # bugged in Symplify, to be fixed soon - ObjectCalisthenics\Sniffs\Classes\ForbiddenPublicPropertySniff: - - src/ObjetCalisthenics/Sniffs/*/*Sniff.php +parameters: + skip: + SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff: + - src/ObjectCalisthenics/Sniffs/*/*Sniff.php diff --git a/src/ObjectCalisthenics/Exception/Helper/NonClassTypeTokenTypeException.php b/src/ObjectCalisthenics/Exception/Helper/NonClassTypeTokenTypeException.php index 097b99b..9c895a5 100644 --- a/src/ObjectCalisthenics/Exception/Helper/NonClassTypeTokenTypeException.php +++ b/src/ObjectCalisthenics/Exception/Helper/NonClassTypeTokenTypeException.php @@ -6,5 +6,4 @@ final class NonClassTypeTokenTypeException extends Exception { - } diff --git a/src/ObjectCalisthenics/Sniffs/Classes/ForbiddenPublicPropertySniff.php b/src/ObjectCalisthenics/Sniffs/Classes/ForbiddenPublicPropertySniff.php index f068b2d..0a900ee 100644 --- a/src/ObjectCalisthenics/Sniffs/Classes/ForbiddenPublicPropertySniff.php +++ b/src/ObjectCalisthenics/Sniffs/Classes/ForbiddenPublicPropertySniff.php @@ -63,6 +63,7 @@ private function isSniffClass(File $file, int $position): bool private function getPropertyScopeModifier(File $file, int $position): array { $scopeModifierPosition = $file->findPrevious(Tokens::$scopeModifiers, ($position - 1)); + return $file->getTokens()[$scopeModifierPosition]; } }