Skip to content

Commit d237f6e

Browse files
authored
Fix Argument Adding rules in Laravel 9 set. (#243)
1 parent d57fa8b commit d237f6e

17 files changed

+203
-45
lines changed

config/sets/laravel80.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PHPStan\Type\ArrayType;
66
use PHPStan\Type\MixedType;
77
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
8-
use Rector\Arguments\ValueObject\ArgumentAdder;
8+
use Rector\Arguments\ValueObject\ArgumentAdderWithoutDefaultValue;
99
use Rector\Config\RectorConfig;
1010
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
1111
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
@@ -21,12 +21,11 @@
2121

2222
// https://github.com/laravel/framework/commit/4d228d6e9dbcbd4d97c45665980d8b8c685b27e6
2323
$rectorConfig
24-
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
24+
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
2525
'Illuminate\Contracts\Database\Eloquent\Castable',
2626
'castUsing',
2727
0,
2828
'arguments',
29-
[], // TODO: Add argument without default value
3029
new ArrayType(new MixedType, new MixedType)
3130
),
3231
]);

config/sets/laravel90.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
declare(strict_types=1);
44

5+
use Rector\Arguments\NodeAnalyzer\ArgumentAddingScope;
56
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
6-
use Rector\Arguments\ValueObject\ArgumentAdderWithoutDefaultValue;
7+
use Rector\Arguments\ValueObject\ArgumentAdder;
78
use Rector\Config\RectorConfig;
89
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
910
use Rector\Renaming\ValueObject\MethodCallRename;
@@ -19,41 +20,40 @@
1920

2021
// https://github.com/laravel/framework/commit/8f9ddea4481717943ed4ecff96d86b703c81a87d
2122
$rectorConfig
22-
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
23+
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
2324
'Illuminate\Contracts\Foundation\Application',
2425
'storagePath',
2526
0,
2627
'path',
28+
'',
29+
null,
30+
ArgumentAddingScope::SCOPE_CLASS_METHOD,
2731
),
2832
]);
2933

3034
// https://github.com/laravel/framework/commit/e6c8aaea886d35cc55bd3469f1a95ad56d53e474
3135
$rectorConfig
32-
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
36+
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
3337
'Illuminate\Foundation\Application',
3438
'langPath',
3539
0,
3640
'path',
41+
'',
42+
null,
43+
ArgumentAddingScope::SCOPE_CLASS_METHOD,
3744
),
3845
]);
3946

4047
// https://github.com/laravel/framework/commit/e095ac0e928b5620f33c9b60816fde5ece867d32
4148
$rectorConfig
42-
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
49+
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
4350
'Illuminate\Database\Eloquent\Model',
4451
'touch',
4552
0,
4653
'attribute',
47-
),
48-
]);
49-
50-
// https://github.com/laravel/framework/commit/6daecf43dd931dc503e410645ff4a7d611e3371f
51-
$rectorConfig
52-
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
53-
'Illuminate\Queue\Failed\FailedJobProviderInterface',
54-
'flush',
55-
0,
56-
'hours',
54+
null,
55+
null,
56+
ArgumentAddingScope::SCOPE_CLASS_METHOD,
5757
),
5858
]);
5959

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Illuminate\Container;
4+
5+
use Illuminate\Contracts\Container\Container as ContainerContract;
6+
7+
class Container implements ContainerContract
8+
{
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Illuminate\Contracts\Container;
4+
5+
interface Container
6+
{
7+
}

stubs/Illuminate/Contracts/Foundation/Application.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
namespace Illuminate\Contracts\Foundation;
66

7+
use Illuminate\Contracts\Container\Container;
8+
79
if (class_exists('Illuminate\Contracts\Foundation\Application')) {
810
return;
911
}
1012

11-
final class Application
13+
interface Application extends Container
1214
{
13-
public function tagged(string $tagName): iterable
14-
{
15-
return [];
16-
}
15+
public function tagged(string $tagName): iterable;
16+
17+
public function storagePath($path = '');
1718
}

stubs/Illuminate/Database/Eloquent/Model.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@
88

99
abstract class Model
1010
{
11+
/**
12+
* Exists in the Illuminate/Database/Eloquent/Concerns/HasTimestamps trait
13+
* Put here for simplicity
14+
*/
15+
public function touch($attribute = null)
16+
{
17+
return true;
18+
}
1119
}

stubs/Illuminate/Foundation/Application.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,27 @@
44

55
namespace Illuminate\Foundation;
66

7+
use Illuminate\Container\Container;
8+
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
9+
710
if (class_exists('Illuminate\Foundation\Application')) {
811
return;
912
}
1013

11-
class Application
14+
class Application extends Container implements ApplicationContract
1215
{
16+
public function tagged(string $tagName): iterable
17+
{
18+
return [];
19+
}
20+
21+
public function storagePath($path = '')
22+
{
23+
return $path;
24+
}
25+
26+
public function langPath($path = '')
27+
{
28+
return $path;
29+
}
1330
}

stubs/Illuminate/Queue/Failed/FailedJobProviderInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@
1010

1111
interface FailedJobProviderInterface
1212
{
13+
public function log($connection, $queue, $payload, $exception);
14+
15+
public function all();
16+
17+
public function find($id);
18+
19+
public function forget($id);
20+
21+
public function flush($hours = null);
1322
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
4+
5+
use Illuminate\Foundation\Application;
6+
7+
class CustomApplication extends Application
8+
{
9+
public function langPath(): string
10+
{
11+
return '';
12+
}
13+
14+
}
15+
16+
$customApp = new CustomApplication();
17+
$customApp->langPath();
18+
19+
?>
20+
-----
21+
<?php
22+
23+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
24+
25+
use Illuminate\Foundation\Application;
26+
27+
class CustomApplication extends Application
28+
{
29+
public function langPath($path = ''): string
30+
{
31+
return '';
32+
}
33+
34+
}
35+
36+
$customApp = new CustomApplication();
37+
$customApp->langPath();
38+
39+
?>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
4+
5+
use Illuminate\Foundation\Application;
6+
7+
class CustomApplication extends Application
8+
{
9+
public function storagePath(): string
10+
{
11+
return '';
12+
}
13+
14+
}
15+
16+
$customApp = new CustomApplication();
17+
$customApp->storagePath();
18+
19+
?>
20+
-----
21+
<?php
22+
23+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
24+
25+
use Illuminate\Foundation\Application;
26+
27+
class CustomApplication extends Application
28+
{
29+
public function storagePath($path = ''): string
30+
{
31+
return '';
32+
}
33+
34+
}
35+
36+
$customApp = new CustomApplication();
37+
$customApp->storagePath();
38+
39+
?>

tests/Sets/Laravel90/Fixture/application_lang_path_new_attribute.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace RectorLaravel\Tests\Sets\Laravel90;
3+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
44

55
use Illuminate\Foundation\Application;
66

tests/Sets/Laravel90/Fixture/application_storage_path_new_attribute.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace RectorLaravel\Tests\Sets\Laravel90;
3+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
44

55
use Illuminate\Contracts\Foundation\Application;
66

tests/Sets/Laravel90/Fixture/exceptions_handler_ignore_with_public_visibility.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace RectorLaravel\Tests\Sets\Laravel90;
3+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
44

55
use Illuminate\Foundation\Exceptions\Handler;
66

@@ -15,7 +15,7 @@ class CustomHandler extends Handler
1515
-----
1616
<?php
1717

18-
namespace RectorLaravel\Tests\Sets\Laravel90;
18+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
1919

2020
use Illuminate\Foundation\Exceptions\Handler;
2121

tests/Sets/Laravel90/Fixture/failed_job_provider_interface_new_attribute.php.inc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace RectorLaravel\Tests\Sets\Laravel90;
3+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
44

55
use Illuminate\Queue\Failed\FailedJobProviderInterface;
66

@@ -9,6 +9,22 @@ class FailedJobProvider implements FailedJobProviderInterface
99
public function flush($age = null)
1010
{
1111
}
12+
13+
public function log($connection, $queue, $payload, $exception)
14+
{
15+
}
16+
17+
public function all()
18+
{
19+
}
20+
21+
public function find($id)
22+
{
23+
}
24+
25+
public function forget($id)
26+
{
27+
}
1228
}
1329

1430
$provider = new FailedJobProvider();

tests/Sets/Laravel90/Fixture/method_renames.php.inc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<?php
22

3-
namespace RectorLaravel\Tests\Sets\Laravel90;
4-
3+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
54

65
use Illuminate\Mail\Mailable;
76
use Illuminate\Mail\Mailer;
87
use Illuminate\Mail\MailManager;
98
use Illuminate\Mail\Message;
109
use Illuminate\Notifications\Messages\MailMessage;
10+
use Illuminate\Support\Collection;
1111
use Illuminate\Testing\TestResponse;
12-
use RectorLaravel\Tests\Sets\Laravel90\Source\Collection;
1312

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

30-
namespace RectorLaravel\Tests\Sets\Laravel90;
31-
29+
namespace RectorLaravel\Tests\Sets\Laravel90\Fixture;
3230

3331
use Illuminate\Mail\Mailable;
3432
use Illuminate\Mail\Mailer;
3533
use Illuminate\Mail\MailManager;
3634
use Illuminate\Mail\Message;
3735
use Illuminate\Notifications\Messages\MailMessage;
36+
use Illuminate\Support\Collection;
3837
use Illuminate\Testing\TestResponse;
39-
use RectorLaravel\Tests\Sets\Laravel90\Source\Collection;
4038

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

0 commit comments

Comments
 (0)