From abbf8615b93badd541b22261b0a479b8ed3ac2e5 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 10 May 2021 09:55:05 +0200 Subject: [PATCH] Keep native_function_invocation => ['include' => ['@internal']] --- composer.json | 2 +- lib/AbstractFixer.php | 2 +- lib/Config.php | 6 ++-- lib/FinalAbstractPublicFixer.php | 6 ++-- lib/FinalInternalClassFixer.php | 6 ++-- lib/InlineCommentSpacerFixer.php | 4 +-- lib/PhpFileOnlyProxyFixer.php | 6 ++-- lib/Utf8Fixer.php | 6 ++-- tests/AbstractFixerTestCase.php | 14 +++++----- tests/ConfigTest.php | 34 +++++++++++------------ tests/FinalAbstractPublicFixerTest.php | 4 +-- tests/FunctionReferenceSpaceFixerTest.php | 18 ++++++------ tests/PhpFileOnlyProxyFixerTest.php | 16 +++++------ tests/Utf8FixerTest.php | 2 +- 14 files changed, 63 insertions(+), 63 deletions(-) diff --git a/composer.json b/composer.json index 6ef971f..6f95478 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require-dev": { "malukenho/mcbumpface": "^1.1.5", - "phpstan/phpstan": "^0.12.85", + "phpstan/phpstan": "^0.12.86", "phpstan/phpstan-phpunit": "^0.12.18", "phpunit/phpunit": "^9.5.4", "slam/php-debug-r": "^1.7.0", diff --git a/lib/AbstractFixer.php b/lib/AbstractFixer.php index fa382af..3ad79e0 100644 --- a/lib/AbstractFixer.php +++ b/lib/AbstractFixer.php @@ -10,6 +10,6 @@ abstract class AbstractFixer extends PhpCsFixerAbstractFixer { final public function getName(): string { - return sprintf('Slam/%s', parent::getName()); + return \sprintf('Slam/%s', parent::getName()); } } diff --git a/lib/Config.php b/lib/Config.php index 24bf89d..b505032 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -43,7 +43,7 @@ final class Config extends PhpCsFixerConfig 'mb_str_functions' => false, 'method_argument_space' => ['keep_multiple_spaces_after_comma' => true], 'native_constant_invocation' => true, - 'native_function_invocation' => true, + 'native_function_invocation' => ['include' => ['@internal']], 'no_blank_lines_before_namespace' => false, 'no_multiline_whitespace_around_double_arrow' => false, 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], @@ -83,7 +83,7 @@ final class Config extends PhpCsFixerConfig public function __construct(array $overriddenRules = []) { parent::__construct(__NAMESPACE__); - putenv('PHP_CS_FIXER_FUTURE_MODE=1'); + \putenv('PHP_CS_FIXER_FUTURE_MODE=1'); $this->setRiskyAllowed(true); $this->registerCustomFixers([ @@ -97,7 +97,7 @@ public function __construct(array $overriddenRules = []) $rules = self::RULES; if (! empty($overriddenRules)) { - $rules = array_merge($rules, $overriddenRules); + $rules = \array_merge($rules, $overriddenRules); } $this->setRules($rules); diff --git a/lib/FinalAbstractPublicFixer.php b/lib/FinalAbstractPublicFixer.php index 2ef56ff..1858501 100644 --- a/lib/FinalAbstractPublicFixer.php +++ b/lib/FinalAbstractPublicFixer.php @@ -48,9 +48,9 @@ public function isRisky(): bool protected function applyFix(SplFileInfo $file, Tokens $tokens): void { - $classes = array_keys($tokens->findGivenKind(\T_CLASS)); + $classes = \array_keys($tokens->findGivenKind(\T_CLASS)); - while ($classIndex = array_pop($classes)) { + while ($classIndex = \array_pop($classes)) { $prevToken = $tokens[$tokens->getPrevMeaningfulToken($classIndex)]; if (! $prevToken->isGivenKind([\T_ABSTRACT])) { continue; @@ -85,7 +85,7 @@ private function fixClass(Tokens $tokens, int $classOpenIndex, int $classCloseIn } $nextIndex = $tokens->getNextMeaningfulToken($nextIndex); $nextToken = $tokens[$nextIndex]; - if (! $nextToken->isGivenKind(\T_STRING) || 0 === mb_strpos($nextToken->getContent(), '__')) { + if (! $nextToken->isGivenKind(\T_STRING) || 0 === \mb_strpos($nextToken->getContent(), '__')) { continue; } $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)]; diff --git a/lib/FinalInternalClassFixer.php b/lib/FinalInternalClassFixer.php index 156cd50..a87e89a 100644 --- a/lib/FinalInternalClassFixer.php +++ b/lib/FinalInternalClassFixer.php @@ -37,9 +37,9 @@ public function isRisky(): bool protected function applyFix(SplFileInfo $file, Tokens $tokens): void { - $classes = array_keys($tokens->findGivenKind(\T_CLASS)); + $classes = \array_keys($tokens->findGivenKind(\T_CLASS)); - while ($classIndex = array_pop($classes)) { + while ($classIndex = \array_pop($classes)) { // ignore class if it is abstract or already final $prevToken = $tokens[$tokens->getPrevMeaningfulToken($classIndex)]; if ($prevToken->isGivenKind([\T_ABSTRACT, \T_FINAL, \T_NEW])) { @@ -48,7 +48,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void // ignore class if it's a Doctrine Entity $docToken = $tokens[$tokens->getPrevNonWhitespace($classIndex)]; - if ($docToken->isGivenKind(\T_DOC_COMMENT) && false !== mb_strpos($docToken->getContent(), '@ORM\Entity')) { + if ($docToken->isGivenKind(\T_DOC_COMMENT) && false !== \mb_strpos($docToken->getContent(), '@ORM\Entity')) { continue; } diff --git a/lib/InlineCommentSpacerFixer.php b/lib/InlineCommentSpacerFixer.php index abe3d60..271d01a 100644 --- a/lib/InlineCommentSpacerFixer.php +++ b/lib/InlineCommentSpacerFixer.php @@ -37,11 +37,11 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void { foreach ($tokens as $index => $token) { $content = $token->getContent(); - if (! $token->isComment() || '//' !== mb_substr($content, 0, 2) || '// ' === mb_substr($content, 0, 3)) { + if (! $token->isComment() || '//' !== \mb_substr($content, 0, 2) || '// ' === \mb_substr($content, 0, 3)) { continue; } - $content = substr_replace($content, ' ', 2, 0); + $content = \substr_replace($content, ' ', 2, 0); $tokens[$index] = new Token([$token->getId(), $content]); } } diff --git a/lib/PhpFileOnlyProxyFixer.php b/lib/PhpFileOnlyProxyFixer.php index 0535e28..a9b16b1 100644 --- a/lib/PhpFileOnlyProxyFixer.php +++ b/lib/PhpFileOnlyProxyFixer.php @@ -65,7 +65,7 @@ public function getDefinition(): FixerDefinitionInterface $originalDefinition = $this->fixer->getDefinition(); return new FixerDefinition( - sprintf('PHP-FILE-ONLY: %s', $originalDefinition->getSummary()), + \sprintf('PHP-FILE-ONLY: %s', $originalDefinition->getSummary()), $originalDefinition->getCodeSamples(), $originalDefinition->getDescription(), $originalDefinition->getRiskyDescription() @@ -89,7 +89,7 @@ public function fix(SplFileInfo $file, Tokens $tokens): void public function getName(): string { - return sprintf('Slam/php_only_%s', str_replace('/', '_', mb_strtolower($this->fixer->getName()))); + return \sprintf('Slam/php_only_%s', \str_replace('/', '_', \mb_strtolower($this->fixer->getName()))); } public function getPriority(): int @@ -99,6 +99,6 @@ public function getPriority(): int public function supports(SplFileInfo $file): bool { - return 'php' === pathinfo($file->getFilename(), \PATHINFO_EXTENSION); + return 'php' === \pathinfo($file->getFilename(), \PATHINFO_EXTENSION); } } diff --git a/lib/Utf8Fixer.php b/lib/Utf8Fixer.php index 5e79060..470a715 100644 --- a/lib/Utf8Fixer.php +++ b/lib/Utf8Fixer.php @@ -17,7 +17,7 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( 'Converts files from Windows-1252 to UTF8.', [ - new CodeSample(mb_convert_encoding('generateCode(); - if (false === mb_check_encoding($content, 'UTF-8')) { - $tokens->setCode(mb_convert_encoding($content, 'UTF-8', 'Windows-1252')); + if (false === \mb_check_encoding($content, 'UTF-8')) { + $tokens->setCode(\mb_convert_encoding($content, 'UTF-8', 'Windows-1252')); } } diff --git a/tests/AbstractFixerTestCase.php b/tests/AbstractFixerTestCase.php index cb5d732..4434011 100644 --- a/tests/AbstractFixerTestCase.php +++ b/tests/AbstractFixerTestCase.php @@ -27,8 +27,8 @@ protected function setUp(): void final protected function createFixer() { $fixerClass = static::class; - $fixerClass = str_replace('\\Tests\\', '\\', $fixerClass); - $fixerClass = preg_replace('/Test$/', '', $fixerClass); + $fixerClass = \str_replace('\\Tests\\', '\\', $fixerClass); + $fixerClass = \preg_replace('/Test$/', '', $fixerClass); return new $fixerClass(); } @@ -95,8 +95,8 @@ final protected function doTest($expected, $input = null, ?SplFileInfo $file = n static::assertSame( \count($tokens), - \count(array_unique(array_map(static function (Token $token) { - return spl_object_hash($token); + \count(\array_unique(\array_map(static function (Token $token) { + return \spl_object_hash($token); }, $tokens->toArray()))), 'Token items inside Tokens collection must be unique.' ); @@ -143,20 +143,20 @@ private static function assertTokens(Tokens $expectedTokens, Tokens $inputTokens { foreach ($expectedTokens as $index => $expectedToken) { if (! isset($inputTokens[$index])) { - static::fail(sprintf("The token at index %d must be:\n%s, but is not set in the input collection.", $index, $expectedToken->toJson())); + static::fail(\sprintf("The token at index %d must be:\n%s, but is not set in the input collection.", $index, $expectedToken->toJson())); } $inputToken = $inputTokens[$index]; static::assertTrue( $expectedToken->equals($inputToken), - sprintf("The token at index %d must be:\n%s,\ngot:\n%s.", $index, $expectedToken->toJson(), $inputToken->toJson()) + \sprintf("The token at index %d must be:\n%s,\ngot:\n%s.", $index, $expectedToken->toJson(), $inputToken->toJson()) ); $expectedTokenKind = $expectedToken->isArray() ? $expectedToken->getId() : $expectedToken->getContent(); static::assertTrue( $inputTokens->isTokenKindFound($expectedTokenKind), - sprintf( + \sprintf( 'The token kind %s (%s) must be found in tokens collection.', $expectedTokenKind, \is_string($expectedTokenKind) ? $expectedTokenKind : Token::getNameForId($expectedTokenKind) diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 280d612..4c3f818 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -47,27 +47,27 @@ public function testAllRulesAreSpecifiedAndDifferentFromRuleSets(): void $rules[$name] = $value; } - $currentRules = array_keys($rules); - sort($currentRules); + $currentRules = \array_keys($rules); + \sort($currentRules); $fixerFactory = new FixerFactory(); $fixerFactory->registerBuiltInFixers(); $fixerFactory->registerCustomFixers($config->getCustomFixers()); $fixers = $fixerFactory->getFixers(); - $availableRules = array_filter($fixers, static function (FixerInterface $fixer): bool { + $availableRules = \array_filter($fixers, static function (FixerInterface $fixer): bool { return ! $fixer instanceof DeprecatedFixerInterface; }); - $availableRules = array_map(function (FixerInterface $fixer): string { + $availableRules = \array_map(function (FixerInterface $fixer): string { return $fixer->getName(); }, $availableRules); - sort($availableRules); + \sort($availableRules); - $diff = array_diff($availableRules, $currentRules); - self::assertEmpty($diff, sprintf("The following fixers are missing:\n- %s", implode(\PHP_EOL . '- ', $diff))); + $diff = \array_diff($availableRules, $currentRules); + self::assertEmpty($diff, \sprintf("The following fixers are missing:\n- %s", \implode(\PHP_EOL . '- ', $diff))); - $diff = array_diff($currentRules, $availableRules); - self::assertEmpty($diff, sprintf("The following fixers do not exist:\n- %s", implode(\PHP_EOL . '- ', $diff))); + $diff = \array_diff($currentRules, $availableRules); + self::assertEmpty($diff, \sprintf("The following fixers do not exist:\n- %s", \implode(\PHP_EOL . '- ', $diff))); $alreadyDefinedRules = []; foreach (Config::RULES as $ruleName => $ruleConfig) { @@ -79,31 +79,31 @@ public function testAllRulesAreSpecifiedAndDifferentFromRuleSets(): void } self::assertSame([], $alreadyDefinedRules, 'These rules are already defined in the respective set'); - $currentSets = array_values(array_filter(array_keys($configRules), static function (string $fixerName): bool { + $currentSets = \array_values(\array_filter(\array_keys($configRules), static function (string $fixerName): bool { return isset($fixerName[0]) && '@' === $fixerName[0]; })); $defaultSets = RuleSets::getSetDefinitionNames(); - $intersectSets = array_values(array_intersect($defaultSets, $currentSets)); - self::assertEquals($intersectSets, $currentSets, sprintf('Rule sets must be ordered as the appear in %s', RuleSet::class)); + $intersectSets = \array_values(\array_intersect($defaultSets, $currentSets)); + self::assertEquals($intersectSets, $currentSets, \sprintf('Rule sets must be ordered as the appear in %s', RuleSet::class)); - $currentRules = array_values(array_filter(array_keys($configRules), static function (string $fixerName): bool { + $currentRules = \array_values(\array_filter(\array_keys($configRules), static function (string $fixerName): bool { return isset($fixerName[0]) && '@' !== $fixerName[0]; })); $orderedCurrentRules = $currentRules; - sort($orderedCurrentRules); + \sort($orderedCurrentRules); self::assertEquals($orderedCurrentRules, $currentRules, 'Order the rules alphabetically please'); } public function testFutureMode(): void { - putenv('PHP_CS_FIXER_FUTURE_MODE'); + \putenv('PHP_CS_FIXER_FUTURE_MODE'); - self::assertFalse(getenv('PHP_CS_FIXER_FUTURE_MODE')); + self::assertFalse(\getenv('PHP_CS_FIXER_FUTURE_MODE')); new Config(); - self::assertNotEmpty(getenv('PHP_CS_FIXER_FUTURE_MODE')); + self::assertNotEmpty(\getenv('PHP_CS_FIXER_FUTURE_MODE')); } public function testOverwrite(): void diff --git a/tests/FinalAbstractPublicFixerTest.php b/tests/FinalAbstractPublicFixerTest.php index bebd31f..5b4dcc3 100644 --- a/tests/FinalAbstractPublicFixerTest.php +++ b/tests/FinalAbstractPublicFixerTest.php @@ -37,8 +37,8 @@ protected static function f5(){} private static function f6(){} '; $fixed = $original; - $fixed = str_replace('public static function', 'final public static function', $fixed); - $fixed = str_replace('public function', 'final public function', $fixed); + $fixed = \str_replace('public static function', 'final public static function', $fixed); + $fixed = \str_replace('public function', 'final public function', $fixed); return [ 'final-class' => ["expects(self::once()) ->method('isCandidate') ->with(self::identicalTo($tokens)) - ->willReturn($candidate = (bool) random_int(0, 1)) + ->willReturn($candidate = (bool) \random_int(0, 1)) ; self::assertSame($candidate, $proxy->isCandidate($tokens)); $fixer ->expects(self::once()) ->method('isRisky') - ->willReturn($risky = (bool) random_int(0, 1)) + ->willReturn($risky = (bool) \random_int(0, 1)) ; self::assertSame($risky, $proxy->isRisky()); @@ -56,7 +56,7 @@ public function testFixerInterfaceProxy(): void $fixer ->expects(self::once()) ->method('getName') - ->willReturn($name = uniqid('_name')) + ->willReturn($name = \uniqid('_name')) ; $proxyName = $proxy->getName(); self::assertStringContainsString('Slam', $proxyName); @@ -65,7 +65,7 @@ public function testFixerInterfaceProxy(): void $fixer ->expects(self::once()) ->method('getPriority') - ->willReturn($priority = random_int(-100, 100)) + ->willReturn($priority = \random_int(-100, 100)) ; self::assertSame($priority, $proxy->getPriority()); @@ -85,10 +85,10 @@ public function testGetDefinitionIsProxied(): void $proxy = new PhpFileOnlyProxyFixer($fixer); $fixerDefinition = $this->createMock(FixerDefinitionInterface::class); - $fixerDefinition->expects(self::once())->method('getSummary')->willReturn($summary = uniqid('summary')); + $fixerDefinition->expects(self::once())->method('getSummary')->willReturn($summary = \uniqid('summary')); $fixerDefinition->expects(self::once())->method('getCodeSamples')->willReturn($codeSamples = []); - $fixerDefinition->expects(self::once())->method('getDescription')->willReturn($description = uniqid('description')); - $fixerDefinition->expects(self::once())->method('getRiskyDescription')->willReturn($riskyDescription = uniqid('riskyDescription')); + $fixerDefinition->expects(self::once())->method('getDescription')->willReturn($description = \uniqid('description')); + $fixerDefinition->expects(self::once())->method('getRiskyDescription')->willReturn($riskyDescription = \uniqid('riskyDescription')); $fixer ->expects(self::once()) @@ -108,7 +108,7 @@ public function testGetDefinitionIsProxied(): void public function testConfigureIsProxied(): void { $fixer = $this->createMock(ConfigurableFixerInterface::class); - $configuration = [uniqid()]; + $configuration = [\uniqid()]; $proxy = new PhpFileOnlyProxyFixer($fixer); diff --git a/tests/Utf8FixerTest.php b/tests/Utf8FixerTest.php index c975718..5a7d168 100644 --- a/tests/Utf8FixerTest.php +++ b/tests/Utf8FixerTest.php @@ -18,6 +18,6 @@ public function testFix(): void € EOF; - $this->doTest($expected, file_get_contents(__DIR__ . '/_files/utf8-ansi.php')); + $this->doTest($expected, \file_get_contents(__DIR__ . '/_files/utf8-ansi.php')); } }