-
-
Notifications
You must be signed in to change notification settings - Fork 424
[DeadCode] Add RemoveDeadCatchRector rule #6939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
rules-tests/DeadCode/Rector/TryCatch/RemoveDeadCatchRector/Fixture/drop_with_finally.php.inc
Outdated
Show resolved
Hide resolved
rules-tests/DeadCode/Rector/TryCatch/RemoveDeadCatchRector/Fixture/empty_try_and_catch.php.inc
Outdated
Show resolved
Hide resolved
rules-tests/DeadCode/Rector/TryCatch/RemoveDeadCatchRector/Fixture/empty_try_and_catch.php.inc
Show resolved
Hide resolved
|
Okay, let's give it a try, thank you @P3gucka |
|
@P3gucka I tested in this 2) src/Application/FileProcessor.php:10
---------- begin diff ----------
@@ @@
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\ChangesReporting\ValueObjectFactory\ErrorFactory;
use Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory;
-use Rector\Exception\ShouldNotHappenException;
use Rector\FileSystem\FilePathHelper;
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;
use Rector\PhpParser\NodeTraverser\RectorNodeTraverser;
@@ @@
} catch (ParserErrorsException) {
$this->parseFileNodes($file, false);
}
- } catch (ShouldNotHappenException $shouldNotHappenException) {
- throw $shouldNotHappenException;
} catch (AnalysedCodeException $analysedCodeException) {
// inform about missing classes in tests
if (StaticPHPUnitEnvironment::isPHPUnitRun()) {
throw $analysedCodeException;
}
return $this->errorFactory->createAutoloadError($analysedCodeException, $file->getFilePath());
} catch (Throwable $throwable) {
if ($this->symfonyStyle->isVerbose() || StaticPHPUnitEnvironment::isPHPUnitRun()) {
throw $throwable;
}
----------- end diff -----------
Applied rules:
* RemoveDeadCatchRectorwhich if next catch has handled I will look into it. |
|
Here the code to skip: use Rector\Exception\ShouldNotHappenException;
use Throwable;
class SkipNextThrowableHasSpecialCondition
{
public function run()
{
try {
// some code
} catch (ShouldNotHappenException $exception) { // on child, specifically ShouldNotHappenException, just throw
throw $exception;
} catch (Throwable $throwable) {
// on parent any Throwable, with special condition message, just return
if ($throwable->getMessage() === 'Special condition') {
return;
}
throw $throwable;
}
}
} |
|
This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work. |
No description provided.