From 2c018f0acb749f7830cab54a40f7c06c78ffd3a7 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Fri, 2 Aug 2024 10:52:16 +0200 Subject: [PATCH 1/4] refactor: apply new coding standards --- .circleci/config.yml | 18 +++++++++++++---- .php-cs-fixer.dist.php | 8 +++++--- README.md | 18 ++++++++--------- bin/Utils.php | 2 +- bin/doc | 5 ++++- composer.json | 20 +++++++++---------- src/PedroTroller/CS/Fixer/AbstractFixer.php | 2 +- src/PedroTroller/CS/Fixer/RuleSetFactory.php | 4 ++-- .../MethodArguments.php | 2 +- 9 files changed, 47 insertions(+), 32 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f85604b..6e46a7b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -106,19 +106,29 @@ workflows: - documentation: matrix: parameters: - php-version: ["8.2"] + php-version: + - "8.3" - tests: matrix: parameters: - php-version: ["8.0", "8.1", "8.2"] + php-version: + - "8.1" + - "8.2" + - "8.3" - tests-with-future-mode: matrix: parameters: - php-version: ["8.0", "8.1", "8.2"] + php-version: + - "8.1" + - "8.2" + - "8.3" - tests-with-lowest-dependencies: matrix: parameters: - php-version: ["8.0", "8.1", "8.2"] + php-version: + - "8.1" + - "8.2" + - "8.3" - release-test - release: requires: diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fdb4fa6..c1ab6a4 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -4,14 +4,16 @@ use PedroTroller\CS\Fixer\Fixers; use PedroTroller\CS\Fixer\RuleSetFactory; +use PhpCsFixer\Config; +use PhpCsFixer\Finder; -return (new PhpCsFixer\Config()) +return (new Config()) ->setRiskyAllowed(true) ->setRules( RuleSetFactory::create() ->per(2, true) ->phpCsFixer(true) - ->php(8.0, true) + ->php(8.1, true) ->pedrotroller(true) ->enable('align_multiline_comment') ->enable('array_indentation') @@ -34,7 +36,7 @@ ->setUsingCache(false) ->registerCustomFixers(new Fixers()) ->setFinder( - PhpCsFixer\Finder::create() + Finder::create() ->in(__DIR__) ->append([__FILE__, __DIR__.'/bin/doc']) ) diff --git a/README.md b/README.md index 6d36aee..08d29ed 100644 --- a/README.md +++ b/README.md @@ -384,12 +384,12 @@ Prohibited functions MUST BE commented on as prohibited ### Available options - - `functions` (*optional*): The function names to be marked how prohibited - - default: `var_dump`, `dump`, `die` - - `comment` (*optional*): The prohibition message to put in the comment - default: `@TODO remove this line` + - `functions` (*optional*): The function names to be marked how prohibited + - default: `var_dump`, `dump`, `die` + ### Configuration examples ```php @@ -511,18 +511,18 @@ If the declaration of a method is too long, the arguments of this method MUST BE ### Available options - - `max-args` (*optional*): The maximum number of arguments allowed with splitting the arguments into several lines (use `false` to disable this feature) - - default: `3` - - - `max-length` (*optional*): The maximum number of characters allowed with splitting the arguments into several lines - - default: `120` - - `automatic-argument-merge` (*optional*): If both conditions are met (the line is not too long and there are not too many arguments), then the arguments are put back inline - default: `true` - `inline-attributes` (*optional*): In the case of a split, the declaration of the attributes of the arguments of the method will be on the same line as the arguments themselves - default: `false` + - `max-args` (*optional*): The maximum number of arguments allowed with splitting the arguments into several lines (use `false` to disable this feature) + - default: `3` + + - `max-length` (*optional*): The maximum number of characters allowed with splitting the arguments into several lines + - default: `120` + ### Configuration examples ```php diff --git a/bin/Utils.php b/bin/Utils.php index 913820e..b21abba 100644 --- a/bin/Utils.php +++ b/bin/Utils.php @@ -4,7 +4,7 @@ final class Utils { - public static function arrayToString(array $array = null) + public static function arrayToString(?array $array = null) { if (null === $array) { return; diff --git a/bin/doc b/bin/doc index 09dd9df..08fa01f 100755 --- a/bin/doc +++ b/bin/doc @@ -1,7 +1,10 @@ #!/usr/bin/env php =3.59.3" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.28", "phpspec/phpspec": "^7.0", "sebastian/diff": "^4.0", "twig/twig": "^3.3", "webmozart/assert": "^1.10" }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "PedroTroller\\CS\\Fixer\\": "src/PedroTroller/CS/Fixer" @@ -31,19 +33,17 @@ "dev-master": "3.x-dev" } }, - "minimum-stability": "dev", - "prefer-stable": true, "scripts": { - "tests": [ - "tests\\Runner::run", - "tests\\Orchestra::run", - "phpspec run -fpretty" + "lint": [ + "@php-cs-fixer" ], "php-cs-fixer": [ "php-cs-fixer fix --dry-run -vvv --diff" ], - "lint": [ - "@php-cs-fixer" + "tests": [ + "tests\\Runner::run", + "tests\\Orchestra::run", + "phpspec run -fpretty" ] } } diff --git a/src/PedroTroller/CS/Fixer/AbstractFixer.php b/src/PedroTroller/CS/Fixer/AbstractFixer.php index 549e599..d2d8b74 100644 --- a/src/PedroTroller/CS/Fixer/AbstractFixer.php +++ b/src/PedroTroller/CS/Fixer/AbstractFixer.php @@ -45,7 +45,7 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( $this->getDocumentation(), array_map( - fn (array $configutation = null) => new CodeSample($this->getSampleCode(), $configutation), + fn (?array $configutation = null) => new CodeSample($this->getSampleCode(), $configutation), $this->getSampleConfigurations() ) ); diff --git a/src/PedroTroller/CS/Fixer/RuleSetFactory.php b/src/PedroTroller/CS/Fixer/RuleSetFactory.php index 6e75b76..dc2d0d9 100644 --- a/src/PedroTroller/CS/Fixer/RuleSetFactory.php +++ b/src/PedroTroller/CS/Fixer/RuleSetFactory.php @@ -55,7 +55,7 @@ public static function create(array $rules = []): self ); } - public function per(int|float $version = null, bool $risky = false): self + public function per(null|float|int $version = null, bool $risky = false): self { $candidates = null !== $version ? ['@PER-CS'.number_format($version, 1, '.', '')] @@ -198,7 +198,7 @@ public function pedrotroller(bool $risky = false): self )); } - public function enable(string $name, array $config = null): self + public function enable(string $name, ?array $config = null): self { return self::create(array_merge( $this->rules, diff --git a/tests/TokensAnalyzerIntegration/MethodArguments.php b/tests/TokensAnalyzerIntegration/MethodArguments.php index c307cbe..872a4a4 100644 --- a/tests/TokensAnalyzerIntegration/MethodArguments.php +++ b/tests/TokensAnalyzerIntegration/MethodArguments.php @@ -67,7 +67,7 @@ public function assertions(TokensAnalyzer $analyzer, Tokens $tokens): void $arguments, [ ($theFunction + 5) => [ - 'type' => 'Domain\\Model\\User', + 'type' => 'Domain\Model\User', 'name' => '$user', 'nullable' => false, 'asDefault' => false, From f928d7640a252fac3b377086e2c4119b2b6fdf8f Mon Sep 17 00:00:00 2001 From: Joris Mak Date: Fri, 28 Jun 2024 11:31:37 +0200 Subject: [PATCH 2/4] fix compatibility with 3.59.3 --- src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php | 5 ++++- .../CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php | 5 ++++- .../CodingStyle/LineBreakBetweenMethodArgumentsFixer.php | 5 ++++- src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php | 5 ++++- src/PedroTroller/CS/Fixer/PhpspecFixer.php | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php b/src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php index ea44517..70f5fed 100644 --- a/src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php +++ b/src/PedroTroller/CS/Fixer/Behat/OrderBehatStepsFixer.php @@ -8,6 +8,7 @@ use PedroTroller\CS\Fixer\Priority; use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer; use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerTrait; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; @@ -15,6 +16,8 @@ final class OrderBehatStepsFixer extends AbstractOrderedClassElementsFixer implements ConfigurableFixerInterface { + use ConfigurableFixerTrait; + public const ANNOTATION_PRIORITIES = [ '@BeforeSuite', '@AfterSuite', @@ -126,7 +129,7 @@ public function getDocumentation(): string return 'Step definition methods in Behat contexts MUST BE ordered by annotation and method name.'; } - public function getConfigurationDefinition(): FixerConfigurationResolverInterface + public function createConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ (new FixerOptionBuilder('instanceof', 'Parent class or interface of your behat context classes.')) diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php index a75f975..c0113ce 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php @@ -6,6 +6,7 @@ use PedroTroller\CS\Fixer\AbstractFixer; use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerTrait; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; @@ -15,6 +16,8 @@ final class ForbiddenFunctionsFixer extends AbstractFixer implements ConfigurableFixerInterface { + use ConfigurableFixerTrait; + public function getSampleCode(): string { return <<<'PHP' @@ -53,7 +56,7 @@ public function getDocumentation(): string return 'Prohibited functions MUST BE commented on as prohibited'; } - public function getConfigurationDefinition(): FixerConfigurationResolverInterface + public function createConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ (new FixerOptionBuilder('functions', 'The function names to be marked how prohibited')) diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php index 6b94a32..988f750 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php @@ -8,6 +8,7 @@ use PedroTroller\CS\Fixer\Priority; use PhpCsFixer\Fixer\Basic\BracesFixer; use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerTrait; use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer; use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; @@ -19,6 +20,8 @@ final class LineBreakBetweenMethodArgumentsFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { + use ConfigurableFixerTrait; + public const T_TYPEHINT_SEMI_COLON = 10025; public function getPriority(): int @@ -81,7 +84,7 @@ public function fun3( SPEC; } - public function getConfigurationDefinition(): FixerConfigurationResolverInterface + public function createConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ (new FixerOptionBuilder('max-args', 'The maximum number of arguments allowed with splitting the arguments into several lines (use `false` to disable this feature)')) diff --git a/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php b/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php index 94bc5e2..814756c 100644 --- a/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php +++ b/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php @@ -6,6 +6,7 @@ use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerTrait; use PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer; use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; @@ -17,6 +18,8 @@ final class DoctrineMigrationsFixer extends AbstractFixer implements ConfigurableFixerInterface { + use ConfigurableFixerTrait; + /** * @var string[] */ @@ -100,7 +103,7 @@ public function getPriority(): int return Priority::before(ClassAttributesSeparationFixer::class, NoEmptyPhpdocFixer::class, NoExtraBlankLinesFixer::class); } - public function getConfigurationDefinition(): FixerConfigurationResolverInterface + public function createConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ (new FixerOptionBuilder('instanceof', 'The parent class of which Doctrine migrations extend')) diff --git a/src/PedroTroller/CS/Fixer/PhpspecFixer.php b/src/PedroTroller/CS/Fixer/PhpspecFixer.php index e92f0e6..3f481a4 100644 --- a/src/PedroTroller/CS/Fixer/PhpspecFixer.php +++ b/src/PedroTroller/CS/Fixer/PhpspecFixer.php @@ -6,6 +6,7 @@ use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer; use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerTrait; use PhpCsFixer\Fixer\FunctionNotation\StaticLambdaFixer; use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; @@ -17,6 +18,8 @@ final class PhpspecFixer extends AbstractOrderedClassElementsFixer implements ConfigurableFixerInterface { + use ConfigurableFixerTrait; + public function getSampleConfigurations(): array { return [ @@ -101,7 +104,7 @@ public function getPriority(): int ); } - public function getConfigurationDefinition(): FixerConfigurationResolverInterface + public function createConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ (new FixerOptionBuilder('instanceof', 'Parent classes of your spec classes.')) From 3c0d30bb551582bffad52250783349757bcc0fd5 Mon Sep 17 00:00:00 2001 From: Joris Mak <47725838+jorismak@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:13:36 +0200 Subject: [PATCH 3/4] fix compatibility with 3.59.3 (#210) Co-authored-by: Joris Mak From 8597cbf1855caf24b2c1d74391f56beeca26c968 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Fri, 2 Aug 2024 11:14:19 +0200 Subject: [PATCH 4/4] refactor: apply new coding standards --- composer.json | 1 + src/PedroTroller/CS/Fixer/AbstractFixer.php | 2 +- .../OrderedWithGetterAndSetterFirstFixer.php | 8 ++++---- .../Fixer/CodingStyle/ExceptionsPunctuationFixer.php | 2 +- .../CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php | 2 +- .../CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php | 2 +- src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php | 2 +- src/PedroTroller/CS/Fixer/PhpspecFixer.php | 2 +- src/PedroTroller/CS/Fixer/TokensAnalyzer.php | 10 +++++----- tests/Orchestra.php | 4 ++-- tests/Runner.php | 10 +++++----- tests/TokensAnalyzerIntegration.php | 2 +- .../LineBreakBetweenMethods/Regression/Case1.php | 4 ++-- tests/UseCase/Phpspec/Regression/Case1.php | 4 ++-- tests/UseCase/Phpspec/Regression/Case2.php | 4 ++-- 15 files changed, 30 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index 9242423..87d66a1 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "friendsofphp/php-cs-fixer": ">=3.59.3" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.60", "phpspec/phpspec": "^7.0", "sebastian/diff": "^4.0", "twig/twig": "^3.3", diff --git a/src/PedroTroller/CS/Fixer/AbstractFixer.php b/src/PedroTroller/CS/Fixer/AbstractFixer.php index d2d8b74..eecec51 100644 --- a/src/PedroTroller/CS/Fixer/AbstractFixer.php +++ b/src/PedroTroller/CS/Fixer/AbstractFixer.php @@ -23,7 +23,7 @@ public function isCandidate(Tokens $tokens): bool public function getName(): string { - return sprintf('PedroTroller/%s', parent::getName()); + return \sprintf('PedroTroller/%s', parent::getName()); } /** diff --git a/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php b/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php index 10552ea..dca0e9a 100644 --- a/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php +++ b/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php @@ -152,11 +152,11 @@ private function getMethodsNames(array $elements): array $methods = []; foreach ($this->getPropertiesNames($elements) as $name) { - $methods[] = sprintf('get%s', ucfirst($name)); - $methods[] = sprintf('is%s', ucfirst($name)); - $methods[] = sprintf('has%s', ucfirst($name)); + $methods[] = \sprintf('get%s', ucfirst($name)); + $methods[] = \sprintf('is%s', ucfirst($name)); + $methods[] = \sprintf('has%s', ucfirst($name)); $methods[] = lcfirst($name); - $methods[] = sprintf('set%s', ucfirst($name)); + $methods[] = \sprintf('set%s', ucfirst($name)); } return $methods; diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/ExceptionsPunctuationFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/ExceptionsPunctuationFixer.php index c2a0add..a8c447e 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/ExceptionsPunctuationFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/ExceptionsPunctuationFixer.php @@ -152,6 +152,6 @@ private function cleanupMessage(Token $token): Token return $token; } - return new Token([T_CONSTANT_ENCAPSED_STRING, sprintf('%s%s.%s', $quotes, implode('', $chars), $quotes)]); + return new Token([T_CONSTANT_ENCAPSED_STRING, \sprintf('%s%s.%s', $quotes, implode('', $chars), $quotes)]); } } diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php index c0113ce..868b89e 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php @@ -89,7 +89,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void if (\in_array($token->getContent(), $this->configuration['functions'], true)) { $end = $this->analyze($tokens)->getEndOfTheLine($index); - $tokens[$end] = new Token([T_WHITESPACE, sprintf(' // %s%s', $this->configuration['comment'], $tokens[$end]->getContent())]); + $tokens[$end] = new Token([T_WHITESPACE, \sprintf(' // %s%s', $this->configuration['comment'], $tokens[$end]->getContent())]); } } } diff --git a/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php b/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php index 5e0cf3a..cedd462 100644 --- a/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php +++ b/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php @@ -153,6 +153,6 @@ private function formatComments(array $comments, string $indentation): string $comments = implode("\n", $comments); $comments = trim($comments, " \n"); - return sprintf("/**\n%s %s\n%s */", $indentation, $comments, $indentation); + return \sprintf("/**\n%s %s\n%s */", $indentation, $comments, $indentation); } } diff --git a/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php b/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php index 814756c..92b9545 100644 --- a/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php +++ b/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php @@ -19,7 +19,7 @@ final class DoctrineMigrationsFixer extends AbstractFixer implements ConfigurableFixerInterface { use ConfigurableFixerTrait; - + /** * @var string[] */ diff --git a/src/PedroTroller/CS/Fixer/PhpspecFixer.php b/src/PedroTroller/CS/Fixer/PhpspecFixer.php index 3f481a4..07ad383 100644 --- a/src/PedroTroller/CS/Fixer/PhpspecFixer.php +++ b/src/PedroTroller/CS/Fixer/PhpspecFixer.php @@ -265,7 +265,7 @@ private function filterElementsByMethodName(string $regex, array $elements): arr $filter = []; foreach ($this->filterElementsByType('method', $elements) as $index => $method) { - if (0 !== preg_match(sprintf('/^%s$/', $regex), $method['methodName'])) { + if (0 !== preg_match(\sprintf('/^%s$/', $regex), $method['methodName'])) { $filter[$index] = $method; } } diff --git a/src/PedroTroller/CS/Fixer/TokensAnalyzer.php b/src/PedroTroller/CS/Fixer/TokensAnalyzer.php index f356f96..d80b50b 100644 --- a/src/PedroTroller/CS/Fixer/TokensAnalyzer.php +++ b/src/PedroTroller/CS/Fixer/TokensAnalyzer.php @@ -186,7 +186,7 @@ public function getNextSemiColon($index) public function getReturnedType($index) { if (false === $this->tokens[$index]->isGivenKind(T_FUNCTION)) { - throw new Exception(sprintf('Expected token: T_FUNCTION Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); + throw new Exception(\sprintf('Expected token: T_FUNCTION Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); } $methodName = $this->tokens->getNextMeaningfulToken($index); @@ -317,7 +317,7 @@ public function endOfTheStatement(int $index): ?int public function getClosingParenthesis($index) { if ('(' !== $this->tokens[$index]->getContent()) { - throw new Exception(sprintf('Expected token: (. Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); + throw new Exception(\sprintf('Expected token: (. Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); } for ($i = $index + 1; $i < $this->tokens->count(); ++$i) { @@ -345,7 +345,7 @@ public function getClosingParenthesis($index) public function getClosingBracket($index) { if ('[' !== $this->tokens[$index]->getContent()) { - throw new Exception(sprintf('Expected token: [. Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); + throw new Exception(\sprintf('Expected token: [. Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); } for ($i = $index + 1; $i < $this->tokens->count(); ++$i) { @@ -373,7 +373,7 @@ public function getClosingBracket($index) public function getClosingCurlyBracket($index) { if ('{' !== $this->tokens[$index]->getContent()) { - throw new Exception(sprintf('Expected token: {. Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); + throw new Exception(\sprintf('Expected token: {. Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); } for ($i = $index + 1; $i < $this->tokens->count(); ++$i) { @@ -401,7 +401,7 @@ public function getClosingCurlyBracket($index) public function getClosingAttribute($index) { if (false === $this->tokens[$index]->isGivenKind(T_ATTRIBUTE)) { - throw new Exception(sprintf('Expected token: T_ATTRIBUTE Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); + throw new Exception(\sprintf('Expected token: T_ATTRIBUTE Token %d id contains %s.', $index, $this->tokens[$index]->getContent())); } for ($i = $index + 1; $i < $this->tokens->count(); ++$i) { diff --git a/tests/Orchestra.php b/tests/Orchestra.php index a92f807..154ee38 100644 --- a/tests/Orchestra.php +++ b/tests/Orchestra.php @@ -65,7 +65,7 @@ public static function assert(FixerInterface $fixer) */ public function before(FixerInterface $other) { - echo sprintf("\nRun %s before %s\n", $this->fixer->getName(), $other->getName()); + echo \sprintf("\nRun %s before %s\n", $this->fixer->getName(), $other->getName()); Assert::greaterThan( $this->fixer->getPriority(), @@ -80,7 +80,7 @@ public function before(FixerInterface $other) */ public function after(FixerInterface $other) { - echo sprintf("\nRun %s after %s\n", $this->fixer->getName(), $other->getName()); + echo \sprintf("\nRun %s after %s\n", $this->fixer->getName(), $other->getName()); Assert::lessThan( $this->fixer->getPriority(), diff --git a/tests/Runner.php b/tests/Runner.php index e8da806..39b5e26 100644 --- a/tests/Runner.php +++ b/tests/Runner.php @@ -19,7 +19,7 @@ public static function run(): void set_error_handler( static function ($type, $message, $file, $line) use (&$deprecations): void { - $deprecations[$message][] = sprintf('%s at line %d', $file, $line); + $deprecations[$message][] = \sprintf('%s at line %d', $file, $line); $deprecations[$message] = array_unique($deprecations[$message]); sort($deprecations[$message]); @@ -35,12 +35,12 @@ static function ($type, $message, $file, $line) use (&$deprecations): void { if (false === empty($deprecations)) { ksort($deprecations); - $message = sprintf( + $message = \sprintf( "Deprecations : \n\n%s", implode( "\n\n", array_map( - static fn ($message, array $files) => sprintf("%s\n%s", $message, implode("\n", $files)), + static fn ($message, array $files) => \sprintf("%s\n%s", $message, implode("\n", $files)), array_keys($deprecations), $deprecations ) @@ -53,7 +53,7 @@ static function ($type, $message, $file, $line) use (&$deprecations): void { private static function runUseCases(): void { - $directory = sprintf('%s/UseCase', __DIR__); + $directory = \sprintf('%s/UseCase', __DIR__); $finder = new Finder(); $finder @@ -100,7 +100,7 @@ private static function runUseCases(): void private static function runAnalyzerIntegrations(): void { - $directory = sprintf('%s/TokensAnalyzerIntegration', __DIR__); + $directory = \sprintf('%s/TokensAnalyzerIntegration', __DIR__); $finder = new Finder(); $finder diff --git a/tests/TokensAnalyzerIntegration.php b/tests/TokensAnalyzerIntegration.php index 0423e15..f36c8ba 100644 --- a/tests/TokensAnalyzerIntegration.php +++ b/tests/TokensAnalyzerIntegration.php @@ -53,7 +53,7 @@ protected function tokensContaining(Tokens $tokens, $content) } if (empty($indexes)) { - throw new Exception(sprintf('There is no token containing %s.', $content)); + throw new Exception(\sprintf('There is no token containing %s.', $content)); } return $indexes; diff --git a/tests/UseCase/LineBreakBetweenMethods/Regression/Case1.php b/tests/UseCase/LineBreakBetweenMethods/Regression/Case1.php index 33d64fd..ec4f5fd 100644 --- a/tests/UseCase/LineBreakBetweenMethods/Regression/Case1.php +++ b/tests/UseCase/LineBreakBetweenMethods/Regression/Case1.php @@ -23,12 +23,12 @@ public function getFixers(): iterable public function getRawScript(): string { - return file_get_contents(sprintf('%s/Case1/CamelizeNamingStrategy.php.text', __DIR__)); + return file_get_contents(\sprintf('%s/Case1/CamelizeNamingStrategy.php.text', __DIR__)); } public function getExpectation(): string { - return file_get_contents(sprintf('%s/Case1/CamelizeNamingStrategy.php.text', __DIR__)); + return file_get_contents(\sprintf('%s/Case1/CamelizeNamingStrategy.php.text', __DIR__)); } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/Phpspec/Regression/Case1.php b/tests/UseCase/Phpspec/Regression/Case1.php index 946586a..bfeb45d 100644 --- a/tests/UseCase/Phpspec/Regression/Case1.php +++ b/tests/UseCase/Phpspec/Regression/Case1.php @@ -22,12 +22,12 @@ public function getFixers(): iterable public function getRawScript(): string { - return file_get_contents(sprintf('%s/Case1/file.php.txt', __DIR__)); + return file_get_contents(\sprintf('%s/Case1/file.php.txt', __DIR__)); } public function getExpectation(): string { - return file_get_contents(sprintf('%s/Case1/file.php.txt', __DIR__)); + return file_get_contents(\sprintf('%s/Case1/file.php.txt', __DIR__)); } public function getMinSupportedPhpVersion(): int diff --git a/tests/UseCase/Phpspec/Regression/Case2.php b/tests/UseCase/Phpspec/Regression/Case2.php index 782c697..5a03634 100644 --- a/tests/UseCase/Phpspec/Regression/Case2.php +++ b/tests/UseCase/Phpspec/Regression/Case2.php @@ -16,12 +16,12 @@ public function getFixers(): iterable public function getRawScript(): string { - return file_get_contents(sprintf('%s/Case2/file.php.txt', __DIR__)); + return file_get_contents(\sprintf('%s/Case2/file.php.txt', __DIR__)); } public function getExpectation(): string { - return file_get_contents(sprintf('%s/Case2/file.php.txt', __DIR__)); + return file_get_contents(\sprintf('%s/Case2/file.php.txt', __DIR__)); } public function getMinSupportedPhpVersion(): int