Skip to content

Commit d791c46

Browse files
lucasmichottaylorotwell
authored andcommitted
Remove all Arr:: helpers. (#19218)
1 parent 76c2079 commit d791c46

File tree

8 files changed

+54
-50
lines changed

8 files changed

+54
-50
lines changed

src/Illuminate/Cache/CacheManager.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ protected function createMemcachedDriver(array $config)
164164

165165
$memcached = $this->app['memcached.connector']->connect(
166166
$config['servers'],
167-
array_get($config, 'persistent_id'),
168-
array_get($config, 'options', []),
169-
array_filter(array_get($config, 'sasl', []))
167+
Arr::get($config, 'persistent_id'),
168+
Arr::get($config, 'options', []),
169+
array_filter(Arr::get($config, 'sasl', []))
170170
);
171171

172172
return $this->repository(new MemcachedStore($memcached, $prefix));

src/Illuminate/Database/Connectors/SqlServerConnector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function getDsn(array $config)
6161
protected function prefersOdbc(array $config)
6262
{
6363
return in_array('odbc', $this->getAvailableDrivers()) &&
64-
array_get($config, 'odbc') === true;
64+
Arr::get($config, 'odbc') === true;
6565
}
6666

6767
/**

src/Illuminate/Queue/Jobs/Job.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Queue\Jobs;
44

5+
use Illuminate\Support\Arr;
56
use Illuminate\Queue\InteractsWithTime;
67

78
abstract class Job
@@ -187,7 +188,7 @@ public function payload()
187188
*/
188189
public function maxTries()
189190
{
190-
return array_get($this->payload(), 'maxTries');
191+
return Arr::get($this->payload(), 'maxTries');
191192
}
192193

193194
/**
@@ -197,7 +198,7 @@ public function maxTries()
197198
*/
198199
public function timeout()
199200
{
200-
return array_get($this->payload(), 'timeout');
201+
return Arr::get($this->payload(), 'timeout');
201202
}
202203

203204
/**

src/Illuminate/Routing/Route.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ public function getActionName()
654654
*/
655655
public function getActionMethod()
656656
{
657-
return array_last(explode('@', $this->getActionName()));
657+
return Arr::last(explode('@', $this->getActionName()));
658658
}
659659

660660
/**

src/Illuminate/Routing/RouteRegistrar.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use BadMethodCallException;
7+
use Illuminate\Support\Arr;
78
use InvalidArgumentException;
89

910
class RouteRegistrar
@@ -75,7 +76,7 @@ public function attribute($key, $value)
7576
throw new InvalidArgumentException("Attribute [{$key}] does not exist.");
7677
}
7778

78-
$this->attributes[array_get($this->aliases, $key, $key)] = $value;
79+
$this->attributes[Arr::get($this->aliases, $key, $key)] = $value;
7980

8081
return $this;
8182
}

src/Illuminate/Validation/ValidationData.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected static function extractValuesForWildcards($masterData, $data, $attribu
6161
$data = [];
6262

6363
foreach ($keys as $key) {
64-
$data[$key] = array_get($masterData, $key);
64+
$data[$key] = Arr::get($masterData, $key);
6565
}
6666

6767
return $data;

tests/Support/SupportHelpersTest.php

+39-38
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ArrayAccess;
77
use Mockery as m;
88
use RuntimeException;
9+
use Illuminate\Support\Arr;
910
use Illuminate\Support\Str;
1011
use PHPUnit\Framework\TestCase;
1112

@@ -25,62 +26,62 @@ public function testArrayDot()
2526
public function testArrayGet()
2627
{
2728
$array = ['names' => ['developer' => 'taylor']];
28-
$this->assertEquals('taylor', array_get($array, 'names.developer'));
29-
$this->assertEquals('dayle', array_get($array, 'names.otherDeveloper', 'dayle'));
30-
$this->assertEquals('dayle', array_get($array, 'names.otherDeveloper', function () {
29+
$this->assertEquals('taylor', Arr::get($array, 'names.developer'));
30+
$this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', 'dayle'));
31+
$this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', function () {
3132
return 'dayle';
3233
}));
3334
}
3435

3536
public function testArrayHas()
3637
{
3738
$array = ['names' => ['developer' => 'taylor']];
38-
$this->assertTrue(array_has($array, 'names'));
39-
$this->assertTrue(array_has($array, 'names.developer'));
40-
$this->assertFalse(array_has($array, 'foo'));
41-
$this->assertFalse(array_has($array, 'foo.bar'));
39+
$this->assertTrue(Arr::has($array, 'names'));
40+
$this->assertTrue(Arr::has($array, 'names.developer'));
41+
$this->assertFalse(Arr::has($array, 'foo'));
42+
$this->assertFalse(Arr::has($array, 'foo.bar'));
4243
}
4344

4445
public function testArraySet()
4546
{
4647
$array = [];
47-
array_set($array, 'names.developer', 'taylor');
48+
Arr::set($array, 'names.developer', 'taylor');
4849
$this->assertEquals('taylor', $array['names']['developer']);
4950
}
5051

5152
public function testArrayForget()
5253
{
5354
$array = ['names' => ['developer' => 'taylor', 'otherDeveloper' => 'dayle']];
54-
array_forget($array, 'names.developer');
55+
Arr::forget($array, 'names.developer');
5556
$this->assertFalse(isset($array['names']['developer']));
5657
$this->assertTrue(isset($array['names']['otherDeveloper']));
5758

5859
$array = ['names' => ['developer' => 'taylor', 'otherDeveloper' => 'dayle', 'thirdDeveloper' => 'Lucas']];
59-
array_forget($array, ['names.developer', 'names.otherDeveloper']);
60+
Arr::forget($array, ['names.developer', 'names.otherDeveloper']);
6061
$this->assertFalse(isset($array['names']['developer']));
6162
$this->assertFalse(isset($array['names']['otherDeveloper']));
6263
$this->assertTrue(isset($array['names']['thirdDeveloper']));
6364

6465
$array = ['names' => ['developer' => 'taylor', 'otherDeveloper' => 'dayle'], 'otherNames' => ['developer' => 'Lucas', 'otherDeveloper' => 'Graham']];
65-
array_forget($array, ['names.developer', 'otherNames.otherDeveloper']);
66+
Arr::forget($array, ['names.developer', 'otherNames.otherDeveloper']);
6667
$expected = ['names' => ['otherDeveloper' => 'dayle'], 'otherNames' => ['developer' => 'Lucas']];
6768
$this->assertEquals($expected, $array);
6869
}
6970

7071
public function testArrayPluckWithArrayAndObjectValues()
7172
{
7273
$array = [(object) ['name' => 'taylor', 'email' => 'foo'], ['name' => 'dayle', 'email' => 'bar']];
73-
$this->assertEquals(['taylor', 'dayle'], array_pluck($array, 'name'));
74-
$this->assertEquals(['taylor' => 'foo', 'dayle' => 'bar'], array_pluck($array, 'email', 'name'));
74+
$this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'name'));
75+
$this->assertEquals(['taylor' => 'foo', 'dayle' => 'bar'], Arr::pluck($array, 'email', 'name'));
7576
}
7677

7778
public function testArrayPluckWithNestedKeys()
7879
{
7980
$array = [['user' => ['taylor', 'otwell']], ['user' => ['dayle', 'rees']]];
80-
$this->assertEquals(['taylor', 'dayle'], array_pluck($array, 'user.0'));
81-
$this->assertEquals(['taylor', 'dayle'], array_pluck($array, ['user', 0]));
82-
$this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], array_pluck($array, 'user.1', 'user.0'));
83-
$this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], array_pluck($array, ['user', 1], ['user', 0]));
81+
$this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'user.0'));
82+
$this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, ['user', 0]));
83+
$this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, 'user.1', 'user.0'));
84+
$this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, ['user', 1], ['user', 0]));
8485
}
8586

8687
public function testArrayPluckWithNestedArrays()
@@ -101,9 +102,9 @@ public function testArrayPluckWithNestedArrays()
101102
],
102103
];
103104

104-
$this->assertEquals([['taylor'], ['abigail', 'dayle']], array_pluck($array, 'users.*.first'));
105-
$this->assertEquals(['a' => ['taylor'], 'b' => ['abigail', 'dayle']], array_pluck($array, 'users.*.first', 'account'));
106-
$this->assertEquals([['[email protected]'], [null, null]], array_pluck($array, 'users.*.email'));
105+
$this->assertEquals([['taylor'], ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first'));
106+
$this->assertEquals(['a' => ['taylor'], 'b' => ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first', 'account'));
107+
$this->assertEquals([['[email protected]'], [null, null]], Arr::pluck($array, 'users.*.email'));
107108
}
108109

109110
public function testArrayExcept()
@@ -121,8 +122,8 @@ public function testArrayExcept()
121122
public function testArrayOnly()
122123
{
123124
$array = ['name' => 'taylor', 'age' => 26];
124-
$this->assertEquals(['name' => 'taylor'], array_only($array, ['name']));
125-
$this->assertSame([], array_only($array, ['nonExistingKey']));
125+
$this->assertEquals(['name' => 'taylor'], Arr::only($array, ['name']));
126+
$this->assertSame([], Arr::only($array, ['nonExistingKey']));
126127
}
127128

128129
public function testArrayCollapse()
@@ -142,15 +143,15 @@ public function testArrayDivide()
142143
public function testArrayFirst()
143144
{
144145
$array = ['name' => 'taylor', 'otherDeveloper' => 'dayle'];
145-
$this->assertEquals('dayle', array_first($array, function ($value) {
146+
$this->assertEquals('dayle', Arr::first($array, function ($value) {
146147
return $value == 'dayle';
147148
}));
148149
}
149150

150151
public function testArrayLast()
151152
{
152153
$array = [100, 250, 290, 320, 500, 560, 670];
153-
$this->assertEquals(670, array_last($array, function ($value) {
154+
$this->assertEquals(670, Arr::last($array, function ($value) {
154155
return $value > 320;
155156
}));
156157
}
@@ -185,25 +186,25 @@ public function testArrayPluck()
185186
'#baz',
186187
],
187188
],
188-
], array_pluck($data, 'comments'));
189+
], Arr::pluck($data, 'comments'));
189190

190-
$this->assertEquals([['#foo', '#bar'], ['#baz']], array_pluck($data, 'comments.tags'));
191-
$this->assertEquals([null, null], array_pluck($data, 'foo'));
192-
$this->assertEquals([null, null], array_pluck($data, 'foo.bar'));
191+
$this->assertEquals([['#foo', '#bar'], ['#baz']], Arr::pluck($data, 'comments.tags'));
192+
$this->assertEquals([null, null], Arr::pluck($data, 'foo'));
193+
$this->assertEquals([null, null], Arr::pluck($data, 'foo.bar'));
193194
}
194195

195196
public function testArrayPrepend()
196197
{
197-
$array = array_prepend(['one', 'two', 'three', 'four'], 'zero');
198+
$array = Arr::prepend(['one', 'two', 'three', 'four'], 'zero');
198199
$this->assertEquals(['zero', 'one', 'two', 'three', 'four'], $array);
199200

200-
$array = array_prepend(['one' => 1, 'two' => 2], 0, 'zero');
201+
$array = Arr::prepend(['one' => 1, 'two' => 2], 0, 'zero');
201202
$this->assertEquals(['zero' => 0, 'one' => 1, 'two' => 2], $array);
202203
}
203204

204205
public function testArrayFlatten()
205206
{
206-
$this->assertEquals(['#foo', '#bar', '#baz'], array_flatten([['#foo', '#bar'], ['#baz']]));
207+
$this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten([['#foo', '#bar'], ['#baz']]));
207208
}
208209

209210
public function testStrIs()
@@ -599,7 +600,7 @@ public function testArraySort()
599600
['name' => 'bar'],
600601
['name' => 'baz'],
601602
['name' => 'foo'], ],
602-
array_values(array_sort($array, function ($v) {
603+
array_values(Arr::sort($array, function ($v) {
603604
return $v['name'];
604605
})));
605606
}
@@ -632,13 +633,13 @@ public function testArraySortRecursive()
632633
],
633634
];
634635

635-
$this->assertEquals($assumedArray, array_sort_recursive($array));
636+
$this->assertEquals($assumedArray, Arr::sortRecursive($array));
636637
}
637638

638639
public function testArrayWhere()
639640
{
640641
$array = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8];
641-
$this->assertEquals(['b' => 2, 'd' => 4, 'f' => 6, 'h' => 8], array_where(
642+
$this->assertEquals(['b' => 2, 'd' => 4, 'f' => 6, 'h' => 8], Arr::where(
642643
$array,
643644
function ($value, $key) {
644645
return $value % 2 === 0;
@@ -652,9 +653,9 @@ public function testArrayWrap()
652653
$array = ['a'];
653654
$object = new stdClass;
654655
$object->value = 'a';
655-
$this->assertEquals(['a'], array_wrap($string));
656-
$this->assertEquals($array, array_wrap($array));
657-
$this->assertEquals([$object], array_wrap($object));
656+
$this->assertEquals(['a'], Arr::wrap($string));
657+
$this->assertEquals($array, Arr::wrap($array));
658+
$this->assertEquals([$object], Arr::wrap($object));
658659
}
659660

660661
public function testHead()
@@ -696,7 +697,7 @@ public function testArrayAdd()
696697
public function testArrayPull()
697698
{
698699
$developer = ['firstname' => 'Ferid', 'surname' => 'Mövsümov'];
699-
$this->assertEquals('Mövsümov', array_pull($developer, 'surname'));
700+
$this->assertEquals('Mövsümov', Arr::pull($developer, 'surname'));
700701
$this->assertEquals(['firstname' => 'Ferid'], $developer);
701702
}
702703

tests/Validation/ValidationValidatorTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DateTime;
66
use Mockery as m;
77
use Carbon\Carbon;
8+
use Illuminate\Support\Arr;
89
use PHPUnit\Framework\TestCase;
910
use Illuminate\Validation\Validator;
1011
use Illuminate\Validation\Rules\Exists;
@@ -432,7 +433,7 @@ public function testDisplayableAttributesAreReplacedInCustomReplacers()
432433
$trans->addLines(['validation.attributes.lastname' => 'Lastname'], 'en');
433434
$v = new Validator($trans, ['firstname' => 'Bob', 'lastname' => 'Smith'], ['lastname' => 'alliteration:firstname']);
434435
$v->addExtension('alliteration', function ($attribute, $value, $parameters, $validator) {
435-
$other = array_get($validator->getData(), $parameters[0]);
436+
$other = Arr::get($validator->getData(), $parameters[0]);
436437

437438
return $value[0] == $other[0];
438439
});
@@ -449,7 +450,7 @@ public function testDisplayableAttributesAreReplacedInCustomReplacers()
449450
$v = new Validator($trans, ['firstname' => 'Bob', 'lastname' => 'Smith'], ['lastname' => 'alliteration:firstname']);
450451
$v->addCustomAttributes($customAttributes);
451452
$v->addExtension('alliteration', function ($attribute, $value, $parameters, $validator) {
452-
$other = array_get($validator->getData(), $parameters[0]);
453+
$other = Arr::get($validator->getData(), $parameters[0]);
453454

454455
return $value[0] == $other[0];
455456
});
@@ -2572,7 +2573,7 @@ public function testCustomDependentValidators()
25722573
['*.name' => 'dependent_rule:*.age']
25732574
);
25742575
$v->addDependentExtension('dependent_rule', function ($name) use ($v) {
2575-
return array_get($v->getData(), $name) == 'Jamie';
2576+
return Arr::get($v->getData(), $name) == 'Jamie';
25762577
});
25772578
$this->assertTrue($v->passes());
25782579
}

0 commit comments

Comments
 (0)