diff --git a/composer.json b/composer.json index 3f6533622f..1b09aaa985 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "illuminate/container": "^12.35", "nette/utils": "^4.0.7", "sebastian/diff": "^6.0.2", - "squizlabs/php_codesniffer": "^3.13.4", + "squizlabs/php_codesniffer": "^4.0", "symfony/console": "^6.4.24", "symfony/finder": "^7.3.0", "symplify/coding-standard": "^12.5", diff --git a/config/set/common/spaces.php b/config/set/common/spaces.php index d810400faa..9382e948e9 100644 --- a/config/set/common/spaces.php +++ b/config/set/common/spaces.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\LanguageConstructSpacingSniff; +use PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\LanguageConstructSpacingSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff; use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer; use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; diff --git a/src/DependencyInjection/CompilerPass/RemoveMutualCheckersCompilerPass.php b/src/DependencyInjection/CompilerPass/RemoveMutualCheckersCompilerPass.php index 117a803655..05811e6469 100644 --- a/src/DependencyInjection/CompilerPass/RemoveMutualCheckersCompilerPass.php +++ b/src/DependencyInjection/CompilerPass/RemoveMutualCheckersCompilerPass.php @@ -27,7 +27,7 @@ use PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\LowercaseClassKeywordsSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\FunctionDeclarationArgumentSpacingSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Strings\DoubleQuoteUsageSniff; -use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\LanguageConstructSpacingSniff; +use PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\LanguageConstructSpacingSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff; use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; use PhpCsFixer\Fixer\Basic\BracesFixer; diff --git a/src/SniffRunner/ValueObject/File.php b/src/SniffRunner/ValueObject/File.php index a0f4025305..e46dd3601c 100644 --- a/src/SniffRunner/ValueObject/File.php +++ b/src/SniffRunner/ValueObject/File.php @@ -21,11 +21,6 @@ */ final class File extends BaseFile { - /** - * @var string - */ - public $tokenizerType = 'PHP'; - private string|null $activeSniffClass = null; private string|null $previousActiveSniffClass = null; @@ -122,7 +117,7 @@ public function process(): void * * @param mixed[] $data */ - public function addFixableError($error, $stackPtr, $code, $data = [], $severity = 0): bool + public function addFixableError(string $error, int $stackPtr, string $code, array $data = [], int $severity = 0): bool { $fullyQualifiedCode = $this->resolveFullyQualifiedCode($code); $this->sniffMetadataCollector->addAppliedSniff($fullyQualifiedCode); @@ -133,7 +128,7 @@ public function addFixableError($error, $stackPtr, $code, $data = [], $severity /** * @param mixed[] $data */ - public function addError($error, $stackPtr, $code, $data = [], $severity = 0, $fixable = false): bool + public function addError(string $error, ?int $stackPtr, string $code, array $data = [], int $severity = 0, bool $fixable = false): bool { if ($this->shouldSkipError($error, $code, $data)) { return false; @@ -143,10 +138,10 @@ public function addError($error, $stackPtr, $code, $data = [], $severity = 0, $f } /** - * @param mixed $data + * @param mixed[] $data * Allow only specific classes */ - public function addWarning($warning, $stackPtr, $code, $data = [], $severity = 0, $fixable = false): bool + public function addWarning(string $warning, ?int $stackPtr, string $code, array $data = [], int $severity = 0, bool $fixable = false): bool { if ($this->activeSniffClass === null) { throw new ShouldNotHappenException(); @@ -175,18 +170,18 @@ public function processWithTokenListenersAndFilePath( } /** - * @param mixed $data + * @param mixed[] $data * Delegated from addError(). */ protected function addMessage( - $isError, - $message, - $line, - $column, - $sniffClassOrCode, - $data, - $severity, - $isFixable = false + bool $isError, + string $message, + int $line, + int $column, + string $sniffClassOrCode, + array $data, + int $severity, + bool $isFixable = false ): bool { // skip warnings if (! $isError) { diff --git a/tests/DependencyInjection/MutualExcludedCheckers/config/config.php b/tests/DependencyInjection/MutualExcludedCheckers/config/config.php index 8215952229..92e5f47322 100644 --- a/tests/DependencyInjection/MutualExcludedCheckers/config/config.php +++ b/tests/DependencyInjection/MutualExcludedCheckers/config/config.php @@ -3,7 +3,7 @@ declare(strict_types=1); use PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\DisallowTabIndentSniff; -use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\LanguageConstructSpacingSniff; +use PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\LanguageConstructSpacingSniff; use PhpCsFixer\Fixer\ControlStructure\IncludeFixer; use PhpCsFixer\Fixer\Whitespace\IndentationTypeFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; diff --git a/tests/SniffRunner/Application/FixerTest.php b/tests/SniffRunner/Application/FixerTest.php index 55b28e0e0c..3b43b14e63 100644 --- a/tests/SniffRunner/Application/FixerTest.php +++ b/tests/SniffRunner/Application/FixerTest.php @@ -40,8 +40,10 @@ public function testTokenContent(): void $this->file->parse(); $this->fixer->startFile($this->file); + // Tokenization of identifier names changed in PHPCS from 3.x to 4.0 + // https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Version-4.0-Developer-Upgrade-Guide#namespaced-names $token = $this->fixer->getTokenContent(14); - $this->assertSame('\\', $token); + $this->assertSame('Symplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSource', $token); $this->fixer->replaceToken(14, '_'); $token = $this->fixer->getTokenContent(14); @@ -59,11 +61,11 @@ public function testAddContent(): void $this->fixer->addContentBefore(14, 'A'); $token = $this->fixer->getTokenContent(14); - $this->assertSame('A\\', $token); + $this->assertSame('ASymplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSource', $token); $this->fixer->addContent(14, 'B'); $token = $this->fixer->getTokenContent(14); - $this->assertSame('A\\B', $token); + $this->assertSame('ASymplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSourceB', $token); } public function testChangesets(): void @@ -73,32 +75,32 @@ public function testChangesets(): void $this->fixer->beginChangeSet(); $tokenContent = $this->fixer->getTokenContent(14); - $this->assertSame('\\', $tokenContent); + $this->assertSame('Symplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSource', $tokenContent); $this->fixer->addContentBefore(14, 'A'); $tokenContent = $this->fixer->getTokenContent(14); - $this->assertSame('A\\', $tokenContent); + $this->assertSame('ASymplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSource', $tokenContent); // during the changeset, you are free to modify current token as you wish... $this->fixer->addContent(14, 'B'); $tokenContent = $this->fixer->getTokenContent(14); - $this->assertSame('A\\B', $tokenContent); + $this->assertSame('ASymplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSourceB', $tokenContent); // you can also rollback the changes... $this->fixer->rollbackChangeset(); $tokenContent = $this->fixer->getTokenContent(14); - $this->assertSame('\\', $tokenContent); + $this->assertSame('Symplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSource', $tokenContent); $this->fixer->addContent(14, 'B'); $this->fixer->endChangeSet(); $tokenContent = $this->fixer->getTokenContent(14); - $this->assertSame('\\B', $tokenContent); + $this->assertSame('Symplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSourceB', $tokenContent); // ...that stops being the case after changeset is committed $this->fixer->addContent(14, 'C'); $tokenContent = $this->fixer->getTokenContent(14); - $this->assertSame('\\B', $tokenContent); + $this->assertSame('Symplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSourceB', $tokenContent); } public function testAddNewline(): void @@ -108,15 +110,15 @@ public function testAddNewline(): void $this->fixer->beginChangeSet(); $token = $this->fixer->getTokenContent(14); - $this->assertSame('\\', $token); + $this->assertSame('Symplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSource', $token); $this->fixer->addNewline(14); $token = $this->fixer->getTokenContent(14); - $this->assertSame('\\' . PHP_EOL, $token); + $this->assertSame('Symplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSource' . PHP_EOL, $token); $this->fixer->addNewlineBefore(14); $token = $this->fixer->getTokenContent(14); - $this->assertSame(PHP_EOL . '\\' . PHP_EOL, $token); + $this->assertSame(PHP_EOL . 'Symplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSource' . PHP_EOL, $token); } public function testSubstrToken(): void @@ -125,19 +127,19 @@ public function testSubstrToken(): void $this->fixer->startFile($this->file); $this->fixer->beginChangeSet(); - $token = $this->fixer->getTokenContent(15); - $this->assertSame('EasyCodingStandard', $token); + $token = $this->fixer->getTokenContent(14); + $this->assertSame('Symplify\EasyCodingStandard\Tests\SniffRunner\Application\FixerSource', $token); - $this->fixer->substrToken(15, 0, 4); - $token = $this->fixer->getTokenContent(15); - $this->assertSame('Easy', $token); + $this->fixer->substrToken(14, 0, 4); + $token = $this->fixer->getTokenContent(14); + $this->assertSame('Symp', $token); - $this->fixer->substrToken(15, 3); - $token = $this->fixer->getTokenContent(15); - $this->assertSame('y', $token); + $this->fixer->substrToken(14, 3); + $token = $this->fixer->getTokenContent(14); + $this->assertSame('p', $token); - $this->fixer->substrToken(17, 3, 0); - $token = $this->fixer->getTokenContent(17); + $this->fixer->substrToken(14, 3, 0); + $token = $this->fixer->getTokenContent(14); $this->assertSame('', $token); } }