Skip to content

Commit 89af4e7

Browse files
committed
Require non-capturing catch
1 parent f8c1bef commit 89af4e7

37 files changed

+67
-57
lines changed

build/rector-downgrade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Rector\DowngradePhp74\Rector\Coalesce\DowngradeNullCoalescingOperatorRector;
77
use Rector\DowngradePhp74\Rector\ArrowFunction\ArrowFunctionToAnonymousFunctionRector;
88
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector;
9+
use Rector\DowngradePhp80\Rector\Catch_\DowngradeNonCapturingCatchesRector;
910
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeTrailingCommasInParamUseRector;
1011
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1112

@@ -36,6 +37,7 @@
3637

3738
if ($targetPhpVersionId < 80000) {
3839
$services->set(DowngradeTrailingCommasInParamUseRector::class);
40+
$services->set(DowngradeNonCapturingCatchesRector::class);
3941
}
4042

4143
if ($targetPhpVersionId < 70400) {

phpcs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@
152152
<property name="enable" value="true"/>
153153
</properties>
154154
</rule>
155+
<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch">
156+
<properties>
157+
<property name="enable" value="true"/>
158+
</properties>
159+
</rule>
155160
<exclude-pattern>tests/*/data</exclude-pattern>
156161
<exclude-pattern>tests/e2e/resultCache_1.php</exclude-pattern>
157162
<exclude-pattern>tests/e2e/resultCache_2.php</exclude-pattern>

src/Analyser/FileAnalyser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ public function analyseFile(
199199
if ($dependencies->getExportedNode() !== null) {
200200
$exportedNodes[] = $dependencies->getExportedNode();
201201
}
202-
} catch (AnalysedCodeException $e) {
202+
} catch (AnalysedCodeException) {
203203
// pass
204-
} catch (IdentifierNotFound $e) {
204+
} catch (IdentifierNotFound) {
205205
// pass
206-
} catch (UnableToCompileNode | NotAClassReflection | NotAnInterfaceReflection $e) {
206+
} catch (UnableToCompileNode | NotAClassReflection | NotAnInterfaceReflection) {
207207
// pass
208208
}
209209
};

src/Analyser/MutatingScope.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,7 +3866,7 @@ public function invalidateExpression(Expr $expressionToInvalidate, bool $require
38663866

38673867
try {
38683868
$expr = $this->parser->parseString('<?php ' . $exprString . ';')[0];
3869-
} catch (ParserErrorsException $e) {
3869+
} catch (ParserErrorsException) {
38703870
continue;
38713871
}
38723872
if (!$expr instanceof Node\Stmt\Expression) {
@@ -3928,7 +3928,7 @@ public function invalidateMethodsOnExpression(Expr $expressionToInvalidate): sel
39283928

39293929
try {
39303930
$expr = $this->parser->parseString('<?php ' . $exprString . ';')[0];
3931-
} catch (ParserErrorsException $e) {
3931+
} catch (ParserErrorsException) {
39323932
continue;
39333933
}
39343934
if (!$expr instanceof Node\Stmt\Expression) {

src/Analyser/ResultCache/ResultCacheManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ private function getPhpStanVersion(): string
808808
{
809809
try {
810810
return PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion();
811-
} catch (OutOfBoundsException $e) {
811+
} catch (OutOfBoundsException) {
812812
return 'Version unknown';
813813
}
814814
}

src/Command/AnalyseCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
191191
} elseif ($ci->getCiName() === CiDetector::CI_TEAMCITY) {
192192
$errorFormat = 'teamcity';
193193
}
194-
} catch (CiNotDetectedException $e) {
194+
} catch (CiNotDetectedException) {
195195
// pass
196196
}
197197
}

src/Command/ClearResultCacheCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6565
false,
6666
false,
6767
);
68-
} catch (InceptionNotSuccessfulException $e) {
68+
} catch (InceptionNotSuccessfulException) {
6969
return 1;
7070
}
7171

src/Command/CommandHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public static function begin(
324324
$memoryLimitFileContents = FileReader::read($memoryLimitFile);
325325
$errorOutput->writeLineFormatted(sprintf('It consumed around %s of memory.', $memoryLimitFileContents));
326326
$errorOutput->writeLineFormatted('');
327-
} catch (CouldNotReadFileException $e) {
327+
} catch (CouldNotReadFileException) {
328328
// pass
329329
}
330330

src/Command/FixerApplication.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function log(string $message): void
268268

269269
try {
270270
$fixerProcess = $this->getFixerProcess($output, $serverPort);
271-
} catch (FixerProcessException $e) {
271+
} catch (FixerProcessException) {
272272
return 1;
273273
}
274274

@@ -318,7 +318,7 @@ private function getFixerProcess(OutputInterface $output, int $serverPort): Proc
318318

319319
try {
320320
$phar = new Phar($pharPath);
321-
} catch (Throwable $e) {
321+
} catch (Throwable) {
322322
@unlink($pharPath);
323323
@unlink($infoPath);
324324
$output->writeln('<fg=red>PHPStan Pro PHAR signature is corrupted.</>');
@@ -407,8 +407,11 @@ private function downloadPhar(
407407
),
408408
);
409409

410-
/** @var array{url: string, version: string} $latestInfo */
411-
$latestInfo = Json::decode((string) await($client->get('https://fixer-download-api.phpstan.com/latest'), $loop, 5.0)->getBody(), Json::FORCE_ARRAY); // @phpstan-ignore-line
410+
/**
411+
* @var array{url: string, version: string} $latestInfo
412+
* @phpstan-ignore-next-line
413+
*/
414+
$latestInfo = Json::decode((string) await($client->get('https://fixer-download-api.phpstan.com/latest'), $loop, 5.0)->getBody(), Json::FORCE_ARRAY);
412415
if ($currentVersion !== null && $latestInfo['version'] === $currentVersion) {
413416
$this->writeInfoFile($infoPath, $latestInfo['version']);
414417
$output->writeln('<fg=green>You\'re running the latest PHPStan Pro!</>');
@@ -586,7 +589,7 @@ private function getPhpstanVersion(): string
586589
{
587590
try {
588591
return PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion();
589-
} catch (OutOfBoundsException $e) {
592+
} catch (OutOfBoundsException) {
590593
return 'Version unknown';
591594
}
592595
}
@@ -601,7 +604,7 @@ private function isDockerRunning(): bool
601604
$contents = FileReader::read('/proc/1/cgroup');
602605

603606
return strpos($contents, 'docker') !== false;
604-
} catch (CouldNotReadFileException $e) {
607+
} catch (CouldNotReadFileException) {
605608
return false;
606609
}
607610
}

src/Command/FixerWorkerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
122122
$insteadOfFile,
123123
false,
124124
);
125-
} catch (InceptionNotSuccessfulException $e) {
125+
} catch (InceptionNotSuccessfulException) {
126126
return 1;
127127
}
128128

0 commit comments

Comments
 (0)