Skip to content

Commit b87922d

Browse files
committed
MC-29289: Adjusting PHPStan configuration based on Magento codebase analysis
- Updated to 0.12.2 version
1 parent 38bf760 commit b87922d

File tree

8 files changed

+231
-993
lines changed

8 files changed

+231
-993
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"pdepend/pdepend": "2.5.2",
9393
"phpcompatibility/php-compatibility": "^9.3",
9494
"phpmd/phpmd": "@stable",
95-
"phpstan/phpstan": "^0.11.19",
95+
"phpstan/phpstan": "^0.12.2",
9696
"phpunit/phpunit": "~6.5.0",
9797
"sebastian/phpcpd": "~3.0.0",
9898
"squizlabs/php_codesniffer": "~3.4.0"

composer.lock

Lines changed: 212 additions & 923 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/static/framework/Magento/PhpStan/Formatters/FilteredErrorFormatter.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
use PHPStan\Command\AnalysisResult;
1111
use PHPStan\Command\ErrorFormatter\TableErrorFormatter;
12-
use PHPStan\File\RelativePathHelper;
13-
use Symfony\Component\Console\Style\OutputStyle;
12+
use PHPStan\Command\Output;
1413

1514
/**
1615
* To mute the PHPStan error message add a comment above the reported error line.
@@ -47,10 +46,11 @@ class FilteredErrorFormatter extends TableErrorFormatter
4746
/**
4847
* @inheritdoc
4948
*/
50-
public function formatErrors(AnalysisResult $analysisResult, OutputStyle $outputStyle): int
49+
public function formatErrors(AnalysisResult $analysisResult, Output $output): int
5150
{
5251
if (!$analysisResult->hasErrors()) {
53-
$outputStyle->success('No errors');
52+
$style = $output->getStyle();
53+
$style->success('No errors');
5454
return self::NO_ERRORS;
5555
}
5656

@@ -62,12 +62,11 @@ public function formatErrors(AnalysisResult $analysisResult, OutputStyle $output
6262
$fileSpecificErrorsWithoutIgnoredErrors,
6363
$analysisResult->getNotFileSpecificErrors(),
6464
$analysisResult->isDefaultLevelUsed(),
65-
$analysisResult->getCurrentDirectory(),
6665
$analysisResult->hasInferrablePropertyTypesFromConstructor(),
6766
$analysisResult->getProjectConfigFile()
6867
);
6968

70-
return parent::formatErrors($clearedAnalysisResult, $outputStyle);
69+
return parent::formatErrors($clearedAnalysisResult, $output);
7170
}
7271

7372
/**

dev/tests/static/framework/Magento/PhpStan/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
if (!defined('TESTS_TEMP_DIR')) {
1818
//phpcs:ignore Magento2.Functions.DiscouragedFunction
19-
define('TESTS_TEMP_DIR', dirname(__DIR__) . '../../tmp');
19+
define('TESTS_TEMP_DIR', dirname(__DIR__) . '/../../tmp');
2020
}
2121

2222
$generatorIo = new Io(

dev/tests/static/framework/tests/unit/testsuite/Magento/PhpStan/Formatters/FilteredErrorFormatterTest.php

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,16 @@
99

1010
use PHPStan\Analyser\Error;
1111
use PHPStan\Command\AnalysisResult;
12-
use PHPStan\Command\ErrorsConsoleStyle;
1312
use PHPStan\File\FuzzyRelativePathHelper;
1413
use PHPStan\ShouldNotHappenException;
15-
use Symfony\Component\Console\Input\StringInput;
16-
use Symfony\Component\Console\Output\StreamOutput;
14+
use PHPStan\Testing\ErrorFormatterTestCase;
1715

1816
/**
1917
* Tests filter error formatter.
2018
*/
21-
class FilteredErrorFormatterTest extends \PHPUnit\Framework\TestCase
19+
class FilteredErrorFormatterTest extends ErrorFormatterTestCase
2220
{
23-
private const DIRECTORY_PATH = __DIR__ . '/Fixtures';
24-
25-
/** @var StreamOutput */
26-
private $outputStream;
27-
28-
/** @var ErrorsConsoleStyle */
29-
private $errorConsoleStyle;
30-
31-
/**
32-
* @throws ShouldNotHappenException
33-
*/
34-
protected function setUp(): void
35-
{
36-
$resource = fopen('php://memory', 'w', false);
37-
if ($resource === false) {
38-
throw new ShouldNotHappenException();
39-
}
40-
$this->outputStream = new StreamOutput($resource);
41-
$this->errorConsoleStyle = new ErrorsConsoleStyle(new StringInput(''), $this->outputStream);
42-
}
21+
protected const DIRECTORY_PATH = __DIR__ . '/Fixtures';
4322

4423
/**
4524
* Tests errors filtering.
@@ -62,14 +41,14 @@ public function testFormatErrors(
6241
new FuzzyRelativePathHelper(self::DIRECTORY_PATH, '/', []),
6342
false,
6443
false,
65-
false
44+
false,
45+
true
6646
);
6747

6848
$analysisResult = new AnalysisResult(
6949
$fileErrors,
7050
[],
7151
false,
72-
self::DIRECTORY_PATH,
7352
false,
7453
null
7554
);
@@ -78,7 +57,7 @@ public function testFormatErrors(
7857
$exitCode,
7958
$formatter->formatErrors(
8059
$analysisResult,
81-
$this->errorConsoleStyle
60+
$this->getOutput()
8261
),
8362
sprintf('%s: response code do not match', $message)
8463
);
@@ -161,35 +140,4 @@ public function dataFormatterOutputProvider(): array
161140
]
162141
];
163142
}
164-
165-
/**
166-
* @return string
167-
* @throws ShouldNotHappenException
168-
*/
169-
private function getOutputContent(): string
170-
{
171-
rewind($this->outputStream->getStream());
172-
$contents = stream_get_contents($this->outputStream->getStream());
173-
if ($contents === false) {
174-
throw new ShouldNotHappenException();
175-
}
176-
177-
return $this->rtrimMultiline($contents);
178-
}
179-
180-
/**
181-
* @param string $output
182-
* @return string
183-
*/
184-
private function rtrimMultiline(string $output): string
185-
{
186-
$result = array_map(
187-
function (string $line): string {
188-
return rtrim($line, " \r\n");
189-
},
190-
explode("\n", $output)
191-
);
192-
193-
return implode("\n", $result);
194-
}
195143
}

dev/tests/static/framework/tmp/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
parameters:
2-
featureToggles:
3-
missingReturnRule: true
2+
checkExplicitMixedMissingReturn: true
43
checkPhpDocMissingReturn: true
54
reportUnmatchedIgnoredErrors: false
65
excludes_analyse:
@@ -9,6 +8,7 @@ parameters:
98
- %rootDir%/../../../dev/tests/functional/*
109
- %rootDir%/../../../dev/tests/*/Fixtures/*
1110
- %rootDir%/../../../dev/tests/*/tmp/*
11+
- %rootDir%/../../../dev/tests/*/_generated/*
1212
- %rootDir%/../../../pub/*
1313
autoload_directories:
1414
- %rootDir%/../../../dev/tests/static/framework/tests/unit/testsuite/Magento
@@ -35,3 +35,4 @@ services:
3535
showTipsOfTheDay: false
3636
checkThisOnly: false
3737
inferPrivatePropertyTypeFromConstructor: true
38+
checkMissingTypehints: %checkMissingTypehints%

lib/internal/Magento/Framework/TestFramework/Unit/Autoloader/FactoryGenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public function generate($className)
4343
*/
4444
private function isFactory($className)
4545
{
46+
if (!preg_match('/[\\\A-Z]/', substr(ltrim($className), 0, 1))) {
47+
return false;
48+
}
4649
$sourceName = rtrim(substr($className, 0, -strlen('Factory')), '\\');
4750
return $sourceName . 'Factory' == $className;
4851
}

0 commit comments

Comments
 (0)