Skip to content

Commit 3925878

Browse files
committed
[Style] Format Arr and SupportArrTest with Pint
1 parent 405a06a commit 3925878

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/Illuminate/Collections/Arr.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,34 +65,24 @@ public static function add($array, $key, $value)
6565
* Get an array item from an array using "dot" notation.
6666
*
6767
* @param \ArrayAccess|array $array
68-
* @param string|int|null $key
69-
* @param array|null $default
70-
* @param bool $throwOnNotFound
68+
* @param string|int|null $key
69+
* @param array|null $default
70+
* @param bool $throwOnNotFound
7171
* @return array
7272
*
7373
* @throws \InvalidArgumentException
7474
* @throws \Illuminate\Support\ItemNotFoundException
7575
*/
76-
public static function array(
77-
ArrayAccess|array $array,
78-
string|int|null $key,
79-
array $default = [],
80-
bool $throwOnNotFound = false
81-
): array {
82-
83-
if(! Arr::has($array, $key)){
84-
85-
if ($throwOnNotFound) {
86-
throw new ItemNotFoundException(
87-
sprintf('Array key [%s] not found.', $key)
88-
);
89-
}
76+
public static function array(ArrayAccess|array $array, string|int|null $key, array $default = [], bool $throwOnNotFound = false): array
77+
{
78+
$value = Arr::get($array, $key, $default);
9079

91-
return $default;
80+
if ($throwOnNotFound && $value === $default && ! Arr::has($array, $key)) {
81+
throw new ItemNotFoundException(
82+
sprintf('Array key [%s] not found.', $key)
83+
);
9284
}
9385

94-
$value = Arr::get($array, $key, $default);
95-
9686
if (! is_array($value)) {
9787
throw new InvalidArgumentException(
9888
sprintf('Array value for key [%s] must be an array, %s found.', $key, gettype($value))

tests/Support/SupportArrTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,6 @@ public function test_it_should_not_throw_when_key_exists_even_if_equal_to_defaul
724724
$this->assertSame([], $result); // expected to return the actual empty array
725725
}
726726

727-
728-
729727
public function testHas()
730728
{
731729
$array = ['products.desk' => ['price' => 100]];
@@ -1650,7 +1648,9 @@ public function testFrom()
16501648
$this->assertSame($subject, Arr::from($items));
16511649

16521650
$items = new WeakMap;
1653-
$items[$temp = new class {}] = 'bar';
1651+
$items[$temp = new class
1652+
{
1653+
}] = 'bar';
16541654
$this->assertSame(['bar'], Arr::from($items));
16551655

16561656
$this->expectException(InvalidArgumentException::class);

0 commit comments

Comments
 (0)