Skip to content

Commit ee2499e

Browse files
kukulichondrejmirtes
authored andcommitted
CS: Use everything
1 parent 1c2e4bd commit ee2499e

1,002 files changed

Lines changed: 6806 additions & 3437 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build-cs/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"require-dev": {
33
"consistence-community/coding-standard": "^3.11.0",
44
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
5-
"slevomat/coding-standard": "^7.0.16",
5+
"slevomat/coding-standard": "^7.0.18",
66
"squizlabs/php_codesniffer": "^3.5.3"
77
}
88
}

build-cs/composer.lock

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

compiler/src/Console/CompileCommand.php

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22

33
namespace PHPStan\Compiler\Console;
44

5+
use Exception;
56
use PHPStan\Compiler\Filesystem\Filesystem;
67
use PHPStan\Compiler\Process\ProcessFactory;
8+
use PHPStan\ShouldNotHappenException;
79
use Symfony\Component\Console\Command\Command;
810
use Symfony\Component\Console\Input\InputInterface;
911
use Symfony\Component\Console\Output\OutputInterface;
12+
use Symfony\Component\Finder\Finder;
13+
use function basename;
14+
use function dirname;
1015
use function escapeshellarg;
16+
use function exec;
17+
use function file_get_contents;
18+
use function file_put_contents;
19+
use function implode;
20+
use function is_dir;
21+
use function json_decode;
22+
use function json_encode;
23+
use function realpath;
24+
use function rename;
25+
use function sprintf;
26+
use function str_replace;
27+
use function strlen;
28+
use function substr;
29+
use function unlink;
30+
use function var_export;
31+
use const JSON_PRETTY_PRINT;
32+
use const JSON_UNESCAPED_SLASHES;
1133

1234
final class CompileCommand extends Command
1335
{
@@ -74,7 +96,7 @@ private function fixComposerJson(string $buildDir): void
7496

7597
$encodedJson = json_encode($json, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
7698
if ($encodedJson === false) {
77-
throw new \Exception('json_encode() was not successful.');
99+
throw new Exception('json_encode() was not successful.');
78100
}
79101

80102
$this->filesystem->write($buildDir . '/composer.json', $encodedJson);
@@ -87,10 +109,10 @@ private function renamePhpStormStubs(): void
87109
return;
88110
}
89111

90-
$stubFinder = \Symfony\Component\Finder\Finder::create();
112+
$stubFinder = Finder::create();
91113
$stubsMapPath = realpath($directory . '/PhpStormStubsMap.php');
92114
if ($stubsMapPath === false) {
93-
throw new \Exception('realpath() failed');
115+
throw new Exception('realpath() failed');
94116
}
95117
foreach ($stubFinder->files()->name('*.php')->in($directory) as $stubFile) {
96118
$path = $stubFile->getPathname();
@@ -103,20 +125,20 @@ private function renamePhpStormStubs(): void
103125
dirname($path) . '/' . $stubFile->getBasename('.php') . '.stub'
104126
);
105127
if ($renameSuccess === false) {
106-
throw new \PHPStan\ShouldNotHappenException(sprintf('Could not rename %s', $path));
128+
throw new ShouldNotHappenException(sprintf('Could not rename %s', $path));
107129
}
108130
}
109131

110132
$stubsMapContents = file_get_contents($stubsMapPath);
111133
if ($stubsMapContents === false) {
112-
throw new \PHPStan\ShouldNotHappenException(sprintf('Could not read %s', $stubsMapPath));
134+
throw new ShouldNotHappenException(sprintf('Could not read %s', $stubsMapPath));
113135
}
114136

115137
$stubsMapContents = str_replace('.php\',', '.stub\',', $stubsMapContents);
116138

117139
$putSuccess = file_put_contents($stubsMapPath, $stubsMapContents);
118140
if ($putSuccess === false) {
119-
throw new \PHPStan\ShouldNotHappenException(sprintf('Could not write %s', $stubsMapPath));
141+
throw new ShouldNotHappenException(sprintf('Could not write %s', $stubsMapPath));
120142
}
121143
}
122144

@@ -127,7 +149,7 @@ private function renamePhp8Stubs(): void
127149
return;
128150
}
129151

130-
$stubFinder = \Symfony\Component\Finder\Finder::create();
152+
$stubFinder = Finder::create();
131153
$stubsMapPath = $directory . '/../Php8StubsMap.php';
132154
foreach ($stubFinder->files()->name('*.php')->in($directory) as $stubFile) {
133155
$path = $stubFile->getPathname();
@@ -140,26 +162,26 @@ private function renamePhp8Stubs(): void
140162
dirname($path) . '/' . $stubFile->getBasename('.php') . '.stub'
141163
);
142164
if ($renameSuccess === false) {
143-
throw new \PHPStan\ShouldNotHappenException(sprintf('Could not rename %s', $path));
165+
throw new ShouldNotHappenException(sprintf('Could not rename %s', $path));
144166
}
145167
}
146168

147169
$stubsMapContents = file_get_contents($stubsMapPath);
148170
if ($stubsMapContents === false) {
149-
throw new \PHPStan\ShouldNotHappenException(sprintf('Could not read %s', $stubsMapPath));
171+
throw new ShouldNotHappenException(sprintf('Could not read %s', $stubsMapPath));
150172
}
151173

152174
$stubsMapContents = str_replace('.php\',', '.stub\',', $stubsMapContents);
153175

154176
$putSuccess = file_put_contents($stubsMapPath, $stubsMapContents);
155177
if ($putSuccess === false) {
156-
throw new \PHPStan\ShouldNotHappenException(sprintf('Could not write %s', $stubsMapPath));
178+
throw new ShouldNotHappenException(sprintf('Could not write %s', $stubsMapPath));
157179
}
158180
}
159181

160182
private function patchPhpStormStubs(OutputInterface $output): void
161183
{
162-
$stubFinder = \Symfony\Component\Finder\Finder::create();
184+
$stubFinder = Finder::create();
163185
$stubsDirectory = __DIR__ . '/../../../vendor/jetbrains/phpstorm-stubs';
164186
foreach ($stubFinder->files()->name('*.patch')->in(__DIR__ . '/../../patches/stubs') as $patchFile) {
165187
$absolutePatchPath = $patchFile->getPathname();
@@ -186,7 +208,7 @@ private function buildPreloadScript(): void
186208
187209
%s
188210
php;
189-
$finder = \Symfony\Component\Finder\Finder::create();
211+
$finder = Finder::create();
190212
$root = realpath(__DIR__ . '/../../..');
191213
if ($root === false) {
192214
return;
@@ -243,7 +265,7 @@ private function transformSource(): void
243265
return;
244266
}
245267

246-
throw new \PHPStan\ShouldNotHappenException(implode("\n", $outputLines));
268+
throw new ShouldNotHappenException(implode("\n", $outputLines));
247269
}
248270

249271
}

compiler/src/Filesystem/SymfonyFilesystem.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace PHPStan\Compiler\Filesystem;
44

5+
use RuntimeException;
6+
use function file_get_contents;
7+
use function file_put_contents;
8+
59
final class SymfonyFilesystem implements Filesystem
610
{
711

@@ -32,7 +36,7 @@ public function read(string $file): string
3236
{
3337
$content = file_get_contents($file);
3438
if ($content === false) {
35-
throw new \RuntimeException();
39+
throw new RuntimeException();
3640
}
3741
return $content;
3842
}

phpcs.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidFormat"/>
1717
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable"/>
1818
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
19-
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
19+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions"/>
2020
<exclude name="Consistence.Exceptions.ExceptionDeclaration"/>
2121
<exclude name="Squiz.Commenting.FunctionComment"/>
2222
<exclude name="Squiz.PHP.Heredoc.NotAllowed"/>
@@ -25,6 +25,7 @@
2525
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
2626
<properties>
2727
<property name="caseSensitive" value="false"/>
28+
<property name="psr12Compatible" value="true"/>
2829
</properties>
2930
</rule>
3031
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
@@ -84,7 +85,21 @@
8485
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
8586
<!--<rule ref="SlevomatCodingStandard.Functions.UnusedParameter"/>-->
8687
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
88+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
89+
<properties>
90+
<property name="searchAnnotations" value="true"/>
91+
<property name="namespacesRequiredToUse" value=""/>
92+
<property name="allowPartialUses" value="true"/>
93+
<property name="allowFallbackGlobalFunctions" value="false"/>
94+
<property name="allowFallbackGlobalConstants" value="false"/>
95+
<property name="allowFullyQualifiedExceptions" value="false"/>
96+
<property name="allowFullyQualifiedNameForCollidingClasses" value="true"/>
97+
<property name="allowFullyQualifiedNameForCollidingFunctions" value="true"/>
98+
<property name="allowFullyQualifiedNameForCollidingConstants" value="true"/>
99+
</properties>
100+
</rule>
87101
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
102+
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing"/>
88103
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
89104
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/>
90105
<rule ref="Squiz.WhiteSpace.FunctionSpacing">

src/AnalysedCodeException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan;
44

5-
abstract class AnalysedCodeException extends \Exception
5+
use Exception;
6+
7+
abstract class AnalysedCodeException extends Exception
68
{
79

810
abstract public function getTip(): ?string;

src/Analyser/Analyser.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@
22

33
namespace PHPStan\Analyser;
44

5+
use Closure;
56
use PHPStan\Rules\Registry;
7+
use Throwable;
8+
use function array_fill_keys;
9+
use function array_merge;
10+
use function count;
11+
use function error_reporting;
12+
use function in_array;
13+
use function restore_error_handler;
14+
use function set_error_handler;
15+
use function sprintf;
16+
use const E_DEPRECATED;
617

718
class Analyser
819
{
920

10-
private \PHPStan\Analyser\FileAnalyser $fileAnalyser;
21+
private FileAnalyser $fileAnalyser;
1122

1223
private Registry $registry;
1324

14-
private \PHPStan\Analyser\NodeScopeResolver $nodeScopeResolver;
25+
private NodeScopeResolver $nodeScopeResolver;
1526

1627
private int $internalErrorsCountLimit;
1728

18-
/** @var \PHPStan\Analyser\Error[] */
29+
/** @var Error[] */
1930
private array $collectedErrors = [];
2031

2132
public function __construct(
@@ -33,14 +44,14 @@ public function __construct(
3344

3445
/**
3546
* @param string[] $files
36-
* @param \Closure(string $file): void|null $preFileCallback
37-
* @param \Closure(int): void|null $postFileCallback
47+
* @param Closure(string $file): void|null $preFileCallback
48+
* @param Closure(int ): void|null $postFileCallback
3849
* @param string[]|null $allAnalysedFiles
3950
*/
4051
public function analyse(
4152
array $files,
42-
?\Closure $preFileCallback = null,
43-
?\Closure $postFileCallback = null,
53+
?Closure $preFileCallback = null,
54+
?Closure $postFileCallback = null,
4455
bool $debug = false,
4556
?array $allAnalysedFiles = null
4657
): AnalyserResult
@@ -78,7 +89,7 @@ public function analyse(
7889
if (count($fileExportedNodes) > 0) {
7990
$exportedNodes[$file] = $fileExportedNodes;
8091
}
81-
} catch (\Throwable $t) {
92+
} catch (Throwable $t) {
8293
if ($debug) {
8394
throw $t;
8495
}

src/Analyser/AnalyserResult.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace PHPStan\Analyser;
44

55
use PHPStan\Dependency\ExportedNode;
6+
use function usort;
67

78
class AnalyserResult
89
{
910

10-
/** @var \PHPStan\Analyser\Error[] */
11+
/** @var Error[] */
1112
private array $unorderedErrors;
1213

13-
/** @var \PHPStan\Analyser\Error[] */
14+
/** @var Error[] */
1415
private array $errors;
1516

1617
/** @var string[] */
@@ -25,7 +26,7 @@ class AnalyserResult
2526
private bool $reachedInternalErrorsCountLimit;
2627

2728
/**
28-
* @param \PHPStan\Analyser\Error[] $errors
29+
* @param Error[] $errors
2930
* @param string[] $internalErrors
3031
* @param array<string, array<string>>|null $dependencies
3132
* @param array<string, array<ExportedNode>> $exportedNodes
@@ -63,15 +64,15 @@ static function (Error $a, Error $b): int {
6364
}
6465

6566
/**
66-
* @return \PHPStan\Analyser\Error[]
67+
* @return Error[]
6768
*/
6869
public function getUnorderedErrors(): array
6970
{
7071
return $this->unorderedErrors;
7172
}
7273

7374
/**
74-
* @return \PHPStan\Analyser\Error[]
75+
* @return Error[]
7576
*/
7677
public function getErrors(): array
7778
{

0 commit comments

Comments
 (0)