-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add finder depth configuration option (#15)
- Loading branch information
1 parent
413f33e
commit 259974d
Showing
11 changed files
with
118 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace FD\LogViewer\Util; | ||
|
||
class Arrays | ||
{ | ||
/** | ||
* @param array<int|string, mixed> $target | ||
* @param array<int|string, mixed> $source | ||
* | ||
* @return array<int|string, mixed> | ||
*/ | ||
public static function merge(array $target, array $source): array | ||
{ | ||
foreach ($source as $key => $value) { | ||
// if target key is not set, assign source value | ||
if (array_key_exists($key, $target) === false) { | ||
$target[$key] = $value; | ||
continue; | ||
} | ||
|
||
// recursively merge (non-list) arrays | ||
if (is_array($value) | ||
&& is_array($target[$key]) | ||
&& array_is_list($value) === false | ||
&& (count($target[$key]) === 0 || array_is_list($target[$key]) === false) | ||
) { | ||
$target[$key] = self::merge($target[$key], $value); | ||
} | ||
} | ||
|
||
return $target; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace FD\LogViewer\Tests\Unit\Util; | ||
|
||
use FD\LogViewer\Util\Arrays; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(Arrays::class)] | ||
class ArraysTest extends TestCase | ||
{ | ||
public function testMergeSingleDepth(): void | ||
{ | ||
static::assertSame(['foo' => 'bar'], Arrays::merge([], ['foo' => 'bar'])); | ||
static::assertSame(['foo' => 'bar'], Arrays::merge(['foo' => 'bar'], [])); | ||
static::assertSame(['foo' => 'bar'], Arrays::merge(['foo' => 'bar'], ['foo' => 'baz'])); | ||
} | ||
|
||
public function testMergeMultiDepth(): void | ||
{ | ||
static::assertSame( | ||
['foo' => ['bar' => ['baz' => 'qux']]], | ||
Arrays::merge(['foo' => []], ['foo' => ['bar' => ['baz' => 'qux']]]) | ||
); | ||
} | ||
|
||
public function testMergeMultiDepthLists(): void | ||
{ | ||
static::assertSame( | ||
['foo' => ['foo' => 'foo', 'bar' => ['baz', 'qux']]], | ||
Arrays::merge(['foo' => ['foo' => 'foo']], ['foo' => ['bar' => ['baz', 'qux']]]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters