1 | <?php |
||
10 | class Field |
||
11 | { |
||
12 | const DATE_REGEX = '/^\d{2}\-\d{2}\-\d{4}$/'; |
||
13 | |||
14 | const VALUE_STRING = 'fvalueString'; |
||
15 | const VALUE_INT = 'fvalueInt'; |
||
16 | const VALUE_FLOAT = 'fvalueFloat'; |
||
17 | const VALUE_IMAGE = 'fvalueImage'; |
||
18 | const VALUE_DATETIME = 'fvalueDatetime'; |
||
19 | const VALUE_DATE = 'fvalueDate'; |
||
20 | const VALUE_RANGE_INT = 'fvalueRangeInt'; |
||
21 | const VALUE_RANGE_FLOAT = 'fvalueRangeFloat'; |
||
22 | const VALUE_RANGE_DATE = 'fvalueRangeDate'; |
||
23 | |||
24 | const DEFAULT_STRING = ''; |
||
25 | const DEFAULT_INT = 0; |
||
26 | const DEFAULT_FLOAT = 0; |
||
27 | const DEFAULT_IMAGE = ''; |
||
28 | const DEFAULT_DATETIME = 0; |
||
29 | const DEFAULT_DATE = ''; |
||
30 | |||
31 | /** |
||
32 | * Allegro WebAPI fid |
||
33 | * @var integer |
||
34 | */ |
||
35 | protected $fid = null; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * array of fValues of this Field |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $fValues = []; |
||
43 | |||
44 | |||
45 | /** |
||
46 | * @param integer $fid WebAPI fid for given field |
||
47 | * @param mixed $value value for given field |
||
48 | * @param string $forceValueType value type to force (i.e. fvalueImage) |
||
49 | */ |
||
50 | 30 | public function __construct($fid = 0, $value = null, $forceValueType = '') |
|
69 | |||
70 | |||
71 | /** |
||
72 | * Default values, "empty" WebAPI fields item |
||
73 | * @return array |
||
74 | */ |
||
75 | 29 | protected function getDefaults() |
|
98 | |||
99 | |||
100 | /** |
||
101 | * Set fid of this Field |
||
102 | * @param integer $fid |
||
103 | */ |
||
104 | 30 | public function setFid($fid) |
|
111 | |||
112 | |||
113 | /** |
||
114 | * Set value to fValue index of corresponding type |
||
115 | * @param mixed $value |
||
116 | */ |
||
117 | 19 | protected function setValueAutodetect($value) |
|
131 | |||
132 | |||
133 | /** |
||
134 | * Detect type of string value (date or normal string) |
||
135 | * @param string $value value to detect type |
||
136 | */ |
||
137 | 9 | protected function setValueStringAutodetect($value) |
|
145 | |||
146 | |||
147 | /** |
||
148 | * Detect type of range passed as argument (int, float, date) |
||
149 | * @param array $value value to detect type of |
||
|
|||
150 | */ |
||
151 | 7 | protected function setValueRangeAutodetect(array $range) |
|
168 | |||
169 | |||
170 | /** |
||
171 | * Sets float range values from given array |
||
172 | * @param array $range array of two float values |
||
173 | */ |
||
174 | 2 | protected function setRangeFloat(array $range) |
|
182 | |||
183 | |||
184 | /** |
||
185 | * Sets int range values from given array |
||
186 | * @param array $range array of two int values |
||
187 | */ |
||
188 | 2 | protected function setRangeInt(array $range) |
|
196 | |||
197 | |||
198 | /** |
||
199 | * Sets date range values from given array |
||
200 | * @param array $range array of two date values |
||
201 | */ |
||
202 | 2 | protected function setRangeDate(array $range) |
|
212 | |||
213 | |||
214 | /** |
||
215 | * Checks if given range is float |
||
216 | * @param array $range range to check |
||
217 | * @return boolean |
||
218 | */ |
||
219 | 6 | protected function isRangeFloat(array $range) |
|
224 | |||
225 | |||
226 | /** |
||
227 | * Checks if given range is int |
||
228 | * @param array $range range to check |
||
229 | * @return boolean |
||
230 | */ |
||
231 | 4 | protected function isRangeInt(array $range) |
|
236 | |||
237 | |||
238 | /** |
||
239 | * Checks if given range is date |
||
240 | * @param array $range range to check |
||
241 | * @return boolean |
||
242 | */ |
||
243 | public function isRangeDate(array $range) |
||
251 | |||
252 | |||
253 | /** |
||
254 | * Set value of arbitrary type |
||
255 | * @param string $forceValueType type ('fvalueString', 'fvalueInt', ...) |
||
256 | * @param mixed $value to set |
||
257 | */ |
||
258 | 3 | protected function setValueForced($forceValueType, $value) |
|
266 | |||
267 | |||
268 | /** |
||
269 | * Returns WebAPI representation of Field |
||
270 | * @return array field |
||
271 | */ |
||
272 | 17 | public function toArray() |
|
277 | |||
278 | |||
279 | /** |
||
280 | * Creates object from WebAPI representation of Field |
||
281 | */ |
||
282 | 8 | public function fromArray(array $array) |
|
302 | |||
303 | |||
304 | /** |
||
305 | * Return field fid |
||
306 | * @return integer |
||
307 | */ |
||
308 | 6 | public function getFid() |
|
312 | |||
313 | |||
314 | /** |
||
315 | * Return first property that is different from its default value |
||
316 | * @return mixed | null |
||
317 | */ |
||
318 | 17 | public function getValue() |
|
332 | |||
333 | |||
334 | } |
||
335 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.