Skip to content

Commit 83c8ea1

Browse files
committed
Increase PHPStan level to 3
1 parent ed34dde commit 83c8ea1

35 files changed

+91
-57
lines changed

dev-tools/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
},
55
"require-dev": {
66
"humbug/box": "^3.8",
7+
"jangregor/phpstan-prophecy": "^0.6",
78
"localheinz/composer-normalize": "^1.1",
89
"mi-schi/phpmd-extension": "^4.3",
910
"phpmd/phpmd": "^2.6",
10-
"phpstan/phpstan-phpunit": "^0.11.2"
11+
"phpstan/phpstan-phpunit": "^0.12"
1112
},
1213
"conflict": {
1314
"hhvm": "*"

dev-tools/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ composer info -D | sort
5656

5757
echo λλλ phive packages
5858

59-
./bin/phive install --trust-gpg-keys D2CCAC42F6295E7D,8E730BA25823D8B5
59+
./bin/phive install --trust-gpg-keys D2CCAC42F6295E7D,8E730BA25823D8B5,CF1A108D0E7AE720

dev-tools/phive.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
33
<phar name="composer-require-checker" version="^2.0" installed="2.0.0" location="./tools/composer-require-checker" copy="false"/>
4-
<phar name="phpstan" version="^0.11.15" installed="0.11.15" location="./tools/phpstan" copy="false"/>
4+
<phar name="phpstan" version="^0.12" installed="0.12.9" location="./tools/phpstan" copy="true"/>
55
</phive>

phpstan.neon

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
includes:
2+
- dev-tools/vendor/jangregor/phpstan-prophecy/src/extension.neon
23
- dev-tools/vendor/phpstan/phpstan-phpunit/extension.neon
34

45
parameters:
5-
level: 1
6+
level: 3
67
paths:
78
- src
89
- tests
910
excludes_analyse:
1011
- tests/Fixtures
1112
ignoreErrors:
12-
- '/^.+::__construct\(\) does not call parent constructor from SplFileInfo\.$/'
1313
- '/^Return typehint of method PhpCsFixer\\Tests\\Test\\.+::createIsIdenticalStringConstraint\(\) has invalid type PHPUnit_Framework_Constraint_IsIdentical\.$/'
1414
- '/^Class (Symfony\\Contracts\\EventDispatcher\\Event|Symfony\\Component\\EventDispatcher\\Event) not found.$/'
15+
- '/^(Access|Call) to an undefined (property|method) PhpCsFixer\\AccessibleObject\\AccessibleObject::.+$/'
16+
-
17+
message: '/^Unsafe usage of new static\(\)\.$/'
18+
path: src/Config.php

src/AbstractFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function configure(array $configuration = null)
140140
'Option "%s" for rule "%s" is deprecated and will be removed in version %d.0. %s',
141141
$name,
142142
$this->getName(),
143-
(int) Application::VERSION + 1,
143+
Application::getMajorVersion() + 1,
144144
str_replace('`', '"', $option->getDeprecationMessage())
145145
);
146146

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getCustomFixers()
6464
}
6565

6666
/**
67-
* {@inheritdoc}
67+
* @return Finder
6868
*/
6969
public function getFinder()
7070
{

src/Console/Application.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ public function __construct()
6363
));
6464
}
6565

66+
/**
67+
* @return int
68+
*/
69+
public static function getMajorVersion()
70+
{
71+
return (int) explode('.', self::VERSION)[0];
72+
}
73+
6674
/**
6775
* {@inheritdoc}
6876
*/

src/Console/Command/DescribeCommand.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use PhpCsFixer\FixerDefinition\CodeSampleInterface;
2626
use PhpCsFixer\FixerDefinition\FileSpecificCodeSampleInterface;
2727
use PhpCsFixer\FixerDefinition\FixerDefinition;
28-
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
2928
use PhpCsFixer\FixerDefinition\VersionSpecificCodeSampleInterface;
3029
use PhpCsFixer\FixerFactory;
3130
use PhpCsFixer\Preg;
@@ -330,12 +329,21 @@ private function describeSet(OutputInterface $output, $name)
330329
$help = '';
331330

332331
foreach ($rules as $rule => $config) {
333-
/** @var FixerDefinitionInterface $definition */
334-
$definition = $fixers[$rule]->getDefinition();
332+
$fixer = $fixers[$rule];
333+
334+
if (!$fixer instanceof DefinedFixerInterface) {
335+
throw new \RuntimeException(sprintf(
336+
'Cannot describe rule %s, the fixer does not implement %s',
337+
$rule,
338+
DefinedFixerInterface::class
339+
));
340+
}
341+
342+
$definition = $fixer->getDefinition();
335343
$help .= sprintf(
336344
" * <info>%s</info>%s\n | %s\n%s\n",
337345
$rule,
338-
$fixers[$rule]->isRisky() ? ' <error>risky</error>' : '',
346+
$fixer->isRisky() ? ' <error>risky</error>' : '',
339347
$definition->getSummary(),
340348
true !== $config ? sprintf(" <comment>| Configuration: %s</comment>\n", HelpCommand::toString($config)) : ''
341349
);

src/Console/Command/HelpCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace PhpCsFixer\Console\Command;
1414

15+
use PhpCsFixer\AbstractFixer;
1516
use PhpCsFixer\Console\Application;
1617
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
1718
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
@@ -400,7 +401,7 @@ public static function getLatestReleaseVersionFromChangeLog()
400401
));
401402
}
402403

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

@@ -440,6 +441,7 @@ private static function getFixersHelp()
440441
{
441442
$help = '';
442443
$fixerFactory = new FixerFactory();
444+
/** @var AbstractFixer[] $fixers */
443445
$fixers = $fixerFactory->registerBuiltInFixers()->getFixers();
444446

445447
// sort fixers by name

src/Console/ConfigurationResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ private function validateRules(array $rules)
762762
if (isset($rules[$fixerName]) && $fixer instanceof DeprecatedFixerInterface) {
763763
$successors = $fixer->getSuccessorsNames();
764764
$messageEnd = [] === $successors
765-
? sprintf(' and will be removed in version %d.0.', (int) Application::VERSION + 1)
765+
? sprintf(' and will be removed in version %d.0.', Application::getMajorVersion())
766766
: sprintf('. Use %s instead.', str_replace('`', '"', Utils::naturalLanguageJoinWithBackticks($successors)));
767767

768768
$message = "Rule \"{$fixerName}\" is deprecated{$messageEnd}";

0 commit comments

Comments
 (0)