From ef1ddc508e66a32f73d6684e1f135333029deab1 Mon Sep 17 00:00:00 2001 From: Mohammad Mortazavi Date: Tue, 14 Jan 2025 18:52:56 +0330 Subject: [PATCH 1/4] Update ApplyDefaultInsteadOfNullCoalesceRector.php --- .../Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php b/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php index 58d90f69..1297aaf1 100644 --- a/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php +++ b/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php @@ -107,12 +107,14 @@ public function refactor(Node $node): MethodCall|StaticCall|FuncCall|null $this->isObjectType( $objectType, $applyDefaultWith->getObjectType()) && - $this->isName($call->name, $applyDefaultWith->getMethodName()) + $this->isName($call->name, $applyDefaultWith->getMethodName()) && + !$node->right instanceof Node\Expr\Throw_ ) { $valid = true; } elseif ( $applyDefaultWith->getObjectType() === null && - $this->isName($call->name, $applyDefaultWith->getMethodName()) + $this->isName($call->name, $applyDefaultWith->getMethodName()) && + !$node->right instanceof Node\Expr\Throw_ ) { $valid = true; } From a5e03f90eb35614849ced936ee56ea75c0799260 Mon Sep 17 00:00:00 2001 From: Mohammad Mortazavi Date: Tue, 14 Jan 2025 18:52:58 +0330 Subject: [PATCH 2/4] Create skip_throw_exceptions.php.inc --- .../Fixture/skip_throw_exceptions.php.inc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector/Fixture/skip_throw_exceptions.php.inc diff --git a/tests/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector/Fixture/skip_throw_exceptions.php.inc b/tests/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector/Fixture/skip_throw_exceptions.php.inc new file mode 100644 index 00000000..072329c7 --- /dev/null +++ b/tests/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector/Fixture/skip_throw_exceptions.php.inc @@ -0,0 +1,11 @@ +input('value') ?? throw new \Exception('No Google maps base URL configured.'); + +\Illuminate\Support\Env::get('APP_NAME') ?? throw new \Exception('No Google maps base URL configured.'); + +?> From 9e97fbbf867a96167ffee46fc36dbb53a7cb16ff Mon Sep 17 00:00:00 2001 From: Mohammad Mortazavi Date: Tue, 14 Jan 2025 19:01:26 +0330 Subject: [PATCH 3/4] Fix style; --- .../Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php b/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php index 1297aaf1..248acf89 100644 --- a/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php +++ b/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php @@ -2,6 +2,7 @@ namespace RectorLaravel\Rector\Coalesce; +use PhpParser\Node\Expr\Throw_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\BinaryOp\Coalesce; @@ -108,13 +109,13 @@ public function refactor(Node $node): MethodCall|StaticCall|FuncCall|null $objectType, $applyDefaultWith->getObjectType()) && $this->isName($call->name, $applyDefaultWith->getMethodName()) && - !$node->right instanceof Node\Expr\Throw_ + ! $node->right instanceof Throw_ ) { $valid = true; } elseif ( $applyDefaultWith->getObjectType() === null && $this->isName($call->name, $applyDefaultWith->getMethodName()) && - !$node->right instanceof Node\Expr\Throw_ + ! $node->right instanceof Throw_ ) { $valid = true; } From ee4076562129f83cac081e20f150a56f4807ac0b Mon Sep 17 00:00:00 2001 From: Mohammad Mortazavi Date: Wed, 15 Jan 2025 11:59:03 +0330 Subject: [PATCH 4/4] Fix lint error; --- src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php b/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php index 248acf89..47ef3262 100644 --- a/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php +++ b/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php @@ -2,13 +2,13 @@ namespace RectorLaravel\Rector\Coalesce; -use PhpParser\Node\Expr\Throw_; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\BinaryOp\Coalesce; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; +use PhpParser\Node\Expr\Throw_; use PHPStan\Type\ObjectType; use Rector\Contract\Rector\ConfigurableRectorInterface; use RectorLaravel\AbstractRector;