From 30489249104ffb01ccb5aa062b1f720b106dde73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Fri, 4 Jul 2025 08:17:25 +0200 Subject: [PATCH] Update dev tools --- .dev-tools/composer.json | 6 +- .dev-tools/composer.lock | 76 +++++++-------- .../src/Fixer/PriorityInternalFixer.php | 4 +- .dev-tools/src/Priority/PriorityFixer.php | 6 +- .dev-tools/src/Readme/ReadmeCommand.php | 96 +++++++++---------- src/Analyzer/Analysis/ConstructorAnalysis.php | 6 +- src/Analyzer/ArrayAnalyzer.php | 18 ++-- src/Analyzer/ConstructorAnalyzer.php | 4 +- src/Analyzer/SwitchAnalyzer.php | 20 ++-- src/Fixer/ClassConstantUsageFixer.php | 12 +-- src/Fixer/CommentedOutFunctionFixer.php | 16 ++-- src/Fixer/ForeachUseValueFixer.php | 13 ++- ...ltilineCommentOpeningClosingAloneFixer.php | 8 +- src/Fixer/NoCommentedOutCodeFixer.php | 14 +-- .../NoImportFromGlobalNamespaceFixer.php | 12 +-- .../NoLeadingSlashInGlobalNamespaceFixer.php | 8 +- .../NoReferenceInFunctionDefinitionFixer.php | 4 +- src/Fixer/NoSuperfluousConcatenationFixer.php | 18 ++-- .../NoTrailingCommaInSinglelineFixer.php | 4 +- src/Fixer/NoUselessCommentFixer.php | 4 +- src/Fixer/NoUselessDirnameCallFixer.php | 8 +- src/Fixer/NoUselessParenthesisFixer.php | 26 ++--- src/Fixer/NoUselessStrlenFixer.php | 16 ++-- src/Fixer/NumericLiteralSeparatorFixer.php | 28 +++--- .../PhpUnitAssertArgumentsOrderFixer.php | 4 +- src/Fixer/PhpUnitDedicatedAssertFixer.php | 4 +- src/Fixer/PhpUnitNoUselessReturnFixer.php | 4 +- src/Fixer/PhpUnitRequiresConstraintFixer.php | 4 +- .../PhpdocNoIncorrectVarAnnotationFixer.php | 28 +++--- src/Fixer/PhpdocNoSuperfluousParamFixer.php | 12 +-- src/Fixer/PhpdocSelfAccessorFixer.php | 12 +-- .../PhpdocVarAnnotationToAssertFixer.php | 26 ++--- .../PromotedConstructorPropertyFixer.php | 40 ++++---- src/Fixer/ReadonlyPromotedPropertiesFixer.php | 4 +- src/Fixer/SingleSpaceBeforeStatementFixer.php | 8 +- src/Fixer/StringableInterfaceFixer.php | 20 ++-- tests/AutoReview/SrcCodeTest.php | 6 +- tests/AutoReview/TestsCodeTest.php | 16 ++-- tests/Fixer/AbstractFixerTestCase.php | 8 +- .../NumericLiteralSeparatorFixerTest.php | 4 +- .../SingleSpaceAfterStatementFixerTest.php | 8 +- tests/FixersTest.php | 6 +- tests/PriorityTest.php | 10 +- 43 files changed, 325 insertions(+), 326 deletions(-) diff --git a/.dev-tools/composer.json b/.dev-tools/composer.json index 8f863fff..7e876070 100644 --- a/.dev-tools/composer.json +++ b/.dev-tools/composer.json @@ -3,9 +3,9 @@ "require": { "php": "^8.4", "ergebnis/composer-normalize": "^2.47", - "infection/infection": "^0.29.14", + "infection/infection": "^0.30.1", "kubawerlos/composer-smaller-lock": "^1.1.0", - "kubawerlos/php-cs-fixer-config": "^5.2", + "kubawerlos/php-cs-fixer-config": "^5.3", "mi-schi/phpmd-extension": "^4.3", "phpmd/phpmd": "^2.15", "phpstan/extension-installer": "^1.4.3", @@ -13,7 +13,7 @@ "phpstan/phpstan-phpunit": "^2.0.6", "phpstan/phpstan-strict-rules": "^2.0.4", "shipmonk/composer-dependency-analyser": "^1.8.3", - "squizlabs/php_codesniffer": "^3.13.0", + "squizlabs/php_codesniffer": "^3.13.2", "tomasvotruba/type-coverage": "^2.0.2", "vimeo/psalm": "^6.12" }, diff --git a/.dev-tools/composer.lock b/.dev-tools/composer.lock index 994edd69..c5d9107f 100644 --- a/.dev-tools/composer.lock +++ b/.dev-tools/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "af0922b4afe03f9e5cc05a7c2534ae29", + "content-hash": "0d7bb777898746275cb9b509f52d9a02", "packages": [ { "name": "amphp/amp", @@ -1006,16 +1006,16 @@ }, { "name": "infection/infection", - "version": "0.29.14", + "version": "0.30.1", "source": { "type": "git", "url": "https://github.com/infection/infection.git", - "reference": "feea2a48a8aeedd3a4d2105167b41a46f0e568a3" + "reference": "70cd94675f6372cf13962d9d52de86b02a909c09" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/infection/infection/zipball/feea2a48a8aeedd3a4d2105167b41a46f0e568a3", - "reference": "feea2a48a8aeedd3a4d2105167b41a46f0e568a3" + "url": "https://api.github.com/repos/infection/infection/zipball/70cd94675f6372cf13962d9d52de86b02a909c09", + "reference": "70cd94675f6372cf13962d9d52de86b02a909c09" }, "require": { "colinodell/json5": "^2.2 || ^3.0", @@ -1034,8 +1034,8 @@ "nikic/php-parser": "^5.3", "ondram/ci-detector": "^4.1.0", "php": "^8.2", - "sanmai/later": "^0.1.1", - "sanmai/pipeline": "^5.1 || ^6", + "sanmai/later": "^0.1.7", + "sanmai/pipeline": "^6.16", "sebastian/diff": "^3.0.2 || ^4.0 || ^5.0 || ^6.0 || ^7.0", "symfony/console": "^6.4 || ^7.0", "symfony/filesystem": "^6.4 || ^7.0", @@ -1189,21 +1189,21 @@ }, { "name": "kubawerlos/php-cs-fixer-config", - "version": "v5.2.0", + "version": "v5.3.0", "source": { "type": "git", "url": "https://github.com/kubawerlos/php-cs-fixer-config.git", - "reference": "418690193c9b5f7625363021ab9594e2c5064a67" + "reference": "b9e9ed4eb42ed45dfc1e71dcf6ce4ad750c49f36" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-config/zipball/418690193c9b5f7625363021ab9594e2c5064a67", - "reference": "418690193c9b5f7625363021ab9594e2c5064a67" + "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-config/zipball/b9e9ed4eb42ed45dfc1e71dcf6ce4ad750c49f36", + "reference": "b9e9ed4eb42ed45dfc1e71dcf6ce4ad750c49f36" }, "require": { - "kubawerlos/php-cs-fixer-custom-fixers": "^3.27", + "kubawerlos/php-cs-fixer-custom-fixers": "^3.28", "php": "^8.3", - "php-cs-fixer/shim": "^3.71" + "php-cs-fixer/shim": "^3.76" }, "bin": [ "fixinit" @@ -1221,21 +1221,21 @@ }, { "name": "kubawerlos/php-cs-fixer-custom-fixers", - "version": "v3.27.0", + "version": "v3.28.0", "source": { "type": "git", "url": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers.git", - "reference": "d860473d16b906c7945206177edc7d112357a706" + "reference": "6115bffca3b8d1bfbd7eff7bdd5df1ffb3c8eddc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-custom-fixers/zipball/d860473d16b906c7945206177edc7d112357a706", - "reference": "d860473d16b906c7945206177edc7d112357a706" + "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-custom-fixers/zipball/6115bffca3b8d1bfbd7eff7bdd5df1ffb3c8eddc", + "reference": "6115bffca3b8d1bfbd7eff7bdd5df1ffb3c8eddc" }, "require": { "ext-filter": "*", "ext-tokenizer": "*", - "friendsofphp/php-cs-fixer": "^3.61.1", + "friendsofphp/php-cs-fixer": "^3.76", "php": "^7.4 || ^8.0" }, "type": "library", @@ -1579,16 +1579,16 @@ }, { "name": "php-cs-fixer/shim", - "version": "v3.75.0", + "version": "v3.76.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/shim.git", - "reference": "eea219a577085bd13ff0cb644a422c20798316c7" + "reference": "b6804c2a1a4fbff582446a44ad678ae1689df1c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/eea219a577085bd13ff0cb644a422c20798316c7", - "reference": "eea219a577085bd13ff0cb644a422c20798316c7" + "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/b6804c2a1a4fbff582446a44ad678ae1689df1c3", + "reference": "b6804c2a1a4fbff582446a44ad678ae1689df1c3" }, "require": { "ext-json": "*", @@ -2107,16 +2107,16 @@ }, { "name": "sanmai/pipeline", - "version": "6.16", + "version": "6.18", "source": { "type": "git", "url": "https://github.com/sanmai/pipeline.git", - "reference": "f32413630904f83b069a7fbdfab34267dbaecdb6" + "reference": "d9fbdf2a4a363f44f4d8155f71766f35d49b8fb2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sanmai/pipeline/zipball/f32413630904f83b069a7fbdfab34267dbaecdb6", - "reference": "f32413630904f83b069a7fbdfab34267dbaecdb6" + "url": "https://api.github.com/repos/sanmai/pipeline/zipball/d9fbdf2a4a363f44f4d8155f71766f35d49b8fb2", + "reference": "d9fbdf2a4a363f44f4d8155f71766f35d49b8fb2" }, "require": { "php": ">=8.2" @@ -2239,16 +2239,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.13.0", + "version": "3.13.2", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "65ff2489553b83b4597e89c3b8b721487011d186" + "reference": "5b5e3821314f947dd040c70f7992a64eac89025c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/65ff2489553b83b4597e89c3b8b721487011d186", - "reference": "65ff2489553b83b4597e89c3b8b721487011d186" + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5b5e3821314f947dd040c70f7992a64eac89025c", + "reference": "5b5e3821314f947dd040c70f7992a64eac89025c" }, "require": { "ext-simplexml": "*", @@ -2306,16 +2306,16 @@ }, { "name": "symfony/console", - "version": "v7.3.0", + "version": "v7.3.1", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "66c1440edf6f339fd82ed6c7caa76cb006211b44" + "reference": "9e27aecde8f506ba0fd1d9989620c04a87697101" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/66c1440edf6f339fd82ed6c7caa76cb006211b44", - "reference": "66c1440edf6f339fd82ed6c7caa76cb006211b44" + "url": "https://api.github.com/repos/symfony/console/zipball/9e27aecde8f506ba0fd1d9989620c04a87697101", + "reference": "9e27aecde8f506ba0fd1d9989620c04a87697101" }, "require": { "php": ">=8.2", @@ -2343,16 +2343,16 @@ }, { "name": "symfony/dependency-injection", - "version": "v7.3.0", + "version": "v7.3.1", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "f64a8f3fa7d4ad5e85de1b128a0e03faed02b732" + "reference": "8656c4848b48784c4bb8c4ae50d2b43f832cead8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/f64a8f3fa7d4ad5e85de1b128a0e03faed02b732", - "reference": "f64a8f3fa7d4ad5e85de1b128a0e03faed02b732" + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/8656c4848b48784c4bb8c4ae50d2b43f832cead8", + "reference": "8656c4848b48784c4bb8c4ae50d2b43f832cead8" }, "require": { "php": ">=8.2", diff --git a/.dev-tools/src/Fixer/PriorityInternalFixer.php b/.dev-tools/src/Fixer/PriorityInternalFixer.php index ba009259..32a00ce8 100644 --- a/.dev-tools/src/Fixer/PriorityInternalFixer.php +++ b/.dev-tools/src/Fixer/PriorityInternalFixer.php @@ -80,7 +80,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $sequencesStartIndex = \key($indices); \assert(\is_int($sequencesStartIndex)); - $commentContent = $this->getCommentContent($className); + $commentContent = self::getCommentContent($className); if ($tokens[$sequencesStartIndex - 2]->isGivenKind(\T_DOC_COMMENT)) { $tokens[$sequencesStartIndex - 2] = new Token([\T_DOC_COMMENT, $commentContent]); @@ -117,7 +117,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $tokens->overrideRange($priorityStartIndex, $priorityEndIndex, $priorityTokens); } - private function getCommentContent(string $className): string + private static function getCommentContent(string $className): string { $comment = "/**\n"; $priorityCollection = PriorityCollection::create(); diff --git a/.dev-tools/src/Priority/PriorityFixer.php b/.dev-tools/src/Priority/PriorityFixer.php index 23d6a972..d8a05f54 100644 --- a/.dev-tools/src/Priority/PriorityFixer.php +++ b/.dev-tools/src/Priority/PriorityFixer.php @@ -65,7 +65,7 @@ public function getPriority(): int */ public function getFixerToRunAfterNames(): array { - return $this->getFixerNames($this->fixersToRunAfter); + return self::getFixerNames($this->fixersToRunAfter); } /** @@ -73,7 +73,7 @@ public function getFixerToRunAfterNames(): array */ public function getFixerToRunBeforeNames(): array { - return $this->getFixerNames($this->fixersToRunBefore); + return self::getFixerNames($this->fixersToRunBefore); } public function calculatePriority(bool $requireAllRelationHavePriority): bool @@ -107,7 +107,7 @@ public function calculatePriority(bool $requireAllRelationHavePriority): bool * * @return list */ - private function getFixerNames(array $priorityFixers): array + private static function getFixerNames(array $priorityFixers): array { $fixers = \array_map( static fn (self $priorityFixer): string => (new \ReflectionObject($priorityFixer->fixer))->getShortName(), diff --git a/.dev-tools/src/Readme/ReadmeCommand.php b/.dev-tools/src/Readme/ReadmeCommand.php index eb16a1ff..27d2bc02 100644 --- a/.dev-tools/src/Readme/ReadmeCommand.php +++ b/.dev-tools/src/Readme/ReadmeCommand.php @@ -45,72 +45,72 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->write( "\n\n" . \sprintf('# %s', self::NAME) . "\n\n" - . $this->badges() . "\n\n" - . $this->description() . "\n\n" - . $this->installation() . "\n\n" - . $this->usage() . "\n\n" - . $this->fixers() . "\n\n" - . $this->contributing() . "\n", + . self::badges() . "\n\n" + . self::description() . "\n\n" + . self::installation() . "\n\n" + . self::usage() . "\n\n" + . self::fixers() . "\n\n" + . self::contributing() . "\n", ); return self::SUCCESS; } - private function badges(): string + private static function badges(): string { return \implode("\n", [ - $this->badge( + self::badge( 'Latest stable version', - \sprintf('%s/packagist/v/%s.svg?label=current%%20version', self::SHIELDS_HOST, $this->composer()->name), - \sprintf('https://packagist.org/packages/%s', $this->composer()->name), + \sprintf('%s/packagist/v/%s.svg?label=current%%20version', self::SHIELDS_HOST, self::composer()->name), + \sprintf('https://packagist.org/packages/%s', self::composer()->name), ), - $this->badge( + self::badge( 'PHP version', - \sprintf('%s/packagist/php-v/%s.svg', self::SHIELDS_HOST, $this->composer()->name), + \sprintf('%s/packagist/php-v/%s.svg', self::SHIELDS_HOST, self::composer()->name), 'https://php.net', ), - $this->badge( + self::badge( 'License', - \sprintf('%s/github/license/%s.svg', self::SHIELDS_HOST, $this->composer()->name), + \sprintf('%s/github/license/%s.svg', self::SHIELDS_HOST, self::composer()->name), 'LICENSE', ), - $this->badge( + self::badge( 'Tests', - \sprintf('%s/badge/tests-%d-brightgreen.svg', self::SHIELDS_HOST, $this->numberOfTests()), + \sprintf('%s/badge/tests-%d-brightgreen.svg', self::SHIELDS_HOST, self::numberOfTests()), ), - $this->badge( + self::badge( 'Downloads', - \sprintf('%s/packagist/dt/%s.svg', self::SHIELDS_HOST, $this->composer()->name), - \sprintf('https://packagist.org/packages/%s', $this->composer()->name), + \sprintf('%s/packagist/dt/%s.svg', self::SHIELDS_HOST, self::composer()->name), + \sprintf('https://packagist.org/packages/%s', self::composer()->name), ), '', - $this->badge( + self::badge( 'CI status', - \sprintf('https://github.com/%s/actions/workflows/ci.yaml/badge.svg', $this->composer()->name), - \sprintf('https://github.com/%s/actions/workflows/ci.yaml', $this->composer()->name), + \sprintf('https://github.com/%s/actions/workflows/ci.yaml/badge.svg', self::composer()->name), + \sprintf('https://github.com/%s/actions/workflows/ci.yaml', self::composer()->name), ), - $this->badge( + self::badge( 'Code coverage', - \sprintf('%s/coveralls/github/%s/main.svg', self::SHIELDS_HOST, $this->composer()->name), - \sprintf('https://coveralls.io/github/%s?branch=main', $this->composer()->name), + \sprintf('%s/coveralls/github/%s/main.svg', self::SHIELDS_HOST, self::composer()->name), + \sprintf('https://coveralls.io/github/%s?branch=main', self::composer()->name), ), - $this->badge( + self::badge( 'Mutation testing badge', \sprintf( 'https://img.shields.io/endpoint?style=flat&url=%s', - \rawurlencode(\sprintf('https://badge-api.stryker-mutator.io/github.com/%s/main', $this->composer()->name)), + \rawurlencode(\sprintf('https://badge-api.stryker-mutator.io/github.com/%s/main', self::composer()->name)), ), - \sprintf('https://dashboard.stryker-mutator.io/reports/github.com/%s/main', $this->composer()->name), + \sprintf('https://dashboard.stryker-mutator.io/reports/github.com/%s/main', self::composer()->name), ), - $this->badge( + self::badge( 'Psalm type coverage', - \sprintf('https://shepherd.dev/github/%s/coverage.svg', $this->composer()->name), - \sprintf('https://shepherd.dev/github/%s', $this->composer()->name), + \sprintf('https://shepherd.dev/github/%s/coverage.svg', self::composer()->name), + \sprintf('https://shepherd.dev/github/%s', self::composer()->name), ), ]); } - private function badge(string $description, string $imageUrl, ?string $targetUrl = null): string + private static function badge(string $description, string $imageUrl, ?string $targetUrl = null): string { $badge = \sprintf('![%s](%s)', $description, $imageUrl); @@ -121,7 +121,7 @@ private function badge(string $description, string $imageUrl, ?string $targetUrl return $badge; } - private function numberOfTests(): int + private static function numberOfTests(): int { $process = new Process([__DIR__ . '/../../../vendor/bin/phpunit', '--list-tests'], __DIR__ . '/../../..'); $process->run(); @@ -129,16 +129,16 @@ private function numberOfTests(): int return \substr_count($process->getOutput(), \PHP_EOL) - 3; // 3 is for header } - private function description(): string + private static function description(): string { return \str_replace( 'PHP CS Fixer', '[PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)', - $this->composer()->description, + self::composer()->description, ) . '.'; } - private function installation(): string + private static function installation(): string { return \sprintf( '## Installation @@ -148,11 +148,11 @@ private function installation(): string ``` ', self::NAME, - $this->composer()->name, + self::composer()->name, ); } - private function usage(): string + private static function usage(): string { return \sprintf( '## Usage @@ -166,15 +166,15 @@ private function usage(): string require __DIR__ . \'/vendor/%s/bootstrap.php\'; ``` ', - $this->diff( + self::diff( \file_get_contents(__DIR__ . '/php-cs-fixer.config.before.txt'), \file_get_contents(__DIR__ . '/php-cs-fixer.config.after.txt'), ), - $this->composer()->name, + self::composer()->name, ); } - private function fixers(): string + private static function fixers(): string { $output = '## Fixers'; @@ -245,19 +245,19 @@ private function fixers(): string $fixer->configure($codeSample->getConfiguration() ?? []); } $tokens = Tokens::fromCode($originalCode); - $fixer->fix($this->createSplFileInfoDouble(), $tokens); + $fixer->fix(self::createSplFileInfoDouble(), $tokens); $fixedCode = $tokens->generateCode(); $output .= \sprintf( "\n```diff\n%s\n```\n", - $this->diff($originalCode, $fixedCode), + self::diff($originalCode, $fixedCode), ); } return $output; } - private function diff(string $from, string $to): string + private static function diff(string $from, string $to): string { static $differ; @@ -277,7 +277,7 @@ private function diff(string $from, string $to): string return \substr($diff, $start + 1, -1); } - private function createSplFileInfoDouble(): \SplFileInfo + private static function createSplFileInfoDouble(): \SplFileInfo { return new class (\getcwd() . \DIRECTORY_SEPARATOR . 'file.php') extends \SplFileInfo { public function __construct(string $filename) @@ -292,7 +292,7 @@ public function getRealPath(): string }; } - private function contributing(): string + private static function contributing(): string { return \sprintf( '## Contributing @@ -303,11 +303,11 @@ private function contributing(): string composer verify ``` and submit a pull request.', - $this->composer()->name, + self::composer()->name, ); } - private function composer(): \stdClass + private static function composer(): \stdClass { return \json_decode(\file_get_contents(__DIR__ . '/../../../composer.json')); } diff --git a/src/Analyzer/Analysis/ConstructorAnalysis.php b/src/Analyzer/Analysis/ConstructorAnalysis.php index 4c12f065..9d714cd8 100644 --- a/src/Analyzer/Analysis/ConstructorAnalysis.php +++ b/src/Analyzer/Analysis/ConstructorAnalysis.php @@ -134,11 +134,11 @@ public function getConstructorPromotableAssignments(): array $propertyToVariableMap[$propertyIndex] = $index; } - foreach ($this->getDuplicatesIndices($properties) as $duplicate) { + foreach (self::getDuplicatesIndices($properties) as $duplicate) { unset($variables[$propertyToVariableMap[$duplicate]]); } - foreach ($this->getDuplicatesIndices($variables) as $duplicate) { + foreach (self::getDuplicatesIndices($variables) as $duplicate) { unset($variables[$duplicate]); } @@ -182,7 +182,7 @@ private function getPropertyIndex(int $index, int $openBrace): ?int * * @return array */ - private function getDuplicatesIndices(array $array): array + private static function getDuplicatesIndices(array $array): array { $duplicates = []; $values = []; diff --git a/src/Analyzer/ArrayAnalyzer.php b/src/Analyzer/ArrayAnalyzer.php index ba6297ea..734b5092 100644 --- a/src/Analyzer/ArrayAnalyzer.php +++ b/src/Analyzer/ArrayAnalyzer.php @@ -32,7 +32,7 @@ public function getElements(Tokens $tokens, int $index): array $arrayContentEndIndex = $tokens->getPrevMeaningfulToken($tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index)); \assert(\is_int($arrayContentEndIndex)); - return $this->getElementsForArrayContent($tokens, $arrayContentStartIndex, $arrayContentEndIndex); + return self::getElementsForArrayContent($tokens, $arrayContentStartIndex, $arrayContentEndIndex); } if ($tokens[$index]->isGivenKind(\T_ARRAY)) { @@ -45,7 +45,7 @@ public function getElements(Tokens $tokens, int $index): array $arrayContentEndIndex = $tokens->getPrevMeaningfulToken($tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $arrayOpenBraceIndex)); \assert(\is_int($arrayContentEndIndex)); - return $this->getElementsForArrayContent($tokens, $arrayContentStartIndex, $arrayContentEndIndex); + return self::getElementsForArrayContent($tokens, $arrayContentStartIndex, $arrayContentEndIndex); } throw new \InvalidArgumentException(\sprintf('Index %d is not an array.', $index)); @@ -54,12 +54,12 @@ public function getElements(Tokens $tokens, int $index): array /** * @return list */ - private function getElementsForArrayContent(Tokens $tokens, int $startIndex, int $endIndex): array + private static function getElementsForArrayContent(Tokens $tokens, int $startIndex, int $endIndex): array { $elements = []; $index = $startIndex; - while ($endIndex >= $index = $this->nextCandidateIndex($tokens, $index)) { + while ($endIndex >= $index = self::nextCandidateIndex($tokens, $index)) { if (!$tokens[$index]->equals(',')) { continue; } @@ -67,23 +67,23 @@ private function getElementsForArrayContent(Tokens $tokens, int $startIndex, int $elementEndIndex = $tokens->getPrevMeaningfulToken($index); \assert(\is_int($elementEndIndex)); - $elements[] = $this->createArrayElementAnalysis($tokens, $startIndex, $elementEndIndex); + $elements[] = self::createArrayElementAnalysis($tokens, $startIndex, $elementEndIndex); $startIndex = $tokens->getNextMeaningfulToken($index); \assert(\is_int($startIndex)); } if ($startIndex <= $endIndex) { - $elements[] = $this->createArrayElementAnalysis($tokens, $startIndex, $endIndex); + $elements[] = self::createArrayElementAnalysis($tokens, $startIndex, $endIndex); } return $elements; } - private function createArrayElementAnalysis(Tokens $tokens, int $startIndex, int $endIndex): ArrayElementAnalysis + private static function createArrayElementAnalysis(Tokens $tokens, int $startIndex, int $endIndex): ArrayElementAnalysis { $index = $startIndex; - while ($endIndex > $index = $this->nextCandidateIndex($tokens, $index)) { + while ($endIndex > $index = self::nextCandidateIndex($tokens, $index)) { if (!$tokens[$index]->isGivenKind(\T_DOUBLE_ARROW)) { continue; } @@ -100,7 +100,7 @@ private function createArrayElementAnalysis(Tokens $tokens, int $startIndex, int return new ArrayElementAnalysis(null, null, $startIndex, $endIndex); } - private function nextCandidateIndex(Tokens $tokens, int $index): int + private static function nextCandidateIndex(Tokens $tokens, int $index): int { if ($tokens[$index]->equals('{')) { return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index) + 1; diff --git a/src/Analyzer/ConstructorAnalyzer.php b/src/Analyzer/ConstructorAnalyzer.php index b869087c..8511c3a0 100644 --- a/src/Analyzer/ConstructorAnalyzer.php +++ b/src/Analyzer/ConstructorAnalyzer.php @@ -34,7 +34,7 @@ public function findNonAbstractConstructor(Tokens $tokens, int $classIndex): ?Co continue; } - if (!$this->isConstructor($tokens, $index, $element)) { + if (!self::isConstructor($tokens, $index, $element)) { continue; } @@ -52,7 +52,7 @@ public function findNonAbstractConstructor(Tokens $tokens, int $classIndex): ?Co /** * @param array $element */ - private function isConstructor(Tokens $tokens, int $index, array $element): bool + private static function isConstructor(Tokens $tokens, int $index, array $element): bool { if ($element['type'] !== 'method') { return false; diff --git a/src/Analyzer/SwitchAnalyzer.php b/src/Analyzer/SwitchAnalyzer.php index d2aefc5d..e3a4c45d 100644 --- a/src/Analyzer/SwitchAnalyzer.php +++ b/src/Analyzer/SwitchAnalyzer.php @@ -26,19 +26,19 @@ public function getSwitchAnalysis(Tokens $tokens, int $switchIndex): SwitchAnaly throw new \InvalidArgumentException(\sprintf('Index %d is not "switch".', $switchIndex)); } - $casesStartIndex = $this->getCasesStart($tokens, $switchIndex); - $casesEndIndex = $this->getCasesEnd($tokens, $casesStartIndex); + $casesStartIndex = self::getCasesStart($tokens, $switchIndex); + $casesEndIndex = self::getCasesEnd($tokens, $casesStartIndex); $cases = []; $index = $casesStartIndex; while ($index < $casesEndIndex) { - $index = $this->getNextSameLevelToken($tokens, $index); + $index = self::getNextSameLevelToken($tokens, $index); if (!$tokens[$index]->isGivenKind([\T_CASE, \T_DEFAULT])) { continue; } - $caseAnalysis = $this->getCaseAnalysis($tokens, $index); + $caseAnalysis = self::getCaseAnalysis($tokens, $index); $cases[] = $caseAnalysis; } @@ -46,7 +46,7 @@ public function getSwitchAnalysis(Tokens $tokens, int $switchIndex): SwitchAnaly return new SwitchAnalysis($casesStartIndex, $casesEndIndex, $cases); } - private function getCasesStart(Tokens $tokens, int $switchIndex): int + private static function getCasesStart(Tokens $tokens, int $switchIndex): int { $parenthesisStartIndex = $tokens->getNextMeaningfulToken($switchIndex); \assert(\is_int($parenthesisStartIndex)); @@ -58,7 +58,7 @@ private function getCasesStart(Tokens $tokens, int $switchIndex): int return $casesStartIndex; } - private function getCasesEnd(Tokens $tokens, int $casesStartIndex): int + private static function getCasesEnd(Tokens $tokens, int $casesStartIndex): int { if ($tokens[$casesStartIndex]->equals('{')) { return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $casesStartIndex); @@ -66,7 +66,7 @@ private function getCasesEnd(Tokens $tokens, int $casesStartIndex): int $index = $casesStartIndex; while ($index < $tokens->count()) { - $index = $this->getNextSameLevelToken($tokens, $index); + $index = self::getNextSameLevelToken($tokens, $index); if ($tokens[$index]->isGivenKind(\T_ENDSWITCH)) { break; @@ -79,10 +79,10 @@ private function getCasesEnd(Tokens $tokens, int $casesStartIndex): int return $tokens[$afterEndswitchIndex]->equals(';') ? $afterEndswitchIndex : $index; } - private function getCaseAnalysis(Tokens $tokens, int $index): CaseAnalysis + private static function getCaseAnalysis(Tokens $tokens, int $index): CaseAnalysis { while ($index < $tokens->count()) { - $index = $this->getNextSameLevelToken($tokens, $index); + $index = self::getNextSameLevelToken($tokens, $index); if ($tokens[$index]->equalsAny([':', ';'])) { break; @@ -92,7 +92,7 @@ private function getCaseAnalysis(Tokens $tokens, int $index): CaseAnalysis return new CaseAnalysis($index); } - private function getNextSameLevelToken(Tokens $tokens, int $index): int + private static function getNextSameLevelToken(Tokens $tokens, int $index): int { $index = $tokens->getNextMeaningfulToken($index); \assert(\is_int($index)); diff --git a/src/Fixer/ClassConstantUsageFixer.php b/src/Fixer/ClassConstantUsageFixer.php index 12578cc3..b9be08bd 100644 --- a/src/Fixer/ClassConstantUsageFixer.php +++ b/src/Fixer/ClassConstantUsageFixer.php @@ -71,13 +71,13 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openParenthesisIndex); - $this->fixClass($tokens, $openParenthesisIndex, $closeParenthesisIndex); + self::fixClass($tokens, $openParenthesisIndex, $closeParenthesisIndex); } } - private function fixClass(Tokens $tokens, int $openParenthesisIndex, int $closeParenthesisIndex): void + private static function fixClass(Tokens $tokens, int $openParenthesisIndex, int $closeParenthesisIndex): void { - [$constantsMap, $constantsIndices] = $this->getClassConstants($tokens, $openParenthesisIndex, $closeParenthesisIndex); + [$constantsMap, $constantsIndices] = self::getClassConstants($tokens, $openParenthesisIndex, $closeParenthesisIndex); for ($index = $closeParenthesisIndex; $index > $openParenthesisIndex; $index--) { if (!$tokens[$index]->isGivenKind(\T_CONSTANT_ENCAPSED_STRING)) { @@ -107,7 +107,7 @@ private function fixClass(Tokens $tokens, int $openParenthesisIndex, int $closeP /** * @return array{array, array} */ - private function getClassConstants(Tokens $tokens, int $openParenthesisIndex, int $closeParenthesisIndex): array + private static function getClassConstants(Tokens $tokens, int $openParenthesisIndex, int $closeParenthesisIndex): array { $constants = []; $constantsIndices = []; @@ -134,7 +134,7 @@ private function getClassConstants(Tokens $tokens, int $openParenthesisIndex, in $constants[$tokens[$constantNameIndex]->getContent()] = $tokens[$constantValueIndex]->getContent(); } - return [$this->getClassConstantsMap($constants), $constantsIndices]; + return [self::getClassConstantsMap($constants), $constantsIndices]; } /** @@ -142,7 +142,7 @@ private function getClassConstants(Tokens $tokens, int $openParenthesisIndex, in * * @return array */ - private function getClassConstantsMap(array $constants): array + private static function getClassConstantsMap(array $constants): array { $map = []; $valuesCount = []; diff --git a/src/Fixer/CommentedOutFunctionFixer.php b/src/Fixer/CommentedOutFunctionFixer.php index 2f51df1c..b5c627b9 100644 --- a/src/Fixer/CommentedOutFunctionFixer.php +++ b/src/Fixer/CommentedOutFunctionFixer.php @@ -103,7 +103,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $startIndex = $prevIndex; } - if (!$this->isPreviousTokenSeparateStatement($tokens, $startIndex)) { + if (!self::isPreviousTokenSeparateStatement($tokens, $startIndex)) { continue; } @@ -123,7 +123,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $endIndex = $semicolonIndex; } - $this->fixBlock($tokens, $startIndex, $endIndex); + self::fixBlock($tokens, $startIndex, $endIndex); } } @@ -140,7 +140,7 @@ private function isFunctionToFix(Tokens $tokens, int $index): bool return (new FunctionsAnalyzer())->isGlobalFunctionCall($tokens, $index); } - private function isPreviousTokenSeparateStatement(Tokens $tokens, int $index): bool + private static function isPreviousTokenSeparateStatement(Tokens $tokens, int $index): bool { $prevIndex = $tokens->getPrevMeaningfulToken($index); \assert(\is_int($prevIndex)); @@ -169,10 +169,10 @@ private function isPreviousTokenSeparateStatement(Tokens $tokens, int $index): b return false; } - private function fixBlock(Tokens $tokens, int $startIndex, int $endIndex): void + private static function fixBlock(Tokens $tokens, int $startIndex, int $endIndex): void { - if ($this->canUseSingleLineComment($tokens, $startIndex, $endIndex)) { - $this->fixBlockWithSingleLineComments($tokens, $startIndex, $endIndex); + if (self::canUseSingleLineComment($tokens, $startIndex, $endIndex)) { + self::fixBlockWithSingleLineComments($tokens, $startIndex, $endIndex); return; } @@ -184,7 +184,7 @@ private function fixBlock(Tokens $tokens, int $startIndex, int $endIndex): void ); } - private function canUseSingleLineComment(Tokens $tokens, int $startIndex, int $endIndex): bool + private static function canUseSingleLineComment(Tokens $tokens, int $startIndex, int $endIndex): bool { if (!$tokens->offsetExists($endIndex + 1)) { return true; @@ -203,7 +203,7 @@ private function canUseSingleLineComment(Tokens $tokens, int $startIndex, int $e return false; } - private function fixBlockWithSingleLineComments(Tokens $tokens, int $startIndex, int $endIndex): void + private static function fixBlockWithSingleLineComments(Tokens $tokens, int $startIndex, int $endIndex): void { $codeToCommentOut = $tokens->generatePartialCode($startIndex, $endIndex); diff --git a/src/Fixer/ForeachUseValueFixer.php b/src/Fixer/ForeachUseValueFixer.php index b4f89816..86b41f20 100644 --- a/src/Fixer/ForeachUseValueFixer.php +++ b/src/Fixer/ForeachUseValueFixer.php @@ -91,7 +91,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesisIndex); - $variables = $this->getForeachVariableNames($tokens, $openParenthesisIndex); + $variables = self::getForeachVariableNames($tokens, $openParenthesisIndex); if ($variables === null) { continue; } @@ -107,14 +107,14 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $this->fixForeachBody($tokens, $blockStartIndex, $blockEndIndex, ...$variables); + self::fixForeachBody($tokens, $blockStartIndex, $blockEndIndex, ...$variables); } } /** * @return null|array{Token, string, string} */ - private function getForeachVariableNames(Tokens $tokens, int $openParenthesisIndex): ?array + private static function getForeachVariableNames(Tokens $tokens, int $openParenthesisIndex): ?array { $arrayIndex = $tokens->getNextMeaningfulToken($openParenthesisIndex); \assert(\is_int($arrayIndex)); @@ -150,7 +150,7 @@ private function getForeachVariableNames(Tokens $tokens, int $openParenthesisInd ]; } - private function fixForeachBody( + private static function fixForeachBody( Tokens $tokens, int $openBraceIndex, int $closeBraceIndex, @@ -160,7 +160,6 @@ private function fixForeachBody( ): void { $sequence = [ $arrayToken, '[', [\T_VARIABLE, $keyName], ']']; - $index = $openBraceIndex; while (($found = $tokens->findSequence($sequence, $index, $closeBraceIndex)) !== null) { $startIndex = \array_key_first($found); @@ -168,7 +167,7 @@ private function fixForeachBody( $index = $endIndex; - if ($this->isInUnset($tokens, $startIndex)) { + if (self::isInUnset($tokens, $startIndex)) { continue; } @@ -182,7 +181,7 @@ private function fixForeachBody( } } - private function isInUnset(Tokens $tokens, int $startIndex): bool + private static function isInUnset(Tokens $tokens, int $startIndex): bool { $openParenthesisIndex = $tokens->getPrevMeaningfulToken($startIndex); \assert(\is_int($openParenthesisIndex)); diff --git a/src/Fixer/MultilineCommentOpeningClosingAloneFixer.php b/src/Fixer/MultilineCommentOpeningClosingAloneFixer.php index 3b023487..fd3e778f 100644 --- a/src/Fixer/MultilineCommentOpeningClosingAloneFixer.php +++ b/src/Fixer/MultilineCommentOpeningClosingAloneFixer.php @@ -61,12 +61,12 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $this->fixOpening($tokens, $index); - $this->fixClosing($tokens, $index); + self::fixOpening($tokens, $index); + self::fixClosing($tokens, $index); } } - private function fixOpening(Tokens $tokens, int $index): void + private static function fixOpening(Tokens $tokens, int $index): void { if (Preg::match('#^/\\*+\\R#', $tokens[$index]->getContent())) { return; @@ -113,7 +113,7 @@ private function fixOpening(Tokens $tokens, int $index): void } } - private function fixClosing(Tokens $tokens, int $index): void + private static function fixClosing(Tokens $tokens, int $index): void { if (Preg::match('#\\R\\h*\\*+/$#', $tokens[$index]->getContent())) { return; diff --git a/src/Fixer/NoCommentedOutCodeFixer.php b/src/Fixer/NoCommentedOutCodeFixer.php index 2aba0806..e7bf59d1 100644 --- a/src/Fixer/NoCommentedOutCodeFixer.php +++ b/src/Fixer/NoCommentedOutCodeFixer.php @@ -69,7 +69,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $commentIndices = $commentsAnalyzer->getCommentBlockIndices($tokens, $index); } - $indicesToRemove = $this->getIndicesToRemove($tokens, $commentIndices); + $indicesToRemove = self::getIndicesToRemove($tokens, $commentIndices); if ($indicesToRemove === []) { continue; @@ -88,14 +88,14 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void * * @return list */ - private function getIndicesToRemove(Tokens $tokens, array $commentIndices): array + private static function getIndicesToRemove(Tokens $tokens, array $commentIndices): array { $indicesToRemove = []; $testedIndices = []; $content = ''; foreach ($commentIndices as $index) { - $content .= \PHP_EOL . $this->getContent($tokens[$index]); + $content .= \PHP_EOL . self::getContent($tokens[$index]); $testedIndices[] = $index; if (\rtrim($content) === '') { @@ -109,8 +109,8 @@ private function getIndicesToRemove(Tokens $tokens, array $commentIndices): arra } if ( - $this->isCorrectSyntax('isCorrectSyntax('getContent(); @@ -130,7 +130,7 @@ private function getContent(Token $token): string return \ltrim($content, '#/'); } - private function isCorrectSyntax(string $content): bool + private static function isCorrectSyntax(string $content): bool { try { @Tokens::fromCode($content); diff --git a/src/Fixer/NoImportFromGlobalNamespaceFixer.php b/src/Fixer/NoImportFromGlobalNamespaceFixer.php index 13b930ab..4a30d7e1 100644 --- a/src/Fixer/NoImportFromGlobalNamespaceFixer.php +++ b/src/Fixer/NoImportFromGlobalNamespaceFixer.php @@ -61,18 +61,18 @@ public function isRisky(): bool public function fix(\SplFileInfo $file, Tokens $tokens): void { foreach (\array_reverse((new NamespacesAnalyzer())->getDeclarations($tokens)) as $namespace) { - $this->fixImports($tokens, $namespace->getScopeStartIndex(), $namespace->getScopeEndIndex(), $namespace->getFullName() === ''); + self::fixImports($tokens, $namespace->getScopeStartIndex(), $namespace->getScopeEndIndex(), $namespace->getFullName() === ''); } } - private function fixImports(Tokens $tokens, int $startIndex, int $endIndex, bool $isInGlobalNamespace): void + private static function fixImports(Tokens $tokens, int $startIndex, int $endIndex, bool $isInGlobalNamespace): void { $importedClassesIndices = self::getImportCandidateIndices($tokens, $startIndex, $endIndex); if (!$isInGlobalNamespace) { for ($index = $endIndex; $index > $startIndex; $index--) { if ($tokens[$index]->isGivenKind(\T_DOC_COMMENT)) { - $importedClassesIndices = $this->updateComment($tokens, $importedClassesIndices, $index); + $importedClassesIndices = self::updateComment($tokens, $importedClassesIndices, $index); continue; } @@ -80,7 +80,7 @@ private function fixImports(Tokens $tokens, int $startIndex, int $endIndex, bool continue; } - $importedClassesIndices = $this->updateUsage($tokens, $importedClassesIndices, $index); + $importedClassesIndices = self::updateUsage($tokens, $importedClassesIndices, $index); } } @@ -121,7 +121,7 @@ private static function getImportCandidateIndices(Tokens $tokens, int $startInde * * @return array */ - private function updateComment(Tokens $tokens, array $importedClassesIndices, int $index): array + private static function updateComment(Tokens $tokens, array $importedClassesIndices, int $index): array { $content = $tokens[$index]->getContent(); @@ -144,7 +144,7 @@ private function updateComment(Tokens $tokens, array $importedClassesIndices, in * * @return array */ - private function updateUsage(Tokens $tokens, array $importedClassesIndices, int $index): array + private static function updateUsage(Tokens $tokens, array $importedClassesIndices, int $index): array { if (!\in_array($tokens[$index]->getContent(), \array_keys($importedClassesIndices), true)) { return $importedClassesIndices; diff --git a/src/Fixer/NoLeadingSlashInGlobalNamespaceFixer.php b/src/Fixer/NoLeadingSlashInGlobalNamespaceFixer.php index b00e3965..61a1319c 100644 --- a/src/Fixer/NoLeadingSlashInGlobalNamespaceFixer.php +++ b/src/Fixer/NoLeadingSlashInGlobalNamespaceFixer.php @@ -54,9 +54,9 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void { $index = 0; while (++$index < $tokens->count()) { - $index = $this->skipNamespacedCode($tokens, $index); + $index = self::skipNamespacedCode($tokens, $index); - if (!$this->isToRemove($tokens, $index)) { + if (!self::isToRemove($tokens, $index)) { continue; } @@ -64,7 +64,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void } } - private function isToRemove(Tokens $tokens, int $index): bool + private static function isToRemove(Tokens $tokens, int $index): bool { if (!$tokens[$index]->isGivenKind(\T_NS_SEPARATOR)) { return false; @@ -90,7 +90,7 @@ private function isToRemove(Tokens $tokens, int $index): bool return $tokens[$prevIndex]->equalsAny(['(', ',', [CT::T_TYPE_ALTERNATION]]) && $tokens[$nextIndex]->isGivenKind([\T_VARIABLE, CT::T_TYPE_ALTERNATION]); } - private function skipNamespacedCode(Tokens $tokens, int $index): int + private static function skipNamespacedCode(Tokens $tokens, int $index): int { if (!$tokens[$index]->isGivenKind(\T_NAMESPACE)) { return $index; diff --git a/src/Fixer/NoReferenceInFunctionDefinitionFixer.php b/src/Fixer/NoReferenceInFunctionDefinitionFixer.php index 0a647141..d8b68bcc 100644 --- a/src/Fixer/NoReferenceInFunctionDefinitionFixer.php +++ b/src/Fixer/NoReferenceInFunctionDefinitionFixer.php @@ -56,7 +56,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $indices = $this->getArgumentStartIndices($tokens, $index); + $indices = self::getArgumentStartIndices($tokens, $index); foreach ($indices as $i) { if ($tokens[$i]->getContent() === '&') { @@ -69,7 +69,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void /** * @return list */ - private function getArgumentStartIndices(Tokens $tokens, int $functionNameIndex): array + private static function getArgumentStartIndices(Tokens $tokens, int $functionNameIndex): array { $argumentsAnalyzer = new ArgumentsAnalyzer(); diff --git a/src/Fixer/NoSuperfluousConcatenationFixer.php b/src/Fixer/NoSuperfluousConcatenationFixer.php index 3376e71a..38dd7117 100644 --- a/src/Fixer/NoSuperfluousConcatenationFixer.php +++ b/src/Fixer/NoSuperfluousConcatenationFixer.php @@ -96,12 +96,12 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $firstIndex = $this->getFirstIndex($tokens, $index); + $firstIndex = self::getFirstIndex($tokens, $index); if ($firstIndex === null) { continue; } - $secondIndex = $this->getSecondIndex($tokens, $index); + $secondIndex = self::getSecondIndex($tokens, $index); if ($secondIndex === null) { continue; } @@ -117,7 +117,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void } } - private function getFirstIndex(Tokens $tokens, int $index): ?int + private static function getFirstIndex(Tokens $tokens, int $index): ?int { $firstIndex = $tokens->getPrevMeaningfulToken($index); \assert(\is_int($firstIndex)); @@ -125,14 +125,14 @@ private function getFirstIndex(Tokens $tokens, int $index): ?int if (!$tokens[$firstIndex]->isGivenKind(\T_CONSTANT_ENCAPSED_STRING)) { return null; } - if (!$this->areOnlyHorizontalWhitespacesBetween($tokens, $firstIndex, $index)) { + if (!self::areOnlyHorizontalWhitespacesBetween($tokens, $firstIndex, $index)) { return null; } return $firstIndex; } - private function getSecondIndex(Tokens $tokens, int $index): ?int + private static function getSecondIndex(Tokens $tokens, int $index): ?int { $secondIndex = $tokens->getNextMeaningfulToken($index); \assert(\is_int($secondIndex)); @@ -140,14 +140,14 @@ private function getSecondIndex(Tokens $tokens, int $index): ?int if (!$tokens[$secondIndex]->isGivenKind(\T_CONSTANT_ENCAPSED_STRING)) { return null; } - if (!$this->areOnlyHorizontalWhitespacesBetween($tokens, $index, $secondIndex)) { + if (!self::areOnlyHorizontalWhitespacesBetween($tokens, $index, $secondIndex)) { return null; } return $secondIndex; } - private function areOnlyHorizontalWhitespacesBetween(Tokens $tokens, int $indexStart, int $indexEnd): bool + private static function areOnlyHorizontalWhitespacesBetween(Tokens $tokens, int $indexStart, int $indexEnd): bool { for ($index = $indexStart + 1; $index < $indexEnd; $index++) { if (!$tokens[$index]->isGivenKind(\T_WHITESPACE)) { @@ -190,14 +190,14 @@ private function fixConcat(Tokens $tokens, int $firstIndex, int $secondIndex): v [ new Token( [\T_CONSTANT_ENCAPSED_STRING, - $prefix . $border . $this->getContentForBorder($firstContent, $border, true) . $this->getContentForBorder($secondContent, $border, false) . $border, + $prefix . $border . self::getContentForBorder($firstContent, $border, true) . self::getContentForBorder($secondContent, $border, false) . $border, ], ), ], ); } - private function getContentForBorder(string $content, string $targetBorder, bool $escapeDollarWhenIsLastCharacter): string + private static function getContentForBorder(string $content, string $targetBorder, bool $escapeDollarWhenIsLastCharacter): string { $currentBorder = $content[0]; $content = \substr($content, 1, -1); diff --git a/src/Fixer/NoTrailingCommaInSinglelineFixer.php b/src/Fixer/NoTrailingCommaInSinglelineFixer.php index cc7323b3..4c168911 100644 --- a/src/Fixer/NoTrailingCommaInSinglelineFixer.php +++ b/src/Fixer/NoTrailingCommaInSinglelineFixer.php @@ -58,11 +58,11 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $this->removeCommas($tokens, $index); + self::removeCommas($tokens, $index); } } - private function removeCommas(Tokens $tokens, int $index): void + private static function removeCommas(Tokens $tokens, int $index): void { $commaIndex = $tokens->getPrevMeaningfulToken($index); \assert(\is_int($commaIndex)); diff --git a/src/Fixer/NoUselessCommentFixer.php b/src/Fixer/NoUselessCommentFixer.php index 4681eeac..737a17ae 100644 --- a/src/Fixer/NoUselessCommentFixer.php +++ b/src/Fixer/NoUselessCommentFixer.php @@ -70,7 +70,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $newContent = $this->getNewContent($tokens, $index); + $newContent = self::getNewContent($tokens, $index); if ($newContent === $tokens[$index]->getContent()) { continue; @@ -83,7 +83,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void } } - private function getNewContent(Tokens $tokens, int $index): string + private static function getNewContent(Tokens $tokens, int $index): string { $content = $tokens[$index]->getContent(); diff --git a/src/Fixer/NoUselessDirnameCallFixer.php b/src/Fixer/NoUselessDirnameCallFixer.php index 26114486..2d3d95bd 100644 --- a/src/Fixer/NoUselessDirnameCallFixer.php +++ b/src/Fixer/NoUselessDirnameCallFixer.php @@ -59,12 +59,12 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $prevInserts = $this->getPrevTokensUpdates($tokens, $index); + $prevInserts = self::getPrevTokensUpdates($tokens, $index); if ($prevInserts === null) { continue; } - $nextInserts = $this->getNextTokensUpdates($tokens, $index); + $nextInserts = self::getNextTokensUpdates($tokens, $index); if ($nextInserts === null) { continue; } @@ -82,7 +82,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void /** * @return null|array */ - private function getPrevTokensUpdates(Tokens $tokens, int $index): ?array + private static function getPrevTokensUpdates(Tokens $tokens, int $index): ?array { $updates = []; @@ -115,7 +115,7 @@ private function getPrevTokensUpdates(Tokens $tokens, int $index): ?array /** * @return null|array */ - private function getNextTokensUpdates(Tokens $tokens, int $index): ?array + private static function getNextTokensUpdates(Tokens $tokens, int $index): ?array { $depthLevel = 1; $updates = []; diff --git a/src/Fixer/NoUselessParenthesisFixer.php b/src/Fixer/NoUselessParenthesisFixer.php index c942b08d..1a39f9f8 100644 --- a/src/Fixer/NoUselessParenthesisFixer.php +++ b/src/Fixer/NoUselessParenthesisFixer.php @@ -62,12 +62,12 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $blockType = Tokens::detectBlockType($tokens[$index]); $blockEndIndex = $tokens->findBlockEnd($blockType['type'], $index); - if (!$this->isBlockToRemove($tokens, $index, $blockEndIndex)) { + if (!self::isBlockToRemove($tokens, $index, $blockEndIndex)) { continue; } - $this->clearWhitespace($tokens, $index + 1); - $this->clearWhitespace($tokens, $blockEndIndex - 1); + self::clearWhitespace($tokens, $index + 1); + self::clearWhitespace($tokens, $blockEndIndex - 1); $tokens->clearTokenAndMergeSurroundingWhitespace($index); $tokens->clearTokenAndMergeSurroundingWhitespace($blockEndIndex); @@ -80,9 +80,9 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void } } - private function isBlockToRemove(Tokens $tokens, int $startIndex, int $endIndex): bool + private static function isBlockToRemove(Tokens $tokens, int $startIndex, int $endIndex): bool { - if ($this->isParenthesisBlockInside($tokens, $startIndex, $endIndex)) { + if (self::isParenthesisBlockInside($tokens, $startIndex, $endIndex)) { return true; } @@ -99,22 +99,22 @@ private function isBlockToRemove(Tokens $tokens, int $startIndex, int $endIndex) return false; } - if ($this->isForbiddenBeforeOpenParenthesis($tokens, $prevStartIndex)) { + if (self::isForbiddenBeforeOpenParenthesis($tokens, $prevStartIndex)) { return false; } - if ($this->isExpressionInside($tokens, $startIndex, $endIndex)) { + if (self::isExpressionInside($tokens, $startIndex, $endIndex)) { return true; } - if ($this->hasLowPrecedenceLogicOperator($tokens, $startIndex, $endIndex)) { + if (self::hasLowPrecedenceLogicOperator($tokens, $startIndex, $endIndex)) { return false; } return $tokens[$prevStartIndex]->equalsAny(['=', [\T_RETURN], [\T_THROW]]) && $tokens[$nextEndIndex]->equals(';'); } - private function isForbiddenBeforeOpenParenthesis(Tokens $tokens, int $index): bool + private static function isForbiddenBeforeOpenParenthesis(Tokens $tokens, int $index): bool { if ( $tokens[$index]->isGivenKind([ @@ -146,7 +146,7 @@ private function isForbiddenBeforeOpenParenthesis(Tokens $tokens, int $index): b return $blockType !== null && !$blockType['isStart']; } - private function isParenthesisBlockInside(Tokens $tokens, int $startIndex, int $endIndex): bool + private static function isParenthesisBlockInside(Tokens $tokens, int $startIndex, int $endIndex): bool { $nextStartIndex = $tokens->getNextMeaningfulToken($startIndex); \assert(\is_int($nextStartIndex)); @@ -161,7 +161,7 @@ private function isParenthesisBlockInside(Tokens $tokens, int $startIndex, int $ return (new BlocksAnalyzer())->isBlock($tokens, $nextStartIndex, $prevIndex); } - private function isExpressionInside(Tokens $tokens, int $startIndex, int $endIndex): bool + private static function isExpressionInside(Tokens $tokens, int $startIndex, int $endIndex): bool { $index = $tokens->getNextMeaningfulToken($startIndex); \assert(\is_int($index)); @@ -188,7 +188,7 @@ private function isExpressionInside(Tokens $tokens, int $startIndex, int $endInd return true; } - private function hasLowPrecedenceLogicOperator(Tokens $tokens, int $startIndex, int $endIndex): bool + private static function hasLowPrecedenceLogicOperator(Tokens $tokens, int $startIndex, int $endIndex): bool { $index = $tokens->getNextMeaningfulToken($startIndex); \assert(\is_int($index)); @@ -211,7 +211,7 @@ private function hasLowPrecedenceLogicOperator(Tokens $tokens, int $startIndex, return false; } - private function clearWhitespace(Tokens $tokens, int $index): void + private static function clearWhitespace(Tokens $tokens, int $index): void { if (!$tokens[$index]->isWhitespace()) { return; diff --git a/src/Fixer/NoUselessStrlenFixer.php b/src/Fixer/NoUselessStrlenFixer.php index 8a0396ad..26f142fd 100644 --- a/src/Fixer/NoUselessStrlenFixer.php +++ b/src/Fixer/NoUselessStrlenFixer.php @@ -94,24 +94,24 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $tokensToRemove[$prevIndex] = 1; } - if (!$this->transformCondition($tokens, $startIndex, $closeParenthesisIndex)) { + if (!self::transformCondition($tokens, $startIndex, $closeParenthesisIndex)) { continue; } - $this->removeTokenAndSiblingWhitespace($tokens, $tokensToRemove); + self::removeTokenAndSiblingWhitespace($tokens, $tokensToRemove); } } - private function transformCondition(Tokens $tokens, int $startIndex, int $endIndex): bool + private static function transformCondition(Tokens $tokens, int $startIndex, int $endIndex): bool { - if ($this->transformConditionLeft($tokens, $startIndex)) { + if (self::transformConditionLeft($tokens, $startIndex)) { return true; } - return $this->transformConditionRight($tokens, $endIndex); + return self::transformConditionRight($tokens, $endIndex); } - private function transformConditionLeft(Tokens $tokens, int $index): bool + private static function transformConditionLeft(Tokens $tokens, int $index): bool { $prevIndex = $tokens->getPrevMeaningfulToken($index); \assert(\is_int($prevIndex)); @@ -139,7 +139,7 @@ private function transformConditionLeft(Tokens $tokens, int $index): bool return true; } - private function transformConditionRight(Tokens $tokens, int $index): bool + private static function transformConditionRight(Tokens $tokens, int $index): bool { $nextIndex = $tokens->getNextMeaningfulToken($index); \assert(\is_int($nextIndex)); @@ -170,7 +170,7 @@ private function transformConditionRight(Tokens $tokens, int $index): bool /** * @param array $tokensToRemove */ - private function removeTokenAndSiblingWhitespace(Tokens $tokens, array $tokensToRemove): void + private static function removeTokenAndSiblingWhitespace(Tokens $tokens, array $tokensToRemove): void { foreach ($tokensToRemove as $index => $direction) { $tokens->clearAt($index); diff --git a/src/Fixer/NumericLiteralSeparatorFixer.php b/src/Fixer/NumericLiteralSeparatorFixer.php index 05317272..d5b95601 100644 --- a/src/Fixer/NumericLiteralSeparatorFixer.php +++ b/src/Fixer/NumericLiteralSeparatorFixer.php @@ -144,44 +144,44 @@ public function getSuccessorsNames(): array private function getNewContent(string $content): string { if (\strpos($content, '.') !== false) { - $content = $this->updateContent($content, null, '.', 3, $this->floatSeparator); - $content = $this->updateContent($content, '.', 'e', 3, $this->floatSeparator, false); + $content = self::updateContent($content, null, '.', 3, $this->floatSeparator); + $content = self::updateContent($content, '.', 'e', 3, $this->floatSeparator, false); - return $this->updateContent($content, 'e', null, 3, $this->floatSeparator); + return self::updateContent($content, 'e', null, 3, $this->floatSeparator); } if (\stripos($content, '0b') === 0) { - return $this->updateContent($content, 'b', null, 8, $this->binarySeparator); + return self::updateContent($content, 'b', null, 8, $this->binarySeparator); } if (\stripos($content, '0x') === 0) { - return $this->updateContent($content, 'x', null, 2, $this->hexadecimalSeparator); + return self::updateContent($content, 'x', null, 2, $this->hexadecimalSeparator); } if (Preg::match('/e-?[\\d_]+$/i', $content)) { - $content = $this->updateContent($content, null, 'e', 3, $this->floatSeparator); + $content = self::updateContent($content, null, 'e', 3, $this->floatSeparator); - return $this->updateContent($content, 'e', null, 3, $this->floatSeparator); + return self::updateContent($content, 'e', null, 3, $this->floatSeparator); } if (\strpos($content, '0') === 0) { - return $this->updateContent($content, '0', null, 4, $this->octalSeparator); + return self::updateContent($content, '0', null, 4, $this->octalSeparator); } - return $this->updateContent($content, null, null, 3, $this->decimalSeparator); + return self::updateContent($content, null, null, 3, $this->decimalSeparator); } - private function updateContent(string $content, ?string $startCharacter, ?string $endCharacter, int $groupSize, ?bool $addSeparators, bool $fromRight = true): string + private static function updateContent(string $content, ?string $startCharacter, ?string $endCharacter, int $groupSize, ?bool $addSeparators, bool $fromRight = true): string { if ($addSeparators === null) { return $content; } - $startPosition = $this->getStartPosition($content, $startCharacter); + $startPosition = self::getStartPosition($content, $startCharacter); if ($startPosition === null) { return $content; } - $endPosition = $this->getEndPosition($content, $endCharacter); + $endPosition = self::getEndPosition($content, $endCharacter); $substringToUpdate = \substr($content, $startPosition, $endPosition - $startPosition); $substringToUpdate = \str_replace('_', '', $substringToUpdate); @@ -201,7 +201,7 @@ private function updateContent(string $content, ?string $startCharacter, ?string return \substr($content, 0, $startPosition) . $substringToUpdate . \substr($content, $endPosition); } - private function getStartPosition(string $content, ?string $startCharacter): ?int + private static function getStartPosition(string $content, ?string $startCharacter): ?int { if ($startCharacter === null) { return 0; @@ -216,7 +216,7 @@ private function getStartPosition(string $content, ?string $startCharacter): ?in return $startPosition + 1; } - private function getEndPosition(string $content, ?string $endCharacter): int + private static function getEndPosition(string $content, ?string $endCharacter): int { if ($endCharacter === null) { return \strlen($content); diff --git a/src/Fixer/PhpUnitAssertArgumentsOrderFixer.php b/src/Fixer/PhpUnitAssertArgumentsOrderFixer.php index 2142e72c..114c9b8b 100644 --- a/src/Fixer/PhpUnitAssertArgumentsOrderFixer.php +++ b/src/Fixer/PhpUnitAssertArgumentsOrderFixer.php @@ -83,11 +83,11 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void /** @var list $indices */ foreach ($phpUnitTestCaseIndicator->findPhpUnitClasses($tokens) as $indices) { - $this->fixArgumentsOrder($tokens, $indices[0], $indices[1]); + self::fixArgumentsOrder($tokens, $indices[0], $indices[1]); } } - private function fixArgumentsOrder(Tokens $tokens, int $startIndex, int $endIndex): void + private static function fixArgumentsOrder(Tokens $tokens, int $startIndex, int $endIndex): void { for ($index = $startIndex; $index < $endIndex; $index++) { $newAssertion = self::getNewAssertion($tokens, $index); diff --git a/src/Fixer/PhpUnitDedicatedAssertFixer.php b/src/Fixer/PhpUnitDedicatedAssertFixer.php index 12e01bf7..639fd401 100644 --- a/src/Fixer/PhpUnitDedicatedAssertFixer.php +++ b/src/Fixer/PhpUnitDedicatedAssertFixer.php @@ -89,11 +89,11 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void /** @var list $indices */ foreach ($phpUnitTestCaseIndicator->findPhpUnitClasses($tokens) as $indices) { - $this->fixAssertions($tokens, $indices[0], $indices[1]); + self::fixAssertions($tokens, $indices[0], $indices[1]); } } - private function fixAssertions(Tokens $tokens, int $startIndex, int $endIndex): void + private static function fixAssertions(Tokens $tokens, int $startIndex, int $endIndex): void { for ($index = $startIndex; $index < $endIndex; $index++) { if (!self::isAssertionToFix($tokens, $index)) { diff --git a/src/Fixer/PhpUnitNoUselessReturnFixer.php b/src/Fixer/PhpUnitNoUselessReturnFixer.php index 50af76ab..0f77e824 100644 --- a/src/Fixer/PhpUnitNoUselessReturnFixer.php +++ b/src/Fixer/PhpUnitNoUselessReturnFixer.php @@ -74,11 +74,11 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void /** @var list $indices */ foreach ($phpUnitTestCaseIndicator->findPhpUnitClasses($tokens) as $indices) { - $this->removeUselessReturns($tokens, $indices[0], $indices[1]); + self::removeUselessReturns($tokens, $indices[0], $indices[1]); } } - private function removeUselessReturns(Tokens $tokens, int $startIndex, int $endIndex): void + private static function removeUselessReturns(Tokens $tokens, int $startIndex, int $endIndex): void { $functionsAnalyzer = new FunctionsAnalyzer(); diff --git a/src/Fixer/PhpUnitRequiresConstraintFixer.php b/src/Fixer/PhpUnitRequiresConstraintFixer.php index 602b6c60..74b84bf0 100644 --- a/src/Fixer/PhpUnitRequiresConstraintFixer.php +++ b/src/Fixer/PhpUnitRequiresConstraintFixer.php @@ -76,11 +76,11 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void /** @var list $indices */ foreach ($phpUnitTestCaseIndicator->findPhpUnitClasses($tokens) as $indices) { - $this->fixClass($tokens, $indices[0], $indices[1]); + self::fixClass($tokens, $indices[0], $indices[1]); } } - private function fixClass(Tokens $tokens, int $index, int $endIndex): void + private static function fixClass(Tokens $tokens, int $index, int $endIndex): void { while ($index < $endIndex) { $index = $tokens->getNextTokenOfKind($index, ['{', [\T_FUNCTION]]); diff --git a/src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php b/src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php index 2475985c..fd855f3b 100644 --- a/src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php +++ b/src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php @@ -64,35 +64,35 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void } // remove ones not having type at the beginning - $this->removeVarAnnotationNotMatchingPattern($tokens, $index, '/@var\\s+[\\?\\\\a-zA-Z_\\x7f-\\xff]/'); + self::removeVarAnnotationNotMatchingPattern($tokens, $index, '/@var\\s+[\\?\\\\a-zA-Z_\\x7f-\\xff]/'); $nextIndex = $tokens->getNextMeaningfulToken($index); if ($nextIndex === null) { - $this->removeVarAnnotationNotMatchingPattern($tokens, $index, null); + self::removeVarAnnotationNotMatchingPattern($tokens, $index, null); continue; } if ($tokens[$nextIndex]->isGivenKind([\T_PRIVATE, \T_PROTECTED, \T_PUBLIC, \T_VAR, \T_STATIC, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE])) { - $this->removeForClassElement($tokens, $index, $nextIndex); + self::removeForClassElement($tokens, $index, $nextIndex); continue; } if ($tokens[$nextIndex]->isGivenKind(\T_VARIABLE)) { - $this->removeVarAnnotation($tokens, $index, [$tokens[$nextIndex]->getContent()]); + self::removeVarAnnotation($tokens, $index, [$tokens[$nextIndex]->getContent()]); continue; } if ($tokens[$nextIndex]->isGivenKind([\T_FOR, \T_FOREACH, \T_IF, \T_SWITCH, \T_WHILE])) { - $this->removeVarAnnotationForControl($tokens, $index, $nextIndex); + self::removeVarAnnotationForControl($tokens, $index, $nextIndex); continue; } - $this->removeVarAnnotationNotMatchingPattern($tokens, $index, null); + self::removeVarAnnotationNotMatchingPattern($tokens, $index, null); } } - private function removeForClassElement(Tokens $tokens, int $index, int $propertyStartIndex): void + private static function removeForClassElement(Tokens $tokens, int $index, int $propertyStartIndex): void { $tokenKinds = [\T_NS_SEPARATOR, \T_STATIC, \T_STRING, \T_WHITESPACE, CT::T_ARRAY_TYPEHINT, CT::T_NULLABLE_TYPE, CT::T_TYPE_ALTERNATION]; @@ -105,29 +105,29 @@ private function removeForClassElement(Tokens $tokens, int $index, int $property \assert(\is_int($variableIndex)); if (!$tokens[$variableIndex]->isGivenKind(\T_VARIABLE)) { - $this->removeVarAnnotationNotMatchingPattern($tokens, $index, null); + self::removeVarAnnotationNotMatchingPattern($tokens, $index, null); return; } if (Preg::match('/@var\\h+(.+\\h+)?\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/', $tokens[$index]->getContent())) { - $this->removeVarAnnotation($tokens, $index, [$tokens[$variableIndex]->getContent()]); + self::removeVarAnnotation($tokens, $index, [$tokens[$variableIndex]->getContent()]); } } /** * @param list $allowedVariables */ - private function removeVarAnnotation(Tokens $tokens, int $index, array $allowedVariables): void + private static function removeVarAnnotation(Tokens $tokens, int $index, array $allowedVariables): void { - $this->removeVarAnnotationNotMatchingPattern( + self::removeVarAnnotationNotMatchingPattern( $tokens, $index, '/(\\Q' . \implode('\\E|\\Q', $allowedVariables) . '\\E)\\b/i', ); } - private function removeVarAnnotationForControl(Tokens $tokens, int $commentIndex, int $controlIndex): void + private static function removeVarAnnotationForControl(Tokens $tokens, int $commentIndex, int $controlIndex): void { $index = $tokens->getNextMeaningfulToken($controlIndex); \assert(\is_int($index)); @@ -144,10 +144,10 @@ private function removeVarAnnotationForControl(Tokens $tokens, int $commentIndex } } - $this->removeVarAnnotation($tokens, $commentIndex, $variables); + self::removeVarAnnotation($tokens, $commentIndex, $variables); } - private function removeVarAnnotationNotMatchingPattern(Tokens $tokens, int $index, ?string $pattern): void + private static function removeVarAnnotationNotMatchingPattern(Tokens $tokens, int $index, ?string $pattern): void { $doc = new DocBlock($tokens[$index]->getContent()); diff --git a/src/Fixer/PhpdocNoSuperfluousParamFixer.php b/src/Fixer/PhpdocNoSuperfluousParamFixer.php index 40bfd66a..b2e0b570 100644 --- a/src/Fixer/PhpdocNoSuperfluousParamFixer.php +++ b/src/Fixer/PhpdocNoSuperfluousParamFixer.php @@ -77,9 +77,9 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $paramNames = $this->getParamNames($tokens, $functionIndex); + $paramNames = self::getParamNames($tokens, $functionIndex); - $newContent = $this->getFilteredDocComment($tokens[$index]->getContent(), $paramNames); + $newContent = self::getFilteredDocComment($tokens[$index]->getContent(), $paramNames); if ($newContent === $tokens[$index]->getContent()) { continue; @@ -96,7 +96,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void /** * @return list */ - private function getParamNames(Tokens $tokens, int $functionIndex): array + private static function getParamNames(Tokens $tokens, int $functionIndex): array { $paramBlockStartIndex = $tokens->getNextTokenOfKind($functionIndex, ['(']); \assert(\is_int($paramBlockStartIndex)); @@ -116,13 +116,13 @@ private function getParamNames(Tokens $tokens, int $functionIndex): array /** * @param list $paramNames */ - private function getFilteredDocComment(string $comment, array $paramNames): string + private static function getFilteredDocComment(string $comment, array $paramNames): string { $doc = new DocBlock($comment); $foundParamNames = []; foreach ($doc->getAnnotationsOfType('param') as $annotation) { - $paramName = $this->getParamName($annotation->getContent()); + $paramName = self::getParamName($annotation->getContent()); if (\in_array($paramName, $paramNames, true) && !\in_array($paramName, $foundParamNames, true)) { $foundParamNames[] = $paramName; @@ -135,7 +135,7 @@ private function getFilteredDocComment(string $comment, array $paramNames): stri return $doc->getContent(); } - private function getParamName(string $annotation): ?string + private static function getParamName(string $annotation): ?string { Preg::match('/@param\\s+(?:[^\\$]+)?\\s*(\\$[a-zA-Z_\\x80-\\xff][a-zA-Z0-9_\\x80-\\xff]*)\\b/', $annotation, $matches); diff --git a/src/Fixer/PhpdocSelfAccessorFixer.php b/src/Fixer/PhpdocSelfAccessorFixer.php index e45e21fa..8c7bb251 100644 --- a/src/Fixer/PhpdocSelfAccessorFixer.php +++ b/src/Fixer/PhpdocSelfAccessorFixer.php @@ -62,11 +62,11 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $namespaces = (new NamespacesAnalyzer())->getDeclarations($tokens); foreach ($namespaces as $namespace) { - $this->fixPhpdocSelfAccessor($tokens, $namespace->getScopeStartIndex(), $namespace->getScopeEndIndex(), $namespace->getFullName()); + self::fixPhpdocSelfAccessor($tokens, $namespace->getScopeStartIndex(), $namespace->getScopeEndIndex(), $namespace->getFullName()); } } - private function fixPhpdocSelfAccessor(Tokens $tokens, int $namespaceStartIndex, int $namespaceEndIndex, string $fullName): void + private static function fixPhpdocSelfAccessor(Tokens $tokens, int $namespaceStartIndex, int $namespaceEndIndex, string $fullName): void { $tokensAnalyzer = new TokensAnalyzer($tokens); @@ -88,20 +88,20 @@ private function fixPhpdocSelfAccessor(Tokens $tokens, int $namespaceStartIndex, $classyName = $tokens[$nameIndex]->getContent(); - $this->replaceNameOccurrences($tokens, $fullName, $classyName, $startIndex, $endIndex); + self::replaceNameOccurrences($tokens, $fullName, $classyName, $startIndex, $endIndex); $index = $endIndex; } } - private function replaceNameOccurrences(Tokens $tokens, string $namespace, string $classyName, int $startIndex, int $endIndex): void + private static function replaceNameOccurrences(Tokens $tokens, string $namespace, string $classyName, int $startIndex, int $endIndex): void { for ($index = $startIndex; $index < $endIndex; $index++) { if (!$tokens[$index]->isGivenKind(\T_DOC_COMMENT)) { continue; } - $newContent = $this->getNewContent($tokens[$index]->getContent(), $namespace, $classyName); + $newContent = self::getNewContent($tokens[$index]->getContent(), $namespace, $classyName); if ($newContent === $tokens[$index]->getContent()) { continue; @@ -111,7 +111,7 @@ private function replaceNameOccurrences(Tokens $tokens, string $namespace, strin } } - private function getNewContent(string $content, string $namespace, string $classyName): string + private static function getNewContent(string $content, string $namespace, string $classyName): string { $docBlock = new DocBlock($content); diff --git a/src/Fixer/PhpdocVarAnnotationToAssertFixer.php b/src/Fixer/PhpdocVarAnnotationToAssertFixer.php index 766394a7..f259ae4a 100644 --- a/src/Fixer/PhpdocVarAnnotationToAssertFixer.php +++ b/src/Fixer/PhpdocVarAnnotationToAssertFixer.php @@ -62,19 +62,19 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $variableIndex = $this->getVariableIndex($tokens, $docCommentIndex); + $variableIndex = self::getVariableIndex($tokens, $docCommentIndex); if ($variableIndex === null) { continue; } - $assertTokens = $this->getAssertTokens($tokens, $docCommentIndex, $tokens[$variableIndex]->getContent()); + $assertTokens = self::getAssertTokens($tokens, $docCommentIndex, $tokens[$variableIndex]->getContent()); if ($assertTokens === null) { continue; } - $expressionEndIndex = $this->getExpressionEnd($tokens, $variableIndex); + $expressionEndIndex = self::getExpressionEnd($tokens, $variableIndex); - if (!$this->canBePlacedAfterExpression($tokens, $expressionEndIndex)) { + if (!self::canBePlacedAfterExpression($tokens, $expressionEndIndex)) { continue; } @@ -88,7 +88,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void } } - private function getVariableIndex(Tokens $tokens, int $docCommentIndex): ?int + private static function getVariableIndex(Tokens $tokens, int $docCommentIndex): ?int { $prevIndex = $tokens->getPrevMeaningfulToken($docCommentIndex); if (!$tokens[$prevIndex]->equalsAny([';', '{', '}', [\T_OPEN_TAG]])) { @@ -116,9 +116,9 @@ private function getVariableIndex(Tokens $tokens, int $docCommentIndex): ?int /** * @return null|list */ - private function getAssertTokens(Tokens $tokens, int $docCommentIndex, string $variableName): ?array + private static function getAssertTokens(Tokens $tokens, int $docCommentIndex, string $variableName): ?array { - $annotation = $this->getAnnotationForVariable($tokens, $docCommentIndex, $variableName); + $annotation = self::getAnnotationForVariable($tokens, $docCommentIndex, $variableName); if ($annotation === null) { return null; } @@ -133,10 +133,10 @@ private function getAssertTokens(Tokens $tokens, int $docCommentIndex, string $v $assertions = []; foreach ($typeExpression->getTypes() as $type) { if (\substr($type, 0, 1) === '?') { - $assertions['null'] = $this->getCodeForType('null', $variableName); + $assertions['null'] = self::getCodeForType('null', $variableName); $type = \substr($type, 1); } - $assertions[$type] = $this->getCodeForType($type, $variableName); + $assertions[$type] = self::getCodeForType($type, $variableName); } try { @@ -151,7 +151,7 @@ private function getAssertTokens(Tokens $tokens, int $docCommentIndex, string $v return \array_slice($arrayTokens, 1); } - private function getAnnotationForVariable(Tokens $tokens, int $docCommentIndex, string $variableName): ?Annotation + private static function getAnnotationForVariable(Tokens $tokens, int $docCommentIndex, string $variableName): ?Annotation { $docBlock = new DocBlock($tokens[$docCommentIndex]->getContent()); @@ -173,7 +173,7 @@ private function getAnnotationForVariable(Tokens $tokens, int $docCommentIndex, return $varAnnotation; } - private function getCodeForType(string $type, string $variableName): string + private static function getCodeForType(string $type, string $variableName): string { $typesMap = [ 'array' => 'is_array', @@ -198,7 +198,7 @@ private function getCodeForType(string $type, string $variableName): string return \sprintf('%s instanceof %s', $variableName, $type); } - private function getExpressionEnd(Tokens $tokens, int $index): int + private static function getExpressionEnd(Tokens $tokens, int $index): int { while (!$tokens[$index]->equals(';')) { $index = $tokens->getNextMeaningfulToken($index); @@ -213,7 +213,7 @@ private function getExpressionEnd(Tokens $tokens, int $index): int return $index; } - private function canBePlacedAfterExpression(Tokens $tokens, int $expressionEndIndex): bool + private static function canBePlacedAfterExpression(Tokens $tokens, int $expressionEndIndex): bool { $afterExpressionIndex = $tokens->getNextMeaningfulToken($expressionEndIndex); diff --git a/src/Fixer/PromotedConstructorPropertyFixer.php b/src/Fixer/PromotedConstructorPropertyFixer.php index 2198edc4..869b4dcf 100644 --- a/src/Fixer/PromotedConstructorPropertyFixer.php +++ b/src/Fixer/PromotedConstructorPropertyFixer.php @@ -135,8 +135,8 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void private function promoteProperties(Tokens $tokens, int $classIndex, ConstructorAnalysis $constructorAnalysis): void { - $isDoctrineEntity = $this->isDoctrineEntity($tokens, $classIndex); - $properties = $this->getClassProperties($tokens, $classIndex); + $isDoctrineEntity = self::isDoctrineEntity($tokens, $classIndex); + $properties = self::getClassProperties($tokens, $classIndex); $constructorParameterNames = $constructorAnalysis->getConstructorParameterNames(); $constructorPromotableParameters = $constructorAnalysis->getConstructorPromotableParameters(); @@ -147,16 +147,16 @@ private function promoteProperties(Tokens $tokens, int $classIndex, ConstructorA continue; } - $propertyIndex = $this->getPropertyIndex($tokens, $properties, $constructorPromotableAssignments[$constructorParameterName]); + $propertyIndex = self::getPropertyIndex($tokens, $properties, $constructorPromotableAssignments[$constructorParameterName]); if (!$this->isPropertyToPromote($tokens, $propertyIndex, $isDoctrineEntity)) { continue; } - $propertyType = $this->getType($tokens, $propertyIndex); - $parameterType = $this->getType($tokens, $constructorParameterIndex); + $propertyType = self::getType($tokens, $propertyIndex); + $parameterType = self::getType($tokens, $constructorParameterIndex); - if (!$this->typesAllowPromoting($propertyType, $parameterType)) { + if (!self::typesAllowPromoting($propertyType, $parameterType)) { continue; } @@ -167,11 +167,11 @@ private function promoteProperties(Tokens $tokens, int $classIndex, ConstructorA continue; } - $tokensToInsert = $this->removePropertyAndReturnTokensToInsert($tokens, $propertyIndex); + $tokensToInsert = self::removePropertyAndReturnTokensToInsert($tokens, $propertyIndex); - $this->renameVariable($tokens, $constructorAnalysis->getConstructorIndex(), $oldParameterName, $newParameterName); + self::renameVariable($tokens, $constructorAnalysis->getConstructorIndex(), $oldParameterName, $newParameterName); - $this->removeAssignment($tokens, $constructorPromotableAssignments[$constructorParameterName]); + self::removeAssignment($tokens, $constructorPromotableAssignments[$constructorParameterName]); $this->updateParameterSignature( $tokens, $constructorParameterIndex, @@ -181,7 +181,7 @@ private function promoteProperties(Tokens $tokens, int $classIndex, ConstructorA } } - private function isDoctrineEntity(Tokens $tokens, int $index): bool + private static function isDoctrineEntity(Tokens $tokens, int $index): bool { $phpDocIndex = $tokens->getPrevNonWhitespace($index); \assert(\is_int($phpDocIndex)); @@ -204,7 +204,7 @@ private function isDoctrineEntity(Tokens $tokens, int $index): bool /** * @param array $properties */ - private function getPropertyIndex(Tokens $tokens, array $properties, int $assignmentIndex): ?int + private static function getPropertyIndex(Tokens $tokens, array $properties, int $assignmentIndex): ?int { $propertyNameIndex = $tokens->getPrevTokenOfKind($assignmentIndex, [[\T_STRING]]); \assert(\is_int($propertyNameIndex)); @@ -246,7 +246,7 @@ private function isPropertyToPromote(Tokens $tokens, ?int $propertyIndex, bool $ return \count($docBlock->getAnnotations()) === 0; } - private function getType(Tokens $tokens, ?int $variableIndex): string + private static function getType(Tokens $tokens, ?int $variableIndex): string { if ($variableIndex === null) { return ''; @@ -269,7 +269,7 @@ private function getType(Tokens $tokens, ?int $variableIndex): string return $type; } - private function typesAllowPromoting(string $propertyType, string $parameterType): bool + private static function typesAllowPromoting(string $propertyType, string $parameterType): bool { if ($propertyType === '') { return true; @@ -296,7 +296,7 @@ private function typesAllowPromoting(string $propertyType, string $parameterType /** * @return array */ - private function getClassProperties(Tokens $tokens, int $classIndex): array + private static function getClassProperties(Tokens $tokens, int $classIndex): array { $properties = []; $tokensAnalyzer = new TokensAnalyzer($tokens); @@ -318,7 +318,7 @@ private function getClassProperties(Tokens $tokens, int $classIndex): array /** * @return list */ - private function removePropertyAndReturnTokensToInsert(Tokens $tokens, ?int $propertyIndex): array + private static function removePropertyAndReturnTokensToInsert(Tokens $tokens, ?int $propertyIndex): array { if ($propertyIndex === null) { return [new Token([\T_PUBLIC, 'public'])]; @@ -327,8 +327,8 @@ private function removePropertyAndReturnTokensToInsert(Tokens $tokens, ?int $pro $visibilityIndex = $tokens->getPrevTokenOfKind($propertyIndex, [[\T_PRIVATE], [\T_PROTECTED], [\T_PUBLIC], [\T_VAR]]); \assert(\is_int($visibilityIndex)); - $prevPropertyIndex = $this->getTokenOfKindSibling($tokens, -1, $propertyIndex, ['{', '}', ';', ',']); - $nextPropertyIndex = $this->getTokenOfKindSibling($tokens, 1, $propertyIndex, [';', ',']); + $prevPropertyIndex = self::getTokenOfKindSibling($tokens, -1, $propertyIndex, ['{', '}', ';', ',']); + $nextPropertyIndex = self::getTokenOfKindSibling($tokens, 1, $propertyIndex, [';', ',']); $removeFrom = $tokens->getTokenNotOfKindSibling($prevPropertyIndex, 1, [[\T_WHITESPACE], [\T_COMMENT]]); \assert(\is_int($removeFrom)); @@ -362,7 +362,7 @@ private function removePropertyAndReturnTokensToInsert(Tokens $tokens, ?int $pro /** * @param list $tokenKinds */ - private function getTokenOfKindSibling(Tokens $tokens, int $direction, int $index, array $tokenKinds): int + private static function getTokenOfKindSibling(Tokens $tokens, int $direction, int $index, array $tokenKinds): int { $index += $direction; @@ -383,7 +383,7 @@ private function getTokenOfKindSibling(Tokens $tokens, int $direction, int $inde return $index; } - private function renameVariable(Tokens $tokens, int $constructorIndex, string $oldName, string $newName): void + private static function renameVariable(Tokens $tokens, int $constructorIndex, string $oldName, string $newName): void { $parenthesesOpenIndex = $tokens->getNextTokenOfKind($constructorIndex, ['(']); \assert(\is_int($parenthesesOpenIndex)); @@ -399,7 +399,7 @@ private function renameVariable(Tokens $tokens, int $constructorIndex, string $o } } - private function removeAssignment(Tokens $tokens, int $variableAssignmentIndex): void + private static function removeAssignment(Tokens $tokens, int $variableAssignmentIndex): void { $thisIndex = $tokens->getPrevTokenOfKind($variableAssignmentIndex, [[\T_VARIABLE]]); \assert(\is_int($thisIndex)); diff --git a/src/Fixer/ReadonlyPromotedPropertiesFixer.php b/src/Fixer/ReadonlyPromotedPropertiesFixer.php index c26edd53..50c322d6 100644 --- a/src/Fixer/ReadonlyPromotedPropertiesFixer.php +++ b/src/Fixer/ReadonlyPromotedPropertiesFixer.php @@ -109,7 +109,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - if ($this->isClassReadonly($tokens, $index)) { + if (self::isClassReadonly($tokens, $index)) { continue; } @@ -136,7 +136,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void } } - private function isClassReadonly(Tokens $tokens, int $index): bool + private static function isClassReadonly(Tokens $tokens, int $index): bool { do { $index = $tokens->getPrevMeaningfulToken($index); diff --git a/src/Fixer/SingleSpaceBeforeStatementFixer.php b/src/Fixer/SingleSpaceBeforeStatementFixer.php index 545f4f46..1059e86a 100644 --- a/src/Fixer/SingleSpaceBeforeStatementFixer.php +++ b/src/Fixer/SingleSpaceBeforeStatementFixer.php @@ -114,22 +114,22 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void } if ($tokens[$index - 2]->isGivenKind(\T_OPEN_TAG)) { - $this->fixTwoTokensAfterOpenTag($tokens, $index); + self::fixTwoTokensAfterOpenTag($tokens, $index); continue; } - $this->fixMoreThanTwoTokensAfterOpenTag($tokens, $index); + self::fixMoreThanTwoTokensAfterOpenTag($tokens, $index); } } - private function fixTwoTokensAfterOpenTag(Tokens $tokens, int $index): void + private static function fixTwoTokensAfterOpenTag(Tokens $tokens, int $index): void { if ($tokens[$index - 1]->isGivenKind(\T_WHITESPACE) && !Preg::match('/\\R/', $tokens[$index - 2]->getContent())) { $tokens->clearAt($index - 1); } } - private function fixMoreThanTwoTokensAfterOpenTag(Tokens $tokens, int $index): void + private static function fixMoreThanTwoTokensAfterOpenTag(Tokens $tokens, int $index): void { if ($tokens[$index - 1]->isGivenKind(\T_WHITESPACE)) { if (!Preg::match('/\\R/', $tokens[$index - 1]->getContent())) { diff --git a/src/Fixer/StringableInterfaceFixer.php b/src/Fixer/StringableInterfaceFixer.php index 99942ce7..497c87d5 100644 --- a/src/Fixer/StringableInterfaceFixer.php +++ b/src/Fixer/StringableInterfaceFixer.php @@ -77,19 +77,19 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $classEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classStartIndex); - if (!$this->doesHaveToStringMethod($tokens, $classStartIndex, $classEndIndex)) { + if (!self::doesHaveToStringMethod($tokens, $classStartIndex, $classEndIndex)) { continue; } - if ($this->doesImplementStringable($tokens, $namespaceStartIndex, $index, $classStartIndex)) { + if (self::doesImplementStringable($tokens, $namespaceStartIndex, $index, $classStartIndex)) { continue; } - $this->addStringableInterface($tokens, $index); + self::addStringableInterface($tokens, $index); } } - private function doesHaveToStringMethod(Tokens $tokens, int $classStartIndex, int $classEndIndex): bool + private static function doesHaveToStringMethod(Tokens $tokens, int $classStartIndex, int $classEndIndex): bool { $index = $classStartIndex; @@ -115,9 +115,9 @@ private function doesHaveToStringMethod(Tokens $tokens, int $classStartIndex, in return false; } - private function doesImplementStringable(Tokens $tokens, int $namespaceStartIndex, int $classKeywordIndex, int $classOpenBraceIndex): bool + private static function doesImplementStringable(Tokens $tokens, int $namespaceStartIndex, int $classKeywordIndex, int $classOpenBraceIndex): bool { - $interfaces = $this->getInterfaces($tokens, $classKeywordIndex, $classOpenBraceIndex); + $interfaces = self::getInterfaces($tokens, $classKeywordIndex, $classOpenBraceIndex); if ($interfaces === []) { return false; } @@ -130,7 +130,7 @@ private function doesImplementStringable(Tokens $tokens, int $namespaceStartInde return true; } - foreach ($this->getImports($tokens, $namespaceStartIndex, $classKeywordIndex) as $import) { + foreach (self::getImports($tokens, $namespaceStartIndex, $classKeywordIndex) as $import) { if (\in_array($import, $interfaces, true)) { return true; } @@ -142,7 +142,7 @@ private function doesImplementStringable(Tokens $tokens, int $namespaceStartInde /** * @return list */ - private function getInterfaces(Tokens $tokens, int $classKeywordIndex, int $classOpenBraceIndex): array + private static function getInterfaces(Tokens $tokens, int $classKeywordIndex, int $classOpenBraceIndex): array { $implementsIndex = $tokens->getNextTokenOfKind($classKeywordIndex, ['{', [\T_IMPLEMENTS]]); \assert(\is_int($implementsIndex)); @@ -172,7 +172,7 @@ private function getInterfaces(Tokens $tokens, int $classKeywordIndex, int $clas /** * @return iterable */ - private function getImports(Tokens $tokens, int $namespaceStartIndex, int $classKeywordIndex): iterable + private static function getImports(Tokens $tokens, int $namespaceStartIndex, int $classKeywordIndex): iterable { for ($index = $namespaceStartIndex; $index < $classKeywordIndex; $index++) { if (!$tokens[$index]->isGivenKind(\T_USE)) { @@ -197,7 +197,7 @@ private function getImports(Tokens $tokens, int $namespaceStartIndex, int $class } } - private function addStringableInterface(Tokens $tokens, int $classIndex): void + private static function addStringableInterface(Tokens $tokens, int $classIndex): void { $implementsIndex = $tokens->getNextTokenOfKind($classIndex, ['{', [\T_IMPLEMENTS]]); \assert(\is_int($implementsIndex)); diff --git a/tests/AutoReview/SrcCodeTest.php b/tests/AutoReview/SrcCodeTest.php index 51a51e51..b691050e 100644 --- a/tests/AutoReview/SrcCodeTest.php +++ b/tests/AutoReview/SrcCodeTest.php @@ -83,7 +83,7 @@ public static function provideFixerCases(): iterable public function testFixerSupportsAllFilesByDefault(): void { - self::assertTrue($this->createAbstractFixerDouble()->supports($this->createSplFileInfoDouble())); + self::assertTrue(self::createAbstractFixerDouble()->supports(self::createSplFileInfoDouble())); } /** @@ -148,7 +148,7 @@ public static function provideThereIsNoPregFunctionUsedDirectlyCases(): iterable } } - private function createAbstractFixerDouble(): AbstractFixer + private static function createAbstractFixerDouble(): AbstractFixer { return new class () extends AbstractFixer { public function isCandidate(Tokens $tokens): bool @@ -178,7 +178,7 @@ public function getPriority(): int }; } - private function createSplFileInfoDouble(): \SplFileInfo + private static function createSplFileInfoDouble(): \SplFileInfo { return new class ('') extends \SplFileInfo {}; } diff --git a/tests/AutoReview/TestsCodeTest.php b/tests/AutoReview/TestsCodeTest.php index 11950c79..1d1f03bb 100644 --- a/tests/AutoReview/TestsCodeTest.php +++ b/tests/AutoReview/TestsCodeTest.php @@ -32,14 +32,14 @@ final class TestsCodeTest extends TestCase public function testClassContainsCorrectMethods(string $className): void { if ((new \ReflectionClass($className))->isTrait()) { - foreach ($this->getMethods($className) as $reflectionMethod) { + foreach (self::getMethods($className) as $reflectionMethod) { self::assertStringStartsWith('assert', $reflectionMethod->getName()); } return; } - foreach ($this->getMethods($className, \ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { + foreach (self::getMethods($className, \ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { self::assertTrue( \strpos($reflectionMethod->getName(), 'test') === 0 || Preg::match('/^provide.+Cases$/', $reflectionMethod->getName()), \sprintf( @@ -58,7 +58,7 @@ public function testClassContainsCorrectMethods(string $className): void */ public function testDataProvidersAreStatic(string $className): void { - $dataProviders = $this->getDataProviders($className); + $dataProviders = self::getDataProviders($className); if ($dataProviders === []) { $this->expectNotToPerformAssertions(); @@ -83,7 +83,7 @@ public function testDataProvidersAreStatic(string $className): void */ public function testDataProvidersKeys(string $className): void { - $dataProviders = $this->getDataProviders($className); + $dataProviders = self::getDataProviders($className); if ($dataProviders === []) { $this->expectNotToPerformAssertions(); @@ -124,7 +124,7 @@ public function testDataProvidersValues(string $className): void return; } - $dataProviders = $this->getDataProviders($className); + $dataProviders = self::getDataProviders($className); foreach ($dataProviders as $dataProvider) { /** @var \Iterator> $dataSet */ @@ -194,10 +194,10 @@ public static function provideTestClassCases(): iterable * * @return list<\ReflectionMethod> */ - private function getDataProviders(string $className): array + private static function getDataProviders(string $className): array { return \array_values(\array_filter( - $this->getMethods($className, \ReflectionMethod::IS_PUBLIC), + self::getMethods($className, \ReflectionMethod::IS_PUBLIC), static fn (\ReflectionMethod $reflectionMethod): bool => \strpos($reflectionMethod->getName(), 'provide') === 0, )); } @@ -207,7 +207,7 @@ private function getDataProviders(string $className): array * * @return list<\ReflectionMethod> */ - private function getMethods(string $className, ?int $methodFilter = null): array + private static function getMethods(string $className, ?int $methodFilter = null): array { $reflectionClass = new \ReflectionClass($className); diff --git a/tests/Fixer/AbstractFixerTestCase.php b/tests/Fixer/AbstractFixerTestCase.php index c41bcf50..0ed73f85 100644 --- a/tests/Fixer/AbstractFixerTestCase.php +++ b/tests/Fixer/AbstractFixerTestCase.php @@ -109,7 +109,7 @@ final public function testCodeSampleIsChangedDuringFixing(): void Tokens::clearCache(); $tokens = Tokens::fromCode($codeSample->getCode()); - $fixer->fix($this->createSplFileInfoDouble(), $tokens); + $fixer->fix(self::createSplFileInfoDouble(), $tokens); self::assertNotSame($codeSample->getCode(), $tokens->generateCode()); } @@ -189,7 +189,7 @@ final protected function doTest(string $expected, ?string $input = null, array $ self::assertTrue($fixer->isCandidate($inputTokens)); - $fixer->fix($this->createSplFileInfoDouble(), $inputTokens); + $fixer->fix(self::createSplFileInfoDouble(), $inputTokens); $inputTokens->clearEmptyTokens(); self::assertSame( @@ -205,7 +205,7 @@ final protected function doTest(string $expected, ?string $input = null, array $ self::assertSameTokens($expectedTokens, $inputTokens); } - $fixer->fix($this->createSplFileInfoDouble(), $expectedTokens); + $fixer->fix(self::createSplFileInfoDouble(), $expectedTokens); self::assertSame($expected, $expectedTokens->generateCode()); @@ -253,7 +253,7 @@ final protected function assertSuccessorName(string $successorName): void self::assertSame([$successorName], $fixer->getSuccessorsNames()); } - private function createSplFileInfoDouble(): \SplFileInfo + private static function createSplFileInfoDouble(): \SplFileInfo { return new class (\getcwd() . \DIRECTORY_SEPARATOR . 'src' . \DIRECTORY_SEPARATOR . 'FixerFile.php') extends \SplFileInfo { public function __construct(string $filename) diff --git a/tests/Fixer/NumericLiteralSeparatorFixerTest.php b/tests/Fixer/NumericLiteralSeparatorFixerTest.php index 53ed584f..52841071 100644 --- a/tests/Fixer/NumericLiteralSeparatorFixerTest.php +++ b/tests/Fixer/NumericLiteralSeparatorFixerTest.php @@ -54,7 +54,7 @@ public function testReversingCodeSample(): void Tokens::clearCache(); $tokens = Tokens::fromCode($codeSample->getCode()); - $fixer->fix($this->createSplFileInfoDouble(), $tokens); + $fixer->fix(self::createSplFileInfoDouble(), $tokens); self::assertNull($this->lintSource($tokens->generateCode())); $this->doTest( @@ -198,7 +198,7 @@ public static function provideFixCases(): iterable ]; } - private function createSplFileInfoDouble(): \SplFileInfo + private static function createSplFileInfoDouble(): \SplFileInfo { return new class ('') extends \SplFileInfo {}; } diff --git a/tests/Fixer/SingleSpaceAfterStatementFixerTest.php b/tests/Fixer/SingleSpaceAfterStatementFixerTest.php index 2d9ddb7f..11e26fd6 100644 --- a/tests/Fixer/SingleSpaceAfterStatementFixerTest.php +++ b/tests/Fixer/SingleSpaceAfterStatementFixerTest.php @@ -284,7 +284,7 @@ class Foo {} public function testExampleWithAllTokensHasAllSpacesFixed(): void { $tokens = Tokens::fromCode(self::EXAMPLE_WITH_ALL_TOKENS); - self::getFixer()->fix($this->createSplFileInfoDouble(), $tokens); + self::getFixer()->fix(self::createSplFileInfoDouble(), $tokens); self::assertDoesNotMatchRegularExpression('/[^\\n ] {2,}/', $tokens->generateCode()); } @@ -297,7 +297,7 @@ public function testTokenIsUseful(int $token): void $fixer = self::getFixer(); $expectedTokens = Tokens::fromCode(self::EXAMPLE_WITH_ALL_TOKENS); - $fixer->fix($this->createSplFileInfoDouble(), $expectedTokens); + $fixer->fix(self::createSplFileInfoDouble(), $expectedTokens); $reflectionObject = new \ReflectionObject($fixer); $property = $reflectionObject->getProperty('tokens'); @@ -309,7 +309,7 @@ public function testTokenIsUseful(int $token): void $property->setValue($fixer, \array_diff($tokens, [$token])); $tokens = Tokens::fromCode(self::EXAMPLE_WITH_ALL_TOKENS); - $fixer->fix($this->createSplFileInfoDouble(), $tokens); + $fixer->fix(self::createSplFileInfoDouble(), $tokens); self::assertNotSame( $expectedTokens->generateCode(), @@ -336,7 +336,7 @@ public static function provideTokenIsUsefulCases(): iterable } } - private function createSplFileInfoDouble(): \SplFileInfo + private static function createSplFileInfoDouble(): \SplFileInfo { return new class ('') extends \SplFileInfo {}; } diff --git a/tests/FixersTest.php b/tests/FixersTest.php index 53e0158d..25d85220 100644 --- a/tests/FixersTest.php +++ b/tests/FixersTest.php @@ -25,7 +25,7 @@ final class FixersTest extends TestCase { public function testCollectionIsSortedByName(): void { - $fixerNames = $this->fixerNamesFromCollection(); + $fixerNames = self::fixerNamesFromCollection(); $sortedFixerNames = $fixerNames; \sort($sortedFixerNames); @@ -38,7 +38,7 @@ public function testCollectionIsSortedByName(): void */ public function testFixerIsInCollection(FixerInterface $fixer): void { - self::assertContains($fixer->getName(), $this->fixerNamesFromCollection()); + self::assertContains($fixer->getName(), self::fixerNamesFromCollection()); } /** @@ -64,7 +64,7 @@ public static function provideFixerIsInCollectionCases(): iterable /** * @return array */ - private function fixerNamesFromCollection(): array + private static function fixerNamesFromCollection(): array { return \array_map( static fn (FixerInterface $fixer): string => $fixer->getName(), diff --git a/tests/PriorityTest.php b/tests/PriorityTest.php index 7811f3d0..8654c4e2 100644 --- a/tests/PriorityTest.php +++ b/tests/PriorityTest.php @@ -57,10 +57,10 @@ public function testInOrder(FixerInterface $firstFixer, FixerInterface $secondFi Tokens::clearCache(); $tokens = Tokens::fromCode($input); - $firstFixer->fix($this->createSplFileInfoDouble(), $tokens); + $firstFixer->fix(self::createSplFileInfoDouble(), $tokens); $tokens->clearEmptyTokens(); - $secondFixer->fix($this->createSplFileInfoDouble(), $tokens); + $secondFixer->fix(self::createSplFileInfoDouble(), $tokens); $tokens->clearEmptyTokens(); self::assertSame($expected, $tokens->generateCode()); @@ -77,10 +77,10 @@ public function testInRevertedOrder(FixerInterface $firstFixer, FixerInterface $ Tokens::clearCache(); $tokens = Tokens::fromCode($input); - $secondFixer->fix($this->createSplFileInfoDouble(), $tokens); + $secondFixer->fix(self::createSplFileInfoDouble(), $tokens); $tokens->clearEmptyTokens(); - $firstFixer->fix($this->createSplFileInfoDouble(), $tokens); + $firstFixer->fix(self::createSplFileInfoDouble(), $tokens); $tokens->clearEmptyTokens(); self::assertNotSame($expected, $tokens->generateCode()); @@ -143,7 +143,7 @@ private static function getFixer(string $name, array $config): FixerInterface throw new \Exception(\sprintf('Fixer "%s" not found in config: "%s".', $name, \json_encode($config))); } - private function createSplFileInfoDouble(): \SplFileInfo + private static function createSplFileInfoDouble(): \SplFileInfo { return new class ('') extends \SplFileInfo {}; }