Skip to content

Commit

Permalink
minor #5661 DX: remove PHPStan exceptions for "tests" from phpstan.ne…
Browse files Browse the repository at this point in the history
…on (kubawerlos)

This PR was merged into the 2.18 branch.

Discussion
----------

DX: remove PHPStan exceptions for "tests" from phpstan.neon

After [#5626](https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5626/files) it got me thinking that PHPStan is not always able to detect errors properly - sometimes because it runs on single PHP version with single set of dependencies, sometimes because there is some dynamic behaviour. So it may be not bad idea to use `@phpstan-ignore-line` as it's not really exception, but false positive case.

Nonetheless, in this PR all the PHPStan exceptions are removed from phpstan.neon and fixed or handled via `@phpstan-ignore-line` annotation.

Commits
-------

7d32ab2 DX: remove PHPStan exceptions for "tests" from phpstan.neon
  • Loading branch information
keradus committed Apr 28, 2021
2 parents 93f1df5 + 7d32ab2 commit 8054f4c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 21 deletions.
15 changes: 0 additions & 15 deletions phpstan.neon
Expand Up @@ -35,32 +35,17 @@ parameters:
paths:
- src/Config.php
- src/Tokenizer/Token.php
-
message: '/^Parameter #1 \$fixers of method PhpCsFixer\\Config::registerCustomFixers\(\) expects iterable<PhpCsFixer\\Fixer\\FixerInterface>, string given\.$/'
path: tests/ConfigTest.php
-
message: '/^Parameter #1 \$options of method PhpCsFixer\\FixerConfiguration\\FixerConfigurationResolverRootless::resolve\(\) expects array<string, mixed>, array<int, string> given\.$/'
path: tests/FixerConfiguration/FixerConfigurationResolverRootlessTest.php
-
message: '/^Parameter #1 \$function of function register_shutdown_function expects callable\(\): void, array\(\$this\(PhpCsFixer\\FileRemoval\), ''clean''\) given\.$/'
path: src/FileRemoval.php
-
message: '/^Parameter #1 \$finder of method PhpCsFixer\\Config::setFinder\(\) expects iterable<string>, int given\.$/'
path: tests/ConfigTest.php
- # https://github.com/phpstan/phpstan/issues/1215
message: '/^Strict comparison using === between false and string will always evaluate to false\.$/'
path: src/Fixer/StringNotation/NoTrailingWhitespaceInStringFixer.php
-
message: '/^Property .*::\$indicator .* does not accept null\.$/'
path: tests/Indicator/PhpUnitTestCaseIndicatorTest.php
-
message: '/^Constant T_ATTRIBUTE not found\.$/'
path: src/Tokenizer/Transformer/AttributeTransformer.php
-
message: '/^\$this\(PhpCsFixer\\Tokenizer\\Tokens\) does not accept PhpCsFixer\\Tokenizer\\Token\|null\.$/'
path: src/Tokenizer/Tokens.php
-
message: '/^Class Test\dConfig not found\.$/'
path: tests/Console/ConfigurationResolverTest.php

tipsOfTheDay: false
4 changes: 2 additions & 2 deletions tests/ConfigTest.php
Expand Up @@ -193,7 +193,7 @@ public function testRegisterCustomFixersWithInvalidArgument()
$this->expectExceptionMessageMatches('/^Argument must be an array or a Traversable, got "\w+"\.$/');

$config = new Config();
$config->registerCustomFixers('foo');
$config->registerCustomFixers('foo'); // @phpstan-ignore-line to avoid `expects iterable<PhpCsFixer\Fixer\FixerInterface>, string given`
}

/**
Expand Down Expand Up @@ -259,7 +259,7 @@ public function testSetInvalidFinder()
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/^Argument must be an array or a Traversable, got "integer"\.$/');

$config->setFinder(123);
$config->setFinder(123); // @phpstan-ignore-line to avoid `expects iterable<string>, int given`
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Console/ConfigurationResolverTest.php
Expand Up @@ -205,7 +205,7 @@ public function testResolveConfigFileByPathOfFile()
$resolver = $this->createConfigurationResolver(['path' => [$dir.\DIRECTORY_SEPARATOR.'foo.php']]);

static::assertSame($dir.\DIRECTORY_SEPARATOR.'.php_cs.dist', $resolver->getConfigFile());
static::assertInstanceOf(\Test1Config::class, $resolver->getConfig());
static::assertInstanceOf(\Test1Config::class, $resolver->getConfig()); // @phpstan-ignore-line to avoid `Class Test1Config not found.`
}

public function testResolveConfigFileSpecified()
Expand All @@ -215,7 +215,7 @@ public function testResolveConfigFileSpecified()
$resolver = $this->createConfigurationResolver(['config' => $file]);

static::assertSame($file, $resolver->getConfigFile());
static::assertInstanceOf(\Test4Config::class, $resolver->getConfig());
static::assertInstanceOf(\Test4Config::class, $resolver->getConfig()); // @phpstan-ignore-line to avoid `Class Test4Config not found.`
}

/**
Expand Down
Expand Up @@ -44,6 +44,6 @@ public function testResolveWithMappedRoot()

static::assertSame($options, $configuration->getOptions());

$configuration->resolve(['baz', 'qux']);
$configuration->resolve(['baz' => 'qux']);
}
}
2 changes: 1 addition & 1 deletion tests/Indicator/PhpUnitTestCaseIndicatorTest.php
Expand Up @@ -25,7 +25,7 @@
final class PhpUnitTestCaseIndicatorTest extends TestCase
{
/**
* @var PhpUnitTestCaseIndicator
* @var null|PhpUnitTestCaseIndicator
*/
private $indicator;

Expand Down

0 comments on commit 8054f4c

Please sign in to comment.