Skip to content

Commit 557a715

Browse files
committed
Improve structures provider
1 parent da677dc commit 557a715

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Lodash/Testing/DataStructuresProvider.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,35 @@
55
namespace Longman\LaravelLodash\Testing;
66

77
use InvalidArgumentException;
8+
use Longman\LaravelLodash\Support\Str;
89

910
use function array_shift;
11+
use function call_user_func_array;
1012
use function explode;
13+
use function get_called_class;
1114
use function is_callable;
15+
use function lcfirst;
16+
use function property_exists;
1217
use function str_contains;
1318
use function str_starts_with;
1419
use function trim;
1520

1621
abstract class DataStructuresProvider
1722
{
23+
public static function __callStatic(string $name, array $arguments): mixed
24+
{
25+
$property = lcfirst(Str::substr($name, 3));
26+
if (! property_exists(get_called_class(), $property)) {
27+
throw new InvalidArgumentException('Property "' . $property . '" does not exists');
28+
}
29+
$structure = static::$$property;
30+
31+
$parameters = [&$structure, $arguments[0] ?? []];
32+
call_user_func_array([get_called_class(), 'includeNestedRelations'], $parameters);
33+
34+
return $structure;
35+
}
36+
1837
protected static function includeNestedRelations(array &$item, array $relations): void
1938
{
2039
if (empty($relations)) {

0 commit comments

Comments
 (0)