| Total Complexity | 12 |
| Total Lines | 76 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | class ArrayHelper extends \craft\helpers\ArrayHelper |
||
| 20 | { |
||
| 21 | // Public Static Methods |
||
| 22 | // ========================================================================= |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param array $array |
||
| 26 | * @param callable $callback |
||
| 27 | * |
||
| 28 | * @return array |
||
| 29 | */ |
||
| 30 | public static function arrayFilterRecursive(array $array, callable $callback): array |
||
| 31 | { |
||
| 32 | foreach ($array as $k => $v) { |
||
| 33 | if (\is_array($v)) { |
||
| 34 | $array[$k] = self::arrayFilterRecursive($v, $callback); |
||
| 35 | } else { |
||
| 36 | if ($callback($v, $k)) { |
||
| 37 | unset($array[$k]); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | return $array; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Used as a callback for array_filter to preserve any boolean values |
||
| 47 | * that are in the array being filtered |
||
| 48 | * |
||
| 49 | * @param $value |
||
| 50 | * |
||
| 51 | * @return bool |
||
| 52 | */ |
||
| 53 | public static function preserveBools($value): bool |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Used as a callback for array_filter to preserve any numeric values |
||
| 60 | * that are in the array being filtered |
||
| 61 | * |
||
| 62 | * @param $value |
||
| 63 | * |
||
| 64 | * @return bool |
||
| 65 | */ |
||
| 66 | public static function preserveNumerics($value): bool |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param $value |
||
| 73 | * @param $key |
||
| 74 | * |
||
| 75 | * @return bool |
||
| 76 | */ |
||
| 77 | public static function unsetEmptyChildren($value, $key): bool |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param $value |
||
| 88 | * @param $key |
||
| 89 | * |
||
| 90 | * @return bool |
||
| 91 | */ |
||
| 92 | public static function unsetNullChildren($value, $key): bool |
||
| 97 |