Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e0561b0

Browse files
[*]: Minor improvements
1 parent af13b74 commit e0561b0

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

‎src/DotArray.php

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function ($match) {
130130
*/
131131
final protected static function wrapSegmentKey($key)
132132
{
133-
return vsprintf(self::WRAP_KEY, [$key]);
133+
return \vsprintf(self::WRAP_KEY, [$key]);
134134
}
135135

136136
/**
@@ -168,18 +168,11 @@ final protected static function flatten(array $items, $prepend = [])
168168

169169
foreach ($items as $key => $value) {
170170
if (\is_array($value) && !empty($value)) {
171-
$flatten = array_merge(
172-
$flatten,
173-
self::flatten(
174-
$value,
175-
array_merge($prepend, [$key])
176-
)
177-
);
178-
171+
$flatten = \array_merge($flatten, self::flatten($value, \array_merge($prepend, [$key])));
179172
continue;
180173
}
181174

182-
$segmentsToKey = self::segmentsToKey(array_merge($prepend, [$key]));
175+
$segmentsToKey = self::segmentsToKey(\array_merge($prepend, [$key]));
183176

184177
$flatten[$segmentsToKey] = $value;
185178
}
@@ -291,12 +284,7 @@ public function merge($array)
291284
[
292285
$this, 'mergeRecursive',
293286
],
294-
\array_values(
295-
\array_merge(
296-
[$this->items],
297-
\func_get_args()
298-
)
299-
)
287+
\array_values(\array_merge([$this->items], \func_get_args()))
300288
);
301289

302290
return $this;
@@ -314,10 +302,7 @@ protected function &read($key = null, $default = null)
314302
$items = &$this->items;
315303

316304
foreach ($segments as $segment) {
317-
if (
318-
!\is_array($items)
319-
|| !\array_key_exists($segment, $items)
320-
) {
305+
if (!\is_array($items) || !\array_key_exists($segment, $items)) {
321306
return $default;
322307
}
323308

@@ -381,12 +366,10 @@ protected function remove($key)
381366
for ($i = 0; $i < $count; $i++) {
382367
$segment = $segments[$i];
383368

384-
// Nothing to unset.
385369
if (!\array_key_exists($segment, $items)) {
386370
break;
387371
}
388372

389-
// Last item, time to unset.
390373
if ($i === ($count - 1)) {
391374
unset($items[$segment]);
392375
break;
@@ -417,9 +400,7 @@ public function has($key)
417400
*/
418401
public function isEmpty($key = null)
419402
{
420-
$items = $this->read($key, null);
421-
422-
return empty($items);
403+
return empty($this->read($key, null));
423404
}
424405

425406
/**
@@ -497,14 +478,13 @@ public function clear($keys = null, $value = [])
497478

498479
/**
499480
* Returning the first value from the current array.
481+
* False otherwise, in case the list is empty.
500482
*
501483
* @return mixed
502484
*/
503485
public function first()
504486
{
505-
$items = $this->items;
506-
507-
return \array_shift($items);
487+
return \reset($this->items);
508488
}
509489

510490
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /