1 | <?php |
||
6 | class Accessor |
||
7 | { |
||
8 | /** |
||
9 | * get value from an array or an object. |
||
10 | * |
||
11 | * @param array|object $data |
||
12 | * @param string $key |
||
13 | * @param mixed $default |
||
14 | * @return mixed |
||
15 | */ |
||
16 | public static function get($data, $key, $default = null) |
||
27 | |||
28 | /** |
||
29 | * @param mixed $data |
||
30 | * @return bool |
||
31 | */ |
||
32 | public static function isArrayAccess($data) |
||
42 | |||
43 | /** |
||
44 | * @param array|ArrayAccess $data |
||
45 | * @param string $key |
||
46 | * @param null $default |
||
47 | * @return mixed |
||
48 | */ |
||
49 | public static function getArray($data, $key, $default = null) |
||
53 | |||
54 | /** |
||
55 | * @param object $data |
||
56 | * @param string $key |
||
57 | * @param null $default |
||
58 | * @return mixed |
||
59 | */ |
||
60 | public static function getObj($data, $key, $default = null) |
||
79 | |||
80 | /** |
||
81 | * check if $data has a $key. |
||
82 | * $data can be an array or an object. |
||
83 | * |
||
84 | * @param array|object $data |
||
85 | * @param string $key |
||
86 | * @return bool |
||
87 | */ |
||
88 | public static function has($data, $key) |
||
108 | } |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.