Skip to content

Commit 12cfbbc

Browse files
authored
feat: add additional methods to laravel-arrayaccess-to-method-call (#371)
This also adds the Cache contract to the list and cleans up the implementations---they are not needed since the contracts ar listed and they all implement the contracts.
1 parent 6ee0a9d commit 12cfbbc

File tree

10 files changed

+100
-25
lines changed

10 files changed

+100
-25
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Rector upgrades rules for Laravel Framework",
66
"require": {
77
"php": ">=8.3",
8-
"rector/rector": "^2.0.0",
8+
"rector/rector": "^2.1.3",
99
"webmozart/assert": "^1.11",
1010
"symplify/rule-doc-generator-contracts": "^11.2"
1111
},

config/sets/laravel-arrayaccess-to-method-call.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,25 @@
1313
->ruleWithConfiguration(
1414
ArrayDimFetchToMethodCallRector::class,
1515
[
16-
new ArrayDimFetchToMethodCall(
17-
new ObjectType('Illuminate\Foundation\Application'),
18-
'make',
19-
),
20-
new ArrayDimFetchToMethodCall(
21-
new ObjectType('Illuminate\Contracts\Foundation\Application'),
22-
'make',
23-
),
24-
new ArrayDimFetchToMethodCall(
25-
new ObjectType('Illuminate\Config\Repository'),
26-
'get',
27-
),
2816
new ArrayDimFetchToMethodCall(
2917
new ObjectType('Illuminate\Contracts\Config\Repository'),
30-
'make',
18+
'get',
19+
'set',
20+
'has',
21+
'set', // intentional
3122
),
3223
new ArrayDimFetchToMethodCall(
33-
new ObjectType('Illuminate\Contracts\Container\Container\Application'),
34-
'make',
24+
new ObjectType('Illuminate\Contracts\Cache\Repository'),
25+
'get',
26+
'set',
27+
'has',
28+
'forget',
3529
),
3630
new ArrayDimFetchToMethodCall(
3731
new ObjectType('Illuminate\Contracts\Container\Container'),
3832
'make',
33+
'bind',
34+
'bound',
3935
),
4036
],
4137
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Illuminate\Cache;
6+
7+
use ArrayAccess;
8+
use Illuminate\Contracts\Cache\Repository as CacheContract;
9+
10+
if (class_exists('Illuminate\Cache\Repository')) {
11+
return;
12+
}
13+
14+
class Repository implements ArrayAccess, CacheContract {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Illuminate\Config;
6+
7+
use ArrayAccess;
8+
use Illuminate\Contracts\Config\Repository as ConfigContract;
9+
10+
if (class_exists('Illuminate\Config\Repository')) {
11+
return;
12+
}
13+
14+
class Repository implements ArrayAccess, ConfigContract {}

stubs/Illuminate/Container/Container.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Illuminate\Container;
44

5+
use ArrayAccess;
56
use Illuminate\Contracts\Container\Container as ContainerContract;
67

7-
class Container implements ContainerContract {}
8+
if (class_exists('Illuminate\Container\Container')) {
9+
return;
10+
}
11+
12+
class Container implements ArrayAccess, ContainerContract {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Illuminate\Contracts\Cache;
6+
7+
if (interface_exists('Illuminate\Contracts\Cache\Repository')) {
8+
return;
9+
}
10+
11+
interface Repository {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Illuminate\Contracts\Config;
6+
7+
if (interface_exists('Illuminate\Contracts\Config\Repository')) {
8+
return;
9+
}
10+
11+
interface Repository {}

stubs/Illuminate/Contracts/Container/Container.php

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

33
namespace Illuminate\Contracts\Container;
44

5+
if (interface_exists('Illuminate\Contracts\Container\Container')) {
6+
return;
7+
}
8+
59
interface Container {}

stubs/Illuminate/Contracts/Foundation/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Illuminate\Contracts\Container\Container;
88

9-
if (class_exists('Illuminate\Contracts\Foundation\Application')) {
9+
if (interface_exists('Illuminate\Contracts\Foundation\Application')) {
1010
return;
1111
}
1212

tests/Sets/ArrayAccessToMethodCall/Fixture/fixture.php.inc

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@
33
namespace RectorLaravel\Tests\Sets\ArrayAccessToMethodCall;
44

55
$app = new \Illuminate\Foundation\Application();
6-
7-
$service = $app[\Illuminate\Contracts\Events\Dispatcher::class];
6+
$app['foo'];
7+
$app['foo'] = 'Foo';
8+
isset($app['foo']);
9+
unset($app['foo']); // skipped
810

911
$config = new \Illuminate\Config\Repository();
12+
$config['app.name'];
13+
$config['app.name'] = 'Foo';
14+
isset($config['app.name']);
15+
unset($config['app.name']);
1016

11-
$name = $config['app.name'];
17+
$cache = new \Illuminate\Cache\Repository();
18+
$cache['app.name'];
19+
$cache['app.name'] = 'Foo';
20+
isset($cache['app.name']);
21+
unset($cache['app.name']);
1222

1323
?>
1424
-----
@@ -17,11 +27,21 @@ $name = $config['app.name'];
1727
namespace RectorLaravel\Tests\Sets\ArrayAccessToMethodCall;
1828

1929
$app = new \Illuminate\Foundation\Application();
20-
21-
$service = $app->make(\Illuminate\Contracts\Events\Dispatcher::class);
30+
$app->make('foo');
31+
$app->bind('foo', 'Foo');
32+
$app->bound('foo');
33+
unset($app['foo']); // skipped
2234

2335
$config = new \Illuminate\Config\Repository();
24-
25-
$name = $config->get('app.name');
36+
$config->get('app.name');
37+
$config->set('app.name', 'Foo');
38+
$config->has('app.name');
39+
$config->set('app.name');
40+
41+
$cache = new \Illuminate\Cache\Repository();
42+
$cache->get('app.name');
43+
$cache->set('app.name', 'Foo');
44+
$cache->has('app.name');
45+
$cache->forget('app.name');
2646

2747
?>

0 commit comments

Comments
 (0)