Completed
Push — master ( e1ba59...cb8392 )
by Dimas
07:55
created

array_keys_exists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
if (isset($_REQUEST['list-user'])) {
4
  $list = pdo()->select('userdata')->row_array();
5
6
  e(array_filter_recursive($list, ['password']));
0 ignored issues
show
Bug introduced by
It seems like $list can also be of type null; however, parameter $array of array_filter_recursive() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

6
  e(array_filter_recursive(/** @scrutinizer ignore-type */ $list, ['password']));
Loading history...
7
}
8
9
/**
10
 * ```php
11
 * array_filter_recursive(['password'=>'secret_password', 'username'=>'any'], ['password']); //will return without password
12
 * ```
13
 * Array filter recursive
14
 *
15
 * @param array $array
16
 * @param array $filterdata
17
 * @return array
18
 */
19
function array_filter_recursive(array $array, array $filterdata)
20
{
21
  if (\ArrayHelper\helper::isSequent($array)) {
22
    return array_map(function ($single) use ($filterdata) {
23
      foreach ($filterdata as $filter) {
24
        if (isset($single[$filter])) {
25
          unset($single[$filter]);
26
        }
27
      }
28
      return $single;
29
    }, $array);
30
  }
31
}
32
33
/**
34
 * Check multiple array keys exists
35
 *
36
 * @param array $keys
37
 * @param array $arr
38
 * @return bool
39
 */
40
function array_keys_exists(array $keys, array $arr)
41
{
42
  return !array_diff_key(array_flip($keys), $arr);
43
}
44