-
-
Notifications
You must be signed in to change notification settings - Fork 741
Closed
rectorphp/rector-src
#6063Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | last dev-main |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/2b19a5fb-5e83-4b97-9968-a7cda22b54f3
<?php
namespace Rector\Tests\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector\Fixture;
class ApiException extends \Exception
{
public function __construct(
string $message,
?string $code = null,
?\Throwable $previous = null
) {
parent::__construct($message, 0, $previous);
$this->code = $code;
}
}
class SkipMethodCall {
private const WEBSITE_ALREADY_EXISTS = 'website_already_exists';
public function run()
{
try {
return $this->someApiAction();
} catch (ApiException $ex) {
if ($ex->getCode() !== self::WEBSITE_ALREADY_EXISTS) {
throw $ex;
}
}
}
private function someApiAction()
{
if (rand() % 2) {
throw new ApiException('API Action failed', 'website_already_exists');
}
return 1;
}
}
Expected Behaviour
Rector should not remove the condition as we cannot know what method call will return
Reactions are currently unavailable