1 | <?php |
||
48 | class IsEmpty |
||
49 | { |
||
50 | /** |
||
51 | * check if an item is empty |
||
52 | * |
||
53 | * empty means one of: |
||
54 | * - item itself is empty |
||
55 | * - item is a data container, and only contains empty data items |
||
56 | * |
||
57 | * BE AWARE that this check WILL descend down into the contents of $item |
||
58 | * until it finds the first piece of non-empty data. This has the potential |
||
59 | * to be computationally expensive. |
||
60 | * |
||
61 | * @param mixed $item |
||
62 | * the item to check |
||
63 | * @return boolean |
||
64 | * TRUE if the item is empty |
||
65 | * FALSE otherwise |
||
66 | */ |
||
67 | public function __invoke($item) |
||
71 | |||
72 | /** |
||
73 | * check if an item is empty |
||
74 | * |
||
75 | * empty means one of: |
||
76 | * - item itself is empty |
||
77 | * - item is a data container, and only contains empty data items |
||
78 | * |
||
79 | * BE AWARE that this check WILL descend down into the contents of $item |
||
80 | * until it finds the first piece of non-empty data. This has the potential |
||
81 | * to be computationally expensive. |
||
82 | * |
||
83 | * @param mixed $item |
||
84 | * the item to check |
||
85 | * @return boolean |
||
86 | * TRUE if the item is empty |
||
87 | * FALSE otherwise |
||
88 | */ |
||
89 | public static function check($item) |
||
94 | |||
95 | /** |
||
96 | * a list of the data types that we support, and how to process each |
||
97 | * supported data type |
||
98 | * |
||
99 | * @var array |
||
100 | */ |
||
101 | private static $dispatchMap = [ |
||
102 | 'Array' => 'checkArray', |
||
103 | 'NULL' => 'checkNull', |
||
104 | 'String' => 'checkString', |
||
105 | 'Traversable' => 'checkTraversable' |
||
106 | ]; |
||
107 | |||
108 | /** |
||
109 | * called when we have a data type that we do not know how to support |
||
110 | * |
||
111 | * @param mixed $item |
||
112 | * the unsupported data |
||
113 | * @return boolean |
||
114 | * always FALSE |
||
115 | */ |
||
116 | private static function nothingMatchesTheInputType($item) |
||
124 | |||
125 | /** |
||
126 | * check if an item is empty |
||
127 | * |
||
128 | * empty means one of: |
||
129 | * - item itself has no content |
||
130 | * - item is a data container, and only contains empty data items |
||
131 | * |
||
132 | * BE AWARE that this check WILL descend down into the contents of $item |
||
133 | * until it finds the first piece of non-empty data. This has the potential |
||
134 | * to be computationally expensive. |
||
135 | * |
||
136 | * @param array $item |
||
137 | * the item to check |
||
138 | * @return boolean |
||
139 | * TRUE if the item is empty |
||
140 | * FALSE otherwise |
||
141 | */ |
||
142 | private static function checkArray($item) |
||
150 | |||
151 | /** |
||
152 | * check if an item is empty |
||
153 | * |
||
154 | * NULL is always treated as an empty value |
||
155 | * |
||
156 | * @param null $item |
||
157 | * the item to check |
||
158 | * @return boolean |
||
159 | * always TRUE |
||
160 | */ |
||
161 | private static function checkNull($item) |
||
165 | |||
166 | /** |
||
167 | * check if an item is empty |
||
168 | * |
||
169 | * empty means one of: |
||
170 | * - the string has zero length |
||
171 | * - the string only contains whitespace |
||
172 | * |
||
173 | * @param string $item |
||
174 | * the item to check |
||
175 | * @return boolean |
||
176 | * TRUE if the item is empty |
||
177 | * FALSE otherwise |
||
178 | */ |
||
179 | private static function checkString($item) |
||
187 | |||
188 | /** |
||
189 | * check if an item is empty |
||
190 | * |
||
191 | * empty means one of: |
||
192 | * - item itself has no content |
||
193 | * - item is a data container, and only contains empty data items |
||
194 | * |
||
195 | * BE AWARE that this check WILL descend down into the contents of $item |
||
196 | * until it finds the first piece of non-empty data. This has the potential |
||
197 | * to be computationally expensive. |
||
198 | * |
||
199 | * @param array $item |
||
200 | * the item to check |
||
201 | * @return boolean |
||
202 | * TRUE if the item is empty |
||
203 | * FALSE otherwise |
||
204 | */ |
||
205 | private static function checkTraversable($item) |
||
216 | } |
||
217 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.