1 | <?php |
||
53 | class DoesArrayHaveKey implements Check, ListCheck |
||
54 | { |
||
55 | // saves us having to implement inspectList() ourselves |
||
56 | use ListCheckHelper; |
||
57 | |||
58 | /** |
||
59 | * the array key that we are looking for |
||
60 | * |
||
61 | * @var string|int |
||
62 | */ |
||
63 | private $expectedKey; |
||
64 | |||
65 | /** |
||
66 | * create a Check that is ready to use |
||
67 | * |
||
68 | * @param string|int $expectedKey |
||
69 | * the array key that we are looking for |
||
70 | */ |
||
71 | public function __construct($expectedKey) |
||
75 | |||
76 | /** |
||
77 | * does the supplied array contain the key we want? |
||
78 | * |
||
79 | * @param array $data |
||
80 | * the array to be checked |
||
81 | * @param string|int $key |
||
82 | * the array index we are looking for |
||
83 | * @return bool |
||
84 | * TRUE if $data[$key] exists |
||
85 | * FALSE otherwise |
||
86 | */ |
||
87 | public static function check(array $data, $key) : bool |
||
91 | |||
92 | /** |
||
93 | * does the supplied array contain the key we want? |
||
94 | * |
||
95 | * @param array $data |
||
96 | * the array to be checked |
||
97 | * @return bool |
||
98 | * TRUE if $data[$key] exists |
||
99 | * FALSE otherwise |
||
100 | */ |
||
101 | public function inspect($data) |
||
106 | |||
107 | /** |
||
108 | * does the supplied array contain the key we want? |
||
109 | * |
||
110 | * @param array|Traversable $list |
||
111 | * the item to be checked |
||
112 | * @return bool |
||
113 | * TRUE if the array key we are looking for exists in every |
||
114 | * item in $list |
||
115 | * FALSE otherwise |
||
116 | */ |
||
117 | public static function checkList($list, $expectedKey) : bool |
||
123 | } |