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/src/Set/LaravelSetProvider.php b/src/Set/LaravelSetProvider.php index 2288cbf5..45f2d8e0 100644 --- a/src/Set/LaravelSetProvider.php +++ b/src/Set/LaravelSetProvider.php @@ -15,27 +15,27 @@ final class LaravelSetProvider implements SetProviderInterface * @var string[] */ private const LARAVEL_FIVE = [ - LaravelSetList::LARAVEL_50, - LaravelSetList::LARAVEL_51, - LaravelSetList::LARAVEL_52, - LaravelSetList::LARAVEL_53, - LaravelSetList::LARAVEL_54, - LaravelSetList::LARAVEL_55, - LaravelSetList::LARAVEL_56, - LaravelSetList::LARAVEL_57, LaravelSetList::LARAVEL_58, + LaravelSetList::LARAVEL_57, + LaravelSetList::LARAVEL_56, + LaravelSetList::LARAVEL_55, + LaravelSetList::LARAVEL_54, + LaravelSetList::LARAVEL_53, + LaravelSetList::LARAVEL_52, + LaravelSetList::LARAVEL_51, + LaravelSetList::LARAVEL_50, ]; /** * @var string[] */ private const LARAVEL_POST_FIVE = [ - LaravelSetList::LARAVEL_60, - LaravelSetList::LARAVEL_70, - LaravelSetList::LARAVEL_80, - LaravelSetList::LARAVEL_90, - LaravelSetList::LARAVEL_100, LaravelSetList::LARAVEL_110, + LaravelSetList::LARAVEL_100, + LaravelSetList::LARAVEL_90, + LaravelSetList::LARAVEL_80, + LaravelSetList::LARAVEL_70, + LaravelSetList::LARAVEL_60, ]; /** @@ -46,13 +46,18 @@ public function provide(): array return [ new Set( self::GROUP_NAME, - 'array/str func to static calls', - LaravelSetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL + 'Code quality', + LaravelSetList::LARAVEL_CODE_QUALITY ), new Set( self::GROUP_NAME, - 'Code quality', - LaravelSetList::LARAVEL_CODE_QUALITY + 'Collection improvements and simplifications', + LaravelSetList::LARAVEL_COLLECTION, + ), + new Set( + self::GROUP_NAME, + 'Container array access to method calls', + LaravelSetList::LARAVEL_ARRAYACCESS_TO_METHOD_CALL, ), new Set( self::GROUP_NAME, @@ -61,22 +66,27 @@ public function provide(): array ), new Set( self::GROUP_NAME, - 'Replaces If statements with helpers', - LaravelSetList::LARAVEL_IF_HELPERS, + 'Rename Aliases to FQN Classes', + LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES, ), new Set( self::GROUP_NAME, - 'Replace facades with service injection', - LaravelSetList::LARAVEL_STATIC_TO_INJECTION, + 'Replace array/str functions with static calls', + LaravelSetList::LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL ), new Set( self::GROUP_NAME, - 'Rename Alias to FQN Classes', - LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES, + 'Replace If statements with helpers', + LaravelSetList::LARAVEL_IF_HELPERS, ), new Set( self::GROUP_NAME, - 'Replace Magic Methods to Query Builder', + 'Replace facades with service injection', + LaravelSetList::LARAVEL_STATIC_TO_INJECTION, + ), + new Set( + self::GROUP_NAME, + 'Replace Magic Methods with Query Builder', LaravelSetList::LARAVEL_ELOQUENT_MAGIC_METHOD_TO_QUERY_BUILDER, ), new Set( @@ -100,18 +110,18 @@ private function getLaravelVersions(): array { $versions = []; - foreach (self::LARAVEL_FIVE as $index => $version) { + foreach (self::LARAVEL_POST_FIVE as $index => $version) { $versions[] = new Set( self::GROUP_NAME, - 'Laravel Framework 5.' . $index, + 'Laravel Framework ' . ($index + 6) . '.0', $version, ); } - foreach (self::LARAVEL_POST_FIVE as $index => $version) { + foreach (self::LARAVEL_FIVE as $index => $version) { $versions[] = new Set( self::GROUP_NAME, - 'Laravel Framework ' . ($index + 6) . '.0', + 'Laravel Framework 5.' . $index, $version, ); } 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')); + } +} +?>