Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Rector/MethodCall/WhereToWhereLikeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
19 changes: 19 additions & 0 deletions stubs/Illuminate/Contracts/Database/Query/Expression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Illuminate\Contracts\Database\Query;

use Illuminate\Database\Grammar;

if (interface_exists('Illuminate\Contracts\Database\Query\Expression')) {
return;
}

interface Expression
{
/**
* Get the value of the expression.
*
* @return string|int|float
*/
public function getValue(Grammar $grammar);
}
9 changes: 9 additions & 0 deletions stubs/Illuminate/Database/Grammar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Illuminate\Database;

if (class_exists('Illuminate\Database\Grammar')) {
return;
}

abstract class Grammar {}
16 changes: 16 additions & 0 deletions stubs/Illuminate/Support/Facades/DB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Illuminate\Support\Facades;

use Illuminate\Contracts\Database\Query\Expression;

if (class_exists('\Illuminate\Support\Facades\DB')) {
return;
}

/**
* @method static Expression raw(mixed $value)
*/
class DB {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace RectorLaravel\Tests\Rector\MethodCall\WhereToWhereLikeRector\Fixture\Default;

use Illuminate\Contracts\Database\Query\Builder;
use Illuminate\Support\Facades\DB;

class SkipWithExpressions
{
public function run(Builder $query)
{
$query->where('name', 'like', DB::raw('Rector'));
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace RectorLaravel\Tests\Rector\MethodCall\WhereToWhereLikeRector\Fixture\Postgres;

use Illuminate\Contracts\Database\Query\Builder;
use Illuminate\Support\Facades\DB;

class SkipWithExpressions
{
public function run(Builder $query)
{
$query->where('name', 'like', DB::raw('Rector'));
}
}
?>
Loading