Skip to content

Commit

Permalink
Fix Argument Adding rules in Laravel 9 set. (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeniJaho authored Aug 23, 2024
1 parent d57fa8b commit d237f6e
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 45 deletions.
5 changes: 2 additions & 3 deletions config/sets/laravel80.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Arguments\ValueObject\ArgumentAdderWithoutDefaultValue;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
Expand All @@ -21,12 +21,11 @@

// https://github.com/laravel/framework/commit/4d228d6e9dbcbd4d97c45665980d8b8c685b27e6
$rectorConfig
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
'Illuminate\Contracts\Database\Eloquent\Castable',
'castUsing',
0,
'arguments',
[], // TODO: Add argument without default value
new ArrayType(new MixedType, new MixedType)
),
]);
Expand Down
28 changes: 14 additions & 14 deletions config/sets/laravel90.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

declare(strict_types=1);

use Rector\Arguments\NodeAnalyzer\ArgumentAddingScope;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdderWithoutDefaultValue;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
Expand All @@ -19,41 +20,40 @@

// https://github.com/laravel/framework/commit/8f9ddea4481717943ed4ecff96d86b703c81a87d
$rectorConfig
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
'Illuminate\Contracts\Foundation\Application',
'storagePath',
0,
'path',
'',
null,
ArgumentAddingScope::SCOPE_CLASS_METHOD,
),
]);

// https://github.com/laravel/framework/commit/e6c8aaea886d35cc55bd3469f1a95ad56d53e474
$rectorConfig
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
'Illuminate\Foundation\Application',
'langPath',
0,
'path',
'',
null,
ArgumentAddingScope::SCOPE_CLASS_METHOD,
),
]);

// https://github.com/laravel/framework/commit/e095ac0e928b5620f33c9b60816fde5ece867d32
$rectorConfig
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
'Illuminate\Database\Eloquent\Model',
'touch',
0,
'attribute',
),
]);

// https://github.com/laravel/framework/commit/6daecf43dd931dc503e410645ff4a7d611e3371f
$rectorConfig
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
'Illuminate\Queue\Failed\FailedJobProviderInterface',
'flush',
0,
'hours',
null,
null,
ArgumentAddingScope::SCOPE_CLASS_METHOD,
),
]);

Expand Down
9 changes: 9 additions & 0 deletions stubs/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Illuminate\Container;

use Illuminate\Contracts\Container\Container as ContainerContract;

class Container implements ContainerContract
{
}
7 changes: 7 additions & 0 deletions stubs/Illuminate/Contracts/Container/Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Illuminate\Contracts\Container;

interface Container
{
}
11 changes: 6 additions & 5 deletions stubs/Illuminate/Contracts/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Illuminate\Contracts\Foundation;

use Illuminate\Contracts\Container\Container;

if (class_exists('Illuminate\Contracts\Foundation\Application')) {
return;
}

final class Application
interface Application extends Container
{
public function tagged(string $tagName): iterable
{
return [];
}
public function tagged(string $tagName): iterable;

public function storagePath($path = '');
}
8 changes: 8 additions & 0 deletions stubs/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@

abstract class Model
{
/**
* Exists in the Illuminate/Database/Eloquent/Concerns/HasTimestamps trait
* Put here for simplicity
*/
public function touch($attribute = null)
{
return true;
}
}
19 changes: 18 additions & 1 deletion stubs/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,27 @@

namespace Illuminate\Foundation;

use Illuminate\Container\Container;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;

if (class_exists('Illuminate\Foundation\Application')) {
return;
}

class Application
class Application extends Container implements ApplicationContract
{
public function tagged(string $tagName): iterable
{
return [];
}

public function storagePath($path = '')
{
return $path;
}

public function langPath($path = '')
{
return $path;
}
}
9 changes: 9 additions & 0 deletions stubs/Illuminate/Queue/Failed/FailedJobProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@

interface FailedJobProviderInterface
{
public function log($connection, $queue, $payload, $exception);

public function all();

public function find($id);

public function forget($id);

public function flush($hours = null);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Foundation\Application;

class CustomApplication extends Application
{
public function langPath(): string
{
return '';
}

}

$customApp = new CustomApplication();
$customApp->langPath();

?>
-----
<?php

namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Foundation\Application;

class CustomApplication extends Application
{
public function langPath($path = ''): string
{
return '';
}

}

$customApp = new CustomApplication();
$customApp->langPath();

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Foundation\Application;

class CustomApplication extends Application
{
public function storagePath(): string
{
return '';
}

}

$customApp = new CustomApplication();
$customApp->storagePath();

?>
-----
<?php

namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Foundation\Application;

class CustomApplication extends Application
{
public function storagePath($path = ''): string
{
return '';
}

}

$customApp = new CustomApplication();
$customApp->storagePath();

?>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Foundation\Application;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Contracts\Foundation\Application;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Foundation\Exceptions\Handler;

Expand All @@ -15,7 +15,7 @@ class CustomHandler extends Handler
-----
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Foundation\Exceptions\Handler;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Queue\Failed\FailedJobProviderInterface;

Expand All @@ -9,6 +9,22 @@ class FailedJobProvider implements FailedJobProviderInterface
public function flush($age = null)
{
}

public function log($connection, $queue, $payload, $exception)
{
}

public function all()
{
}

public function find($id)
{
}

public function forget($id)
{
}
}

$provider = new FailedJobProvider();
Expand Down
10 changes: 4 additions & 6 deletions tests/Sets/Laravel90/Fixture/method_renames.php.inc
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;

namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailer;
use Illuminate\Mail\MailManager;
use Illuminate\Mail\Message;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Collection;
use Illuminate\Testing\TestResponse;
use RectorLaravel\Tests\Sets\Laravel90\Source\Collection;

(new Collection())->reduceWithKeys(fn () => null);
(new Collection())->reduceMany(fn () => null);
Expand All @@ -27,16 +26,15 @@ use RectorLaravel\Tests\Sets\Laravel90\Source\Collection;
-----
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;

namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;

use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailer;
use Illuminate\Mail\MailManager;
use Illuminate\Mail\Message;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Collection;
use Illuminate\Testing\TestResponse;
use RectorLaravel\Tests\Sets\Laravel90\Source\Collection;

(new Collection())->reduce(fn () => null);
(new Collection())->reduceSpread(fn () => null);
Expand Down
Loading

0 comments on commit d237f6e

Please sign in to comment.