diff --git a/src/Rector/MethodCall/WhereToWhereLikeRector.php b/src/Rector/MethodCall/WhereToWhereLikeRector.php index 1ac812ff..6dc4f33f 100644 --- a/src/Rector/MethodCall/WhereToWhereLikeRector.php +++ b/src/Rector/MethodCall/WhereToWhereLikeRector.php @@ -106,6 +106,13 @@ public function refactor(Node $node): ?Node return null; } + // Expressions are not supported with the `like` operator + if ($node->args[2] instanceof Arg && + $this->isObjectType($node->args[2]->value, new ObjectType('Illuminate\Contracts\Database\Query\Expression')) + ) { + return null; + } + $likeParameter = $this->getLikeParameterUsedInQuery($node); if (! in_array($likeParameter, ['like', 'like binary', 'ilike', 'not like', 'not like binary', 'not ilike'], true)) { diff --git a/stubs/Illuminate/Contracts/Database/Query/Expression.php b/stubs/Illuminate/Contracts/Database/Query/Expression.php new file mode 100644 index 00000000..a5623383 --- /dev/null +++ b/stubs/Illuminate/Contracts/Database/Query/Expression.php @@ -0,0 +1,19 @@ +where('name', 'like', DB::raw('Rector')); + } +} +?> diff --git a/tests/Rector/MethodCall/WhereToWhereLikeRector/Fixture/Postgres/SkipWithExpressions.php.inc b/tests/Rector/MethodCall/WhereToWhereLikeRector/Fixture/Postgres/SkipWithExpressions.php.inc new file mode 100644 index 00000000..593e3cb4 --- /dev/null +++ b/tests/Rector/MethodCall/WhereToWhereLikeRector/Fixture/Postgres/SkipWithExpressions.php.inc @@ -0,0 +1,15 @@ +where('name', 'like', DB::raw('Rector')); + } +} +?>