t-kuni /
php-normalizer
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace TKuni\PhpNormalizer\Helper; |
||
| 5 | |||
| 6 | use Closure; |
||
| 7 | |||
| 8 | class DotChainOperator |
||
| 9 | { |
||
| 10 | 14 | public static function update($arr, $key, $val) |
|
| 11 | { |
||
| 12 | 14 | $separatedKeys = explode('.', $key); |
|
| 13 | 14 | if (is_callable($val)) { |
|
| 14 | 10 | self::_v($arr, $separatedKeys, $val); |
|
| 15 | } else { |
||
| 16 | self::_v($arr, $separatedKeys, function($in) use ($val) { |
||
|
0 ignored issues
–
show
|
|||
| 17 | 4 | return $val; |
|
| 18 | 4 | }); |
|
| 19 | } |
||
| 20 | |||
| 21 | 14 | return $arr; |
|
| 22 | } |
||
| 23 | |||
| 24 | 14 | private static function _v(&$arr, array $keys, Closure $filter, $i = 0) |
|
| 25 | { |
||
| 26 | 14 | if (empty($keys[$i])) { |
|
| 27 | 14 | $arr = $filter($arr); |
|
| 28 | 14 | return; |
|
| 29 | } |
||
| 30 | |||
| 31 | 14 | $currKey = $keys[$i]; |
|
| 32 | |||
| 33 | 14 | if ($currKey === '*') { |
|
| 34 | 10 | self::_h($arr, $keys, $filter, $i); |
|
| 35 | } else { |
||
| 36 | 14 | self::_v($arr[$currKey], $keys, $filter, $i + 1); |
|
| 37 | } |
||
| 38 | 14 | } |
|
| 39 | |||
| 40 | 10 | private static function _h(&$arr, array $keys, Closure $filter, $i) |
|
| 41 | { |
||
| 42 | 10 | foreach ($arr as &$item) { |
|
| 43 | 10 | self::_v($item, $keys, $filter, $i + 1); |
|
| 44 | } |
||
| 45 | } |
||
| 46 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.