Skip to content

Commit

Permalink
Merge branch 'main' into 292-skip-throw-exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
GeniJaho authored Jan 15, 2025
2 parents ee40765 + f80e95e commit 3296348
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 28 deletions.
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
66 changes: 38 additions & 28 deletions src/Set/LaravelSetProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

/**
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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,
);
}
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'));
}
}
?>

0 comments on commit 3296348

Please sign in to comment.