Skip to content

Commit

Permalink
minor #4791 Increase PHPStan level to 3 (julienfalque)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.15 branch.

Discussion
----------

Increase PHPStan level to 3

Commits
-------

83c8ea1 Increase PHPStan level to 3
  • Loading branch information
SpacePossum committed Feb 26, 2020
2 parents ed34dde + 83c8ea1 commit aa8e45f
Show file tree
Hide file tree
Showing 35 changed files with 91 additions and 57 deletions.
3 changes: 2 additions & 1 deletion dev-tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
},
"require-dev": {
"humbug/box": "^3.8",
"jangregor/phpstan-prophecy": "^0.6",
"localheinz/composer-normalize": "^1.1",
"mi-schi/phpmd-extension": "^4.3",
"phpmd/phpmd": "^2.6",
"phpstan/phpstan-phpunit": "^0.11.2"
"phpstan/phpstan-phpunit": "^0.12"
},
"conflict": {
"hhvm": "*"
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ composer info -D | sort

echo λλλ phive packages

./bin/phive install --trust-gpg-keys D2CCAC42F6295E7D,8E730BA25823D8B5
./bin/phive install --trust-gpg-keys D2CCAC42F6295E7D,8E730BA25823D8B5,CF1A108D0E7AE720
2 changes: 1 addition & 1 deletion dev-tools/phive.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="composer-require-checker" version="^2.0" installed="2.0.0" location="./tools/composer-require-checker" copy="false"/>
<phar name="phpstan" version="^0.11.15" installed="0.11.15" location="./tools/phpstan" copy="false"/>
<phar name="phpstan" version="^0.12" installed="0.12.9" location="./tools/phpstan" copy="true"/>
</phive>
8 changes: 6 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
includes:
- dev-tools/vendor/jangregor/phpstan-prophecy/src/extension.neon
- dev-tools/vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
level: 1
level: 3
paths:
- src
- tests
excludes_analyse:
- tests/Fixtures
ignoreErrors:
- '/^.+::__construct\(\) does not call parent constructor from SplFileInfo\.$/'
- '/^Return typehint of method PhpCsFixer\\Tests\\Test\\.+::createIsIdenticalStringConstraint\(\) has invalid type PHPUnit_Framework_Constraint_IsIdentical\.$/'
- '/^Class (Symfony\\Contracts\\EventDispatcher\\Event|Symfony\\Component\\EventDispatcher\\Event) not found.$/'
- '/^(Access|Call) to an undefined (property|method) PhpCsFixer\\AccessibleObject\\AccessibleObject::.+$/'
-
message: '/^Unsafe usage of new static\(\)\.$/'
path: src/Config.php
2 changes: 1 addition & 1 deletion src/AbstractFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function configure(array $configuration = null)
'Option "%s" for rule "%s" is deprecated and will be removed in version %d.0. %s',
$name,
$this->getName(),
(int) Application::VERSION + 1,
Application::getMajorVersion() + 1,
str_replace('`', '"', $option->getDeprecationMessage())
);

Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getCustomFixers()
}

/**
* {@inheritdoc}
* @return Finder
*/
public function getFinder()
{
Expand Down
8 changes: 8 additions & 0 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public function __construct()
));
}

/**
* @return int
*/
public static function getMajorVersion()
{
return (int) explode('.', self::VERSION)[0];
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 12 additions & 4 deletions src/Console/Command/DescribeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use PhpCsFixer\FixerDefinition\CodeSampleInterface;
use PhpCsFixer\FixerDefinition\FileSpecificCodeSampleInterface;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\FixerDefinition\VersionSpecificCodeSampleInterface;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\Preg;
Expand Down Expand Up @@ -330,12 +329,21 @@ private function describeSet(OutputInterface $output, $name)
$help = '';

foreach ($rules as $rule => $config) {
/** @var FixerDefinitionInterface $definition */
$definition = $fixers[$rule]->getDefinition();
$fixer = $fixers[$rule];

if (!$fixer instanceof DefinedFixerInterface) {
throw new \RuntimeException(sprintf(
'Cannot describe rule %s, the fixer does not implement %s',
$rule,
DefinedFixerInterface::class
));
}

$definition = $fixer->getDefinition();
$help .= sprintf(
" * <info>%s</info>%s\n | %s\n%s\n",
$rule,
$fixers[$rule]->isRisky() ? ' <error>risky</error>' : '',
$fixer->isRisky() ? ' <error>risky</error>' : '',
$definition->getSummary(),
true !== $config ? sprintf(" <comment>| Configuration: %s</comment>\n", HelpCommand::toString($config)) : ''
);
Expand Down
4 changes: 3 additions & 1 deletion src/Console/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\Console\Command;

use PhpCsFixer\AbstractFixer;
use PhpCsFixer\Console\Application;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
Expand Down Expand Up @@ -400,7 +401,7 @@ public static function getLatestReleaseVersionFromChangeLog()
));
}

for ($i = (int) Application::VERSION; $i > 0; --$i) {
for ($i = Application::getMajorVersion(); $i > 0; --$i) {
if (1 === Preg::match('/Changelog for v('.$i.'.\d+.\d+)/', $changelog, $matches)) {
$version = $matches[1];

Expand Down Expand Up @@ -440,6 +441,7 @@ private static function getFixersHelp()
{
$help = '';
$fixerFactory = new FixerFactory();
/** @var AbstractFixer[] $fixers */
$fixers = $fixerFactory->registerBuiltInFixers()->getFixers();

// sort fixers by name
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ private function validateRules(array $rules)
if (isset($rules[$fixerName]) && $fixer instanceof DeprecatedFixerInterface) {
$successors = $fixer->getSuccessorsNames();
$messageEnd = [] === $successors
? sprintf(' and will be removed in version %d.0.', (int) Application::VERSION + 1)
? sprintf(' and will be removed in version %d.0.', Application::getMajorVersion())
: sprintf('. Use %s instead.', str_replace('`', '"', Utils::naturalLanguageJoinWithBackticks($successors)));

$message = "Rule \"{$fixerName}\" is deprecated{$messageEnd}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ private function getLastNonDefaultArgumentIndex(Tokens $tokens, $startIndex, $en
return $i;
}
}

return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
final class PhpdocToReturnTypeFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
{
/**
* @var array<array<int, string>>
* @var array<int, array<int, int|string>>
*/
private $blacklistFuncNames = [
[T_STRING, '__construct'],
Expand Down
1 change: 1 addition & 0 deletions src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private function storeImports(Tokens $tokens, $startIndex, $endIndex)
$tokensAnalyzer = new TokensAnalyzer($tokens);
$this->imports = [];

/** @var int $index */
foreach ($tokensAnalyzer->getImportUseIndexes() as $index) {
if ($index < $startIndex || $index > $endIndex) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/PhpUnit/PhpUnitSizeClassFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private function getSingleLineDocBlockEntry($line)
}

/**
* @return Annotation[]
* @return Annotation[][]
*/
private function filterDocBlock(DocBlock $doc)
{
Expand Down
7 changes: 4 additions & 3 deletions tests/AutoReview/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,12 @@ public function testProvideFixersPriorityCasesAreSorted()

usort(
$sorted,
/**
* @param array<FixerInterface> $priorityPair1
* @param array<FixerInterface> $priorityPair2
*/
static function (array $priorityPair1, array $priorityPair2) {
/** @var FixerInterface $fixer */
$fixer1 = $priorityPair1[0];

/** @var FixerInterface $fixer */
$fixer2 = $priorityPair2[0];

if ($fixer1->getName() === $fixer2->getName()) {
Expand Down
9 changes: 4 additions & 5 deletions tests/AutoReview/FixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

namespace PhpCsFixer\Tests\AutoReview;

use PhpCsFixer\AbstractFixer;
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
use PhpCsFixer\Fixer\DefinedFixerInterface;
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\Fixer\Whitespace\SingleBlankLineAtEofFixer;
Expand Down Expand Up @@ -50,11 +50,10 @@ final class FixerTest extends TestCase
/**
* @dataProvider provideFixerDefinitionsCases
*/
public function testFixerDefinitions(FixerInterface $fixer)
public function testFixerDefinitions(AbstractFixer $fixer)
{
static::assertInstanceOf(\PhpCsFixer\Fixer\DefinedFixerInterface::class, $fixer);

/** @var DefinedFixerInterface $fixer */
$fixerName = $fixer->getName();
$definition = $fixer->getDefinition();
$fixerIsConfigurable = $fixer instanceof ConfigurationDefinitionFixerInterface;
Expand Down Expand Up @@ -185,7 +184,7 @@ public function testFixerDefinitions(FixerInterface $fixer)
* @expectedDeprecation PhpCsFixer\FixerDefinition\FixerDefinition::getConfigurationDescription is deprecated and will be removed in 3.0.
* @expectedDeprecation PhpCsFixer\FixerDefinition\FixerDefinition::getDefaultConfiguration is deprecated and will be removed in 3.0.
*/
public function testLegacyFixerDefinitions(FixerInterface $fixer)
public function testLegacyFixerDefinitions(AbstractFixer $fixer)
{
$definition = $fixer->getDefinition();

Expand Down Expand Up @@ -217,7 +216,7 @@ public function testFixersAreDefined(FixerInterface $fixer)
/**
* @dataProvider provideFixerDefinitionsCases
*/
public function testDeprecatedFixersHaveCorrectSummary(FixerInterface $fixer)
public function testDeprecatedFixersHaveCorrectSummary(AbstractFixer $fixer)
{
$reflection = new \ReflectionClass($fixer);
$comment = $reflection->getDocComment();
Expand Down
2 changes: 1 addition & 1 deletion tests/AutoReview/TravisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private function getMaxPhpVersionFromEntryFile()
throw new \LogicException("Can't find version - perhaps entry file was modified?");
}

$phpVerId = end($sequence)->getContent();
$phpVerId = (int) end($sequence)->getContent();

return $this->convertPhpVerIdToNiceVer((string) ($phpVerId - 100));
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Console/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public function testApplication()
$app = new Application();
static::assertStringMatchesFormat('%s by <comment>Fabien Potencier</comment> and <comment>Dariusz Ruminski</comment>', $app->getLongVersion());
}

public function testGetMajorVersion()
{
static::assertSame(2, Application::getMajorVersion());
}
}
2 changes: 1 addition & 1 deletion tests/Console/Command/SelfUpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
final class SelfUpdateCommandTest extends TestCase
{
/**
* @var vfsStreamDirectory
* @var null|vfsStreamDirectory
*/
private $root;

Expand Down
6 changes: 3 additions & 3 deletions tests/Fixer/ControlStructure/NoUselessElseFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ public function provideConditionsWithoutBracesCases()
}

/**
* @param string $input
* @param string<int, bool> $indexes
* @param string $input
* @param array<int, bool> $indexes
*
* @dataProvider provideIsInConditionWithoutBracesCases
*/
Expand Down Expand Up @@ -959,7 +959,7 @@ public function provideIsInConditionWithoutBracesCases()
* @param string $expected
* @param null|string $input
*
* @return array<string, string>
* @return array<array<string>>
*/
private function generateCases($expected, $input = null)
{
Expand Down
6 changes: 6 additions & 0 deletions tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\Tests\Fixer\FunctionNotation;

use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\WhitespacesFixerConfig;
Expand All @@ -25,6 +26,11 @@
*/
final class MethodArgumentSpaceFixerTest extends AbstractFixerTestCase
{
/**
* @var MethodArgumentSpaceFixer
*/
protected $fixer;

/**
* @param string $expected
* @param null|string $input
Expand Down
1 change: 0 additions & 1 deletion tests/Fixer/PhpUnit/PhpUnitTestAnnotationFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,6 @@ public function test_() {}
*
* @param string $expected
* @param null|string $input
* @param null|array $config
*/
public function testFixLegacyCaseOption($expected, $input = null, array $config = [])
{
Expand Down
5 changes: 0 additions & 5 deletions tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ public function AB($self)
$this->doTest($expected, $input);
}

/**
* Expected after fixing, return type to fix.
*
* @return array<array<string, string>
*/
public function provideGeneratedFixCases()
{
return [
Expand Down
6 changes: 2 additions & 4 deletions tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public function testLegacyConfigNull()
}

/**
* @param int[] $lineNumberRemoved Line numbers expected to be removed after fixing
* @param null|string[] $config
* @param int[] $lineNumberRemoved Line numbers expected to be removed after fixing
*
* @group legacy
* @dataProvider provideWithConfigCases
Expand All @@ -116,8 +115,7 @@ public function testLegacyWithConfig(array $lineNumberRemoved, array $config)
}

/**
* @param int[] $lineNumberRemoved Line numbers expected to be removed after fixing
* @param null|string[] $config
* @param int[] $lineNumberRemoved Line numbers expected to be removed after fixing
*
* @dataProvider provideWithConfigCases
*/
Expand Down
2 changes: 0 additions & 2 deletions tests/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace PhpCsFixer\Tests;

use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet;
use PhpCsFixer\WhitespacesFixerConfig;
Expand Down Expand Up @@ -343,7 +342,6 @@ public function testConfigurableFixerIsConfigured()

private function createFixerDouble($name, $priority = 0)
{
/** @var FixerInterface $fixer */
$fixer = $this->prophesize(\PhpCsFixer\Fixer\FixerInterface::class);
$fixer->getName()->willReturn($name);
$fixer->getPriority()->willReturn($priority);
Expand Down
4 changes: 2 additions & 2 deletions tests/Indicator/PhpUnitTestCaseIndicatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public function testThrowsExceptionIfNotClass()
}

/**
* @param array<[int, int]> $expectedIndexes
* @param string $code
* @param array<int,int> $expectedIndexes
* @param string $code
*
* @dataProvider provideFindPhpUnitClassesCases
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/PregTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function providePatternValidationCases()
/**
* @dataProvider providePatternValidationCases
*
* @param $pattern
* @param string $pattern
* @param null|int $expected
* @param null|string $expectedException
* @param null|string $expectedMessage
Expand Down
2 changes: 1 addition & 1 deletion tests/Report/AbstractReporterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
abstract class AbstractReporterTestCase extends TestCase
{
/**
* @var ReporterInterface
* @var null|ReporterInterface
*/
protected $reporter;

Expand Down
Loading

0 comments on commit aa8e45f

Please sign in to comment.