Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redundant default arguments in Laravel 9 Set #221

Merged
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
12 changes: 5 additions & 7 deletions config/sets/laravel90.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

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\ValueObject\MethodCallRename;
Expand All @@ -19,29 +19,27 @@

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

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

// https://github.com/laravel/framework/commit/e095ac0e928b5620f33c9b60816fde5ece867d32
$rectorConfig
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
'Illuminate\Database\Eloquent\Model',
'touch',
0,
Expand All @@ -51,7 +49,7 @@

// https://github.com/laravel/framework/commit/6daecf43dd931dc503e410645ff4a7d611e3371f
$rectorConfig
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
'Illuminate\Queue\Failed\FailedJobProviderInterface',
'flush',
0,
Expand Down
13 changes: 13 additions & 0 deletions stubs/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Foundation;

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

class Application
{
}
13 changes: 13 additions & 0 deletions stubs/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Foundation\Exceptions;

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

class Handler
{
}
13 changes: 13 additions & 0 deletions stubs/Illuminate/Mail/MailManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Mail;

if (class_exists('Illuminate\Mail\MailManager')) {
return;
}

class MailManager
{
}
13 changes: 13 additions & 0 deletions stubs/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Mail;

if (class_exists('Illuminate\Mail\Mailable')) {
return;
}

class Mailable
{
}
13 changes: 13 additions & 0 deletions stubs/Illuminate/Mail/Mailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Mail;

if (class_exists('Illuminate\Mail\Mailer')) {
return;
}

class Mailer
{
}
13 changes: 13 additions & 0 deletions stubs/Illuminate/Mail/Message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Mail;

if (class_exists('Illuminate\Mail\Message')) {
return;
}

class Message
{
}
13 changes: 13 additions & 0 deletions stubs/Illuminate/Notifications/Messages/MailMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Notifications\Messages;

if (class_exists('Illuminate\Notifications\Messages\MailMessage')) {
return;
}

class MailMessage
{
}
13 changes: 13 additions & 0 deletions stubs/Illuminate/Queue/Failed/FailedJobProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Queue\Failed;

if (class_exists('Illuminate\Queue\Failed\FailedJobProviderInterface')) {
return;
}

interface FailedJobProviderInterface
{
}
13 changes: 13 additions & 0 deletions stubs/Illuminate/Support/Enumerable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Support;

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

interface Enumerable
{
}
13 changes: 13 additions & 0 deletions stubs/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Illuminate\Testing;

if (class_exists('Illuminate\Testing\TestResponse')) {
return;
}

class TestResponse
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;

use Illuminate\Foundation\Application;

class SomeFixture
{
protected Application $app;

public function run(): void
{
$this->app->langPath();
}
}

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

namespace RectorLaravel\Tests\Sets\Laravel90;

use Illuminate\Contracts\Foundation\Application;

class SomeFixture
{
protected Application $app;

public function run(): void
{
$this->app->storagePath();
}
}

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

namespace RectorLaravel\Tests\Sets\Laravel90;

use Illuminate\Foundation\Exceptions\Handler;

class CustomHandler extends Handler
{
protected function ignore(string $class)
{
}
}

?>
-----
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;

use Illuminate\Foundation\Exceptions\Handler;

class CustomHandler extends Handler
{
public function ignore(string $class)
{
}
}

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

namespace RectorLaravel\Tests\Sets\Laravel90;

use Illuminate\Queue\Failed\FailedJobProviderInterface;

class FailedJobProvider implements FailedJobProviderInterface
{
public function flush($age = null)
{
}
}

$provider = new FailedJobProvider();
$provider->flush();
$provider->flush(10);

?>
53 changes: 53 additions & 0 deletions tests/Sets/Laravel90/Fixture/method_renames.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;


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

(new Collection())->reduceWithKeys(fn () => null);
(new Collection())->reduceMany(fn () => null);

(new Message())->getSwiftMessage();
(new Mailable())->withSwiftMessage();
(new MailMessage())->withSwiftMessage();
(new Mailer())->getSwiftMailer();
(new Mailer())->setSwiftMailer();
(new MailManager())->createTransport();

(new TestResponse())->assertDeleted(null);

?>
-----
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;


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

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

(new Message())->getSymfonyMessage();
(new Mailable())->withSymfonyMessage();
(new MailMessage())->withSymfonyMessage();
(new Mailer())->getSymfonyTransport();
(new Mailer())->setSymfonyTransport();
(new MailManager())->createSymfonyTransport();

(new TestResponse())->assertModelMissing(null);

?>
12 changes: 12 additions & 0 deletions tests/Sets/Laravel90/Fixture/model_touch_new_attribute.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90;

use Illuminate\Database\Eloquent\Model;

class User extends Model {}

$user = new User();
$user->touch();

?>
31 changes: 31 additions & 0 deletions tests/Sets/Laravel90/Laravel90Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace RectorLaravel\Tests\Sets\Laravel90;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class Laravel90Test extends AbstractRectorTestCase
{
public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

/**
* @test
*/
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
9 changes: 9 additions & 0 deletions tests/Sets/Laravel90/Source/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace RectorLaravel\Tests\Sets\Laravel90\Source;

use Illuminate\Support\Enumerable;

class Collection implements Enumerable
{
}
9 changes: 9 additions & 0 deletions tests/Sets/Laravel90/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../config/sets/laravel90.php');
};
Loading