Skip to content

Commit

Permalink
Keep native_function_invocation => ['include' => ['@internal']]
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed May 10, 2021
1 parent bd71a1d commit abbf861
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/AbstractFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
6 changes: 3 additions & 3 deletions lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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([
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/FinalAbstractPublicFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)];
Expand Down
6 changes: 3 additions & 3 deletions lib/FinalInternalClassFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/InlineCommentSpacerFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/PhpFileOnlyProxyFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions lib/Utf8Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function getDefinition(): FixerDefinitionInterface
return new FixerDefinition(
'Converts files from Windows-1252 to UTF8.',
[
new CodeSample(mb_convert_encoding('<?php return \'è\';' . \PHP_EOL, 'Windows-1252', 'UTF-8')),
new CodeSample(\mb_convert_encoding('<?php return \'è\';' . \PHP_EOL, 'Windows-1252', 'UTF-8')),
],
null,
'Risky when files are encoded different from UTF-8 and Windows-1252.'
Expand All @@ -37,8 +37,8 @@ public function isRisky(): bool
protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
$content = $tokens->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'));
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/AbstractFixerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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.'
);
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 17 additions & 17 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/FinalAbstractPublicFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => ["<?php final class MyClass { ${original} }"],
Expand Down
18 changes: 9 additions & 9 deletions tests/FunctionReferenceSpaceFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public function provideCases(): array
{
$same = static function (string $content): string {
$use = $content;
$use = str_replace('array &', '&', $use);
$use = str_replace(' = array()', '', $use);
$use = str_replace('$array', '$secondArray', $use);
$use = \str_replace('array &', '&', $use);
$use = \str_replace(' = array()', '', $use);
$use = \str_replace('$array', '$secondArray', $use);

$invariant = \PHP_EOL . preg_replace('/\s+/', ' ', '
$invariant = \PHP_EOL . \preg_replace('/\s+/', ' ', '
$var =& $var;
$var =& $var;
$var =&$var;
Expand All @@ -42,7 +42,7 @@ public function provideCases(): array
$var = "&";
') . \PHP_EOL;

return sprintf(
return \sprintf(
'<?php
function test(%1$s) {
Expand Down Expand Up @@ -90,12 +90,12 @@ function xyz(%1$s) {
$same("array & \n \$array = array()"),
],
[
$same(implode(',', array_map(static function (string $var) use (& $inc1): string {
$same(\implode(',', \array_map(static function (string $var) use (& $inc1): string {
return $var . ++$inc1;
}, array_fill(0, 30, '& $array')))),
$same(implode(',', array_map(static function (string $var) use (& $inc2): string {
}, \array_fill(0, 30, '& $array')))),
$same(\implode(',', \array_map(static function (string $var) use (& $inc2): string {
return $var . ++$inc2;
}, array_fill(0, 30, '&$array')))),
}, \array_fill(0, 30, '&$array')))),
],
];
}
Expand Down
16 changes: 8 additions & 8 deletions tests/PhpFileOnlyProxyFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public function testFixerInterfaceProxy(): void
->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());

Expand All @@ -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);
Expand All @@ -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());

Expand All @@ -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())
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Utf8FixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

0 comments on commit abbf861

Please sign in to comment.