| Total Complexity | 8 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | trait HelpsLoopFunctions |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Assign the value to the property or rescue. |
||
| 11 | * |
||
| 12 | * @param int|string $key |
||
| 13 | * @param mixed $value |
||
| 14 | * @param mixed|null $rescue |
||
| 15 | * |
||
| 16 | * @return void |
||
| 17 | */ |
||
| 18 | 5 | private function assignValue(int|string $key, mixed $value, mixed $rescue = null): void |
|
| 19 | { |
||
| 20 | 5 | if ($this->canAssignValue($key)) { |
|
| 21 | 5 | rescue( |
|
| 22 | 5 | fn () => ! empty($this->{$key}) ?: $this->{$key} = $value, |
|
| 23 | $rescue, |
||
| 24 | 5 | config('loop-functions.log') ?? false |
|
| 25 | ); |
||
| 26 | } |
||
| 27 | 5 | } |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @return array |
||
| 31 | */ |
||
| 32 | 13 | private function ignoreKeys(): array |
|
| 33 | { |
||
| 34 | 13 | $defaults = ['id', 'password']; |
|
| 35 | |||
| 36 | 13 | $ignores = config('loop-functions.ignore_keys', $defaults); |
|
| 37 | |||
| 38 | 13 | return is_array($ignores) |
|
| 39 | 13 | ? $ignores |
|
| 40 | 13 | : $defaults; |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Check if the function can walk recursively over an array. |
||
| 45 | * |
||
| 46 | * @param mixed $value |
||
| 47 | * |
||
| 48 | * @return bool |
||
| 49 | */ |
||
| 50 | 5 | private function canWalkRecursively(mixed $value): bool |
|
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param int|string $key |
||
| 57 | * |
||
| 58 | * @return bool |
||
| 59 | */ |
||
| 60 | 5 | private function canAssignValue(int|string $key): bool |
|
| 63 | } |
||
| 64 | } |
||
| 65 |