@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | * @param mixed $value |
17 | 17 | * @return \AppUtils\NumberInfo |
18 | 18 | */ |
19 | -function parseNumber($value, $forceNew=false) |
|
19 | +function parseNumber($value, $forceNew = false) |
|
20 | 20 | { |
21 | - if($value instanceof NumberInfo && $forceNew !== true) { |
|
21 | + if ($value instanceof NumberInfo && $forceNew !== true) { |
|
22 | 22 | return $value; |
23 | 23 | } |
24 | 24 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $args = func_get_args(); |
100 | 100 | |
101 | 101 | // is the localization package installed? |
102 | - if(class_exists('\AppLocalize\Localization')) |
|
102 | + if (class_exists('\AppLocalize\Localization')) |
|
103 | 103 | { |
104 | 104 | return call_user_func_array('\AppLocalize\t', $args); |
105 | 105 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function requireCURL() : void |
119 | 119 | { |
120 | - if(function_exists('curl_init')) { |
|
120 | + if (function_exists('curl_init')) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | function init() |
137 | 137 | { |
138 | - if(!class_exists('\AppLocalize\Localization')) { |
|
138 | + if (!class_exists('\AppLocalize\Localization')) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 |
@@ -39,42 +39,42 @@ discard block |
||
39 | 39 | const TYPE_PHONE = 'phone'; |
40 | 40 | const TYPE_URL = 'url'; |
41 | 41 | |
42 | - /** |
|
43 | - * The original URL that was passed to the constructor. |
|
44 | - * @var string |
|
45 | - */ |
|
42 | + /** |
|
43 | + * The original URL that was passed to the constructor. |
|
44 | + * @var string |
|
45 | + */ |
|
46 | 46 | protected $rawURL; |
47 | 47 | |
48 | - /** |
|
49 | - * @var array |
|
50 | - */ |
|
48 | + /** |
|
49 | + * @var array |
|
50 | + */ |
|
51 | 51 | protected $info; |
52 | 52 | |
53 | - /** |
|
54 | - * @var string[] |
|
55 | - */ |
|
53 | + /** |
|
54 | + * @var string[] |
|
55 | + */ |
|
56 | 56 | protected $excludedParams = array(); |
57 | 57 | |
58 | - /** |
|
59 | - * @var bool |
|
60 | - * @see URLInfo::setParamExclusion() |
|
61 | - */ |
|
58 | + /** |
|
59 | + * @var bool |
|
60 | + * @see URLInfo::setParamExclusion() |
|
61 | + */ |
|
62 | 62 | protected $paramExclusion = false; |
63 | 63 | |
64 | - /** |
|
65 | - * @var array |
|
66 | - * @see URLInfo::getTypeLabel() |
|
67 | - */ |
|
64 | + /** |
|
65 | + * @var array |
|
66 | + * @see URLInfo::getTypeLabel() |
|
67 | + */ |
|
68 | 68 | protected static $typeLabels; |
69 | 69 | |
70 | - /** |
|
71 | - * @var bool |
|
72 | - */ |
|
70 | + /** |
|
71 | + * @var bool |
|
72 | + */ |
|
73 | 73 | protected $highlightExcluded = false; |
74 | 74 | |
75 | - /** |
|
76 | - * @var array |
|
77 | - */ |
|
75 | + /** |
|
76 | + * @var array |
|
77 | + */ |
|
78 | 78 | protected $infoKeys = array( |
79 | 79 | 'scheme', |
80 | 80 | 'host', |
@@ -86,19 +86,19 @@ discard block |
||
86 | 86 | 'fragment' |
87 | 87 | ); |
88 | 88 | |
89 | - /** |
|
90 | - * @var string |
|
91 | - */ |
|
89 | + /** |
|
90 | + * @var string |
|
91 | + */ |
|
92 | 92 | protected $url; |
93 | 93 | |
94 | - /** |
|
95 | - * @var URLInfo_Parser |
|
96 | - */ |
|
94 | + /** |
|
95 | + * @var URLInfo_Parser |
|
96 | + */ |
|
97 | 97 | protected $parser; |
98 | 98 | |
99 | - /** |
|
100 | - * @var URLInfo_Normalizer |
|
101 | - */ |
|
99 | + /** |
|
100 | + * @var URLInfo_Normalizer |
|
101 | + */ |
|
102 | 102 | protected $normalizer; |
103 | 103 | |
104 | 104 | public function __construct(string $url) |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | $this->info = $this->parser->getInfo(); |
111 | 111 | } |
112 | 112 | |
113 | - /** |
|
114 | - * Filters an URL: removes control characters and the |
|
115 | - * like to have a clean URL to work with. |
|
116 | - * |
|
117 | - * @param string $url |
|
118 | - * @return string |
|
119 | - */ |
|
113 | + /** |
|
114 | + * Filters an URL: removes control characters and the |
|
115 | + * like to have a clean URL to work with. |
|
116 | + * |
|
117 | + * @param string $url |
|
118 | + * @return string |
|
119 | + */ |
|
120 | 120 | public static function filterURL(string $url) |
121 | 121 | { |
122 | 122 | return URLInfo_Filter::filter($url); |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | return $this->info['type'] === self::TYPE_PHONE; |
147 | 147 | } |
148 | 148 | |
149 | - /** |
|
150 | - * Whether the URL is a regular URL, not one of the |
|
151 | - * other types like a phone number or email address. |
|
152 | - * |
|
153 | - * @return bool |
|
154 | - */ |
|
149 | + /** |
|
150 | + * Whether the URL is a regular URL, not one of the |
|
151 | + * other types like a phone number or email address. |
|
152 | + * |
|
153 | + * @return bool |
|
154 | + */ |
|
155 | 155 | public function isURL() : bool |
156 | 156 | { |
157 | 157 | $host = $this->getHost(); |
@@ -163,20 +163,20 @@ discard block |
||
163 | 163 | return $this->parser->isValid(); |
164 | 164 | } |
165 | 165 | |
166 | - /** |
|
167 | - * Retrieves the host name, or an empty string if none is present. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
166 | + /** |
|
167 | + * Retrieves the host name, or an empty string if none is present. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | 171 | public function getHost() : string |
172 | 172 | { |
173 | 173 | return $this->getInfoKey('host'); |
174 | 174 | } |
175 | 175 | |
176 | - /** |
|
177 | - * Retrieves the path, or an empty string if none is present. |
|
178 | - * @return string |
|
179 | - */ |
|
176 | + /** |
|
177 | + * Retrieves the path, or an empty string if none is present. |
|
178 | + * @return string |
|
179 | + */ |
|
180 | 180 | public function getPath() : string |
181 | 181 | { |
182 | 182 | return $this->getInfoKey('path'); |
@@ -192,10 +192,10 @@ discard block |
||
192 | 192 | return $this->getInfoKey('scheme'); |
193 | 193 | } |
194 | 194 | |
195 | - /** |
|
196 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
197 | - * @return int |
|
198 | - */ |
|
195 | + /** |
|
196 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
197 | + * @return int |
|
198 | + */ |
|
199 | 199 | public function getPort() : int |
200 | 200 | { |
201 | 201 | $port = $this->getInfoKey('port'); |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | return -1; |
208 | 208 | } |
209 | 209 | |
210 | - /** |
|
211 | - * Retrieves the raw query string, or an empty string if none is present. |
|
212 | - * |
|
213 | - * @return string |
|
214 | - * |
|
215 | - * @see URLInfo::getParams() |
|
216 | - */ |
|
210 | + /** |
|
211 | + * Retrieves the raw query string, or an empty string if none is present. |
|
212 | + * |
|
213 | + * @return string |
|
214 | + * |
|
215 | + * @see URLInfo::getParams() |
|
216 | + */ |
|
217 | 217 | public function getQuery() : string |
218 | 218 | { |
219 | 219 | return $this->getInfoKey('query'); |
@@ -229,20 +229,20 @@ discard block |
||
229 | 229 | return $this->getInfoKey('pass'); |
230 | 230 | } |
231 | 231 | |
232 | - /** |
|
233 | - * Whether the URL contains a port number. |
|
234 | - * @return bool |
|
235 | - */ |
|
232 | + /** |
|
233 | + * Whether the URL contains a port number. |
|
234 | + * @return bool |
|
235 | + */ |
|
236 | 236 | public function hasPort() : bool |
237 | 237 | { |
238 | 238 | return $this->getPort() !== -1; |
239 | 239 | } |
240 | 240 | |
241 | - /** |
|
242 | - * Alias for the hasParams() method. |
|
243 | - * @return bool |
|
244 | - * @see URLInfo::hasParams() |
|
245 | - */ |
|
241 | + /** |
|
242 | + * Alias for the hasParams() method. |
|
243 | + * @return bool |
|
244 | + * @see URLInfo::hasParams() |
|
245 | + */ |
|
246 | 246 | public function hasQuery() : bool |
247 | 247 | { |
248 | 248 | return $this->hasParams(); |
@@ -300,25 +300,25 @@ discard block |
||
300 | 300 | return $this->normalizer->normalize(); |
301 | 301 | } |
302 | 302 | |
303 | - /** |
|
304 | - * Creates a hash of the URL, which can be used for comparisons. |
|
305 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
306 | - * the same links with a different parameter order will have the |
|
307 | - * same hash. |
|
308 | - * |
|
309 | - * @return string |
|
310 | - */ |
|
303 | + /** |
|
304 | + * Creates a hash of the URL, which can be used for comparisons. |
|
305 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
306 | + * the same links with a different parameter order will have the |
|
307 | + * same hash. |
|
308 | + * |
|
309 | + * @return string |
|
310 | + */ |
|
311 | 311 | public function getHash() |
312 | 312 | { |
313 | 313 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
314 | 314 | } |
315 | 315 | |
316 | - /** |
|
317 | - * Highlights the URL using HTML tags with specific highlighting |
|
318 | - * class names. |
|
319 | - * |
|
320 | - * @return string Will return an empty string if the URL is not valid. |
|
321 | - */ |
|
316 | + /** |
|
317 | + * Highlights the URL using HTML tags with specific highlighting |
|
318 | + * class names. |
|
319 | + * |
|
320 | + * @return string Will return an empty string if the URL is not valid. |
|
321 | + */ |
|
322 | 322 | public function getHighlighted() : string |
323 | 323 | { |
324 | 324 | if(!$this->isValid()) { |
@@ -352,15 +352,15 @@ discard block |
||
352 | 352 | return count($params); |
353 | 353 | } |
354 | 354 | |
355 | - /** |
|
356 | - * Retrieves all parameters specified in the url, |
|
357 | - * if any, as an associative array. |
|
358 | - * |
|
359 | - * NOTE: Ignores parameters that have been added |
|
360 | - * to the excluded parameters list. |
|
361 | - * |
|
362 | - * @return array |
|
363 | - */ |
|
355 | + /** |
|
356 | + * Retrieves all parameters specified in the url, |
|
357 | + * if any, as an associative array. |
|
358 | + * |
|
359 | + * NOTE: Ignores parameters that have been added |
|
360 | + * to the excluded parameters list. |
|
361 | + * |
|
362 | + * @return array |
|
363 | + */ |
|
364 | 364 | public function getParams() : array |
365 | 365 | { |
366 | 366 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -378,22 +378,22 @@ discard block |
||
378 | 378 | return $keep; |
379 | 379 | } |
380 | 380 | |
381 | - /** |
|
382 | - * Retrieves the names of all parameters present in the URL, if any. |
|
383 | - * @return string[] |
|
384 | - */ |
|
381 | + /** |
|
382 | + * Retrieves the names of all parameters present in the URL, if any. |
|
383 | + * @return string[] |
|
384 | + */ |
|
385 | 385 | public function getParamNames() : array |
386 | 386 | { |
387 | 387 | $params = $this->getParams(); |
388 | 388 | return array_keys($params); |
389 | 389 | } |
390 | 390 | |
391 | - /** |
|
392 | - * Retrieves a specific parameter value from the URL. |
|
393 | - * |
|
394 | - * @param string $name |
|
395 | - * @return string The parameter value, or an empty string if it does not exist. |
|
396 | - */ |
|
391 | + /** |
|
392 | + * Retrieves a specific parameter value from the URL. |
|
393 | + * |
|
394 | + * @param string $name |
|
395 | + * @return string The parameter value, or an empty string if it does not exist. |
|
396 | + */ |
|
397 | 397 | public function getParam(string $name) : string |
398 | 398 | { |
399 | 399 | if(isset($this->info['params'][$name])) { |
@@ -403,16 +403,16 @@ discard block |
||
403 | 403 | return ''; |
404 | 404 | } |
405 | 405 | |
406 | - /** |
|
407 | - * Excludes an URL parameter entirely if present: |
|
408 | - * the parser will act as if the parameter was not |
|
409 | - * even present in the source URL, effectively |
|
410 | - * stripping it. |
|
411 | - * |
|
412 | - * @param string $name |
|
413 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
414 | - * @return URLInfo |
|
415 | - */ |
|
406 | + /** |
|
407 | + * Excludes an URL parameter entirely if present: |
|
408 | + * the parser will act as if the parameter was not |
|
409 | + * even present in the source URL, effectively |
|
410 | + * stripping it. |
|
411 | + * |
|
412 | + * @param string $name |
|
413 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
414 | + * @return URLInfo |
|
415 | + */ |
|
416 | 416 | public function excludeParam(string $name, string $reason) : URLInfo |
417 | 417 | { |
418 | 418 | if(!isset($this->excludedParams[$name])) |
@@ -465,25 +465,25 @@ discard block |
||
465 | 465 | return self::$typeLabels[$this->getType()]; |
466 | 466 | } |
467 | 467 | |
468 | - /** |
|
469 | - * Whether excluded parameters should be highlighted in |
|
470 | - * a different color in the URL when using the |
|
471 | - * {@link URLInfo::getHighlighted()} method. |
|
472 | - * |
|
473 | - * @param bool $highlight |
|
474 | - * @return URLInfo |
|
475 | - */ |
|
468 | + /** |
|
469 | + * Whether excluded parameters should be highlighted in |
|
470 | + * a different color in the URL when using the |
|
471 | + * {@link URLInfo::getHighlighted()} method. |
|
472 | + * |
|
473 | + * @param bool $highlight |
|
474 | + * @return URLInfo |
|
475 | + */ |
|
476 | 476 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
477 | 477 | { |
478 | 478 | $this->highlightExcluded = $highlight; |
479 | 479 | return $this; |
480 | 480 | } |
481 | 481 | |
482 | - /** |
|
483 | - * Returns an array with all relevant URL information. |
|
484 | - * |
|
485 | - * @return array |
|
486 | - */ |
|
482 | + /** |
|
483 | + * Returns an array with all relevant URL information. |
|
484 | + * |
|
485 | + * @return array |
|
486 | + */ |
|
487 | 487 | public function toArray() : array |
488 | 488 | { |
489 | 489 | return array( |
@@ -527,24 +527,24 @@ discard block |
||
527 | 527 | return $this; |
528 | 528 | } |
529 | 529 | |
530 | - /** |
|
531 | - * Whether the parameter exclusion mode is enabled: |
|
532 | - * In this case, if any parameters have been added to the |
|
533 | - * exclusion list, all relevant methods will exclude these. |
|
534 | - * |
|
535 | - * @return bool |
|
536 | - */ |
|
530 | + /** |
|
531 | + * Whether the parameter exclusion mode is enabled: |
|
532 | + * In this case, if any parameters have been added to the |
|
533 | + * exclusion list, all relevant methods will exclude these. |
|
534 | + * |
|
535 | + * @return bool |
|
536 | + */ |
|
537 | 537 | public function isParamExclusionEnabled() : bool |
538 | 538 | { |
539 | 539 | return $this->paramExclusion; |
540 | 540 | } |
541 | 541 | |
542 | - /** |
|
543 | - * Checks whether the link contains any parameters that |
|
544 | - * are on the list of excluded parameters. |
|
545 | - * |
|
546 | - * @return bool |
|
547 | - */ |
|
542 | + /** |
|
543 | + * Checks whether the link contains any parameters that |
|
544 | + * are on the list of excluded parameters. |
|
545 | + * |
|
546 | + * @return bool |
|
547 | + */ |
|
548 | 548 | public function containsExcludedParams() : bool |
549 | 549 | { |
550 | 550 | if(empty($this->excludedParams)) { |
@@ -612,16 +612,16 @@ discard block |
||
612 | 612 | return $this->highlightExcluded; |
613 | 613 | } |
614 | 614 | |
615 | - /** |
|
616 | - * Checks if the URL exists, i.e. can be connected to. Will return |
|
617 | - * true if the returned HTTP status code is `200` or `302`. |
|
618 | - * |
|
619 | - * NOTE: If the target URL requires HTTP authentication, the username |
|
620 | - * and password should be integrated into the URL. |
|
621 | - * |
|
622 | - * @return bool |
|
623 | - * @throws BaseException |
|
624 | - */ |
|
615 | + /** |
|
616 | + * Checks if the URL exists, i.e. can be connected to. Will return |
|
617 | + * true if the returned HTTP status code is `200` or `302`. |
|
618 | + * |
|
619 | + * NOTE: If the target URL requires HTTP authentication, the username |
|
620 | + * and password should be integrated into the URL. |
|
621 | + * |
|
622 | + * @return bool |
|
623 | + * @throws BaseException |
|
624 | + */ |
|
625 | 625 | public function tryConnect() : bool |
626 | 626 | { |
627 | 627 | requireCURL(); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | { |
201 | 201 | $port = $this->getInfoKey('port'); |
202 | 202 | |
203 | - if(!empty($port)) { |
|
203 | + if (!empty($port)) { |
|
204 | 204 | return (int)$port; |
205 | 205 | } |
206 | 206 | |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | |
281 | 281 | protected function getInfoKey(string $name) : string |
282 | 282 | { |
283 | - if(isset($this->info[$name])) { |
|
283 | + if (isset($this->info[$name])) { |
|
284 | 284 | return (string)$this->info[$name]; |
285 | 285 | } |
286 | 286 | |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | |
290 | 290 | public function getNormalized() : string |
291 | 291 | { |
292 | - if(!$this->isValid()) { |
|
292 | + if (!$this->isValid()) { |
|
293 | 293 | return ''; |
294 | 294 | } |
295 | 295 | |
296 | - if(!isset($this->normalizer)) { |
|
296 | + if (!isset($this->normalizer)) { |
|
297 | 297 | $this->normalizer = new URLInfo_Normalizer($this); |
298 | 298 | } |
299 | 299 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function getHighlighted() : string |
323 | 323 | { |
324 | - if(!$this->isValid()) { |
|
324 | + if (!$this->isValid()) { |
|
325 | 325 | return ''; |
326 | 326 | } |
327 | 327 | |
@@ -363,14 +363,14 @@ discard block |
||
363 | 363 | */ |
364 | 364 | public function getParams() : array |
365 | 365 | { |
366 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
366 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
367 | 367 | return $this->info['params']; |
368 | 368 | } |
369 | 369 | |
370 | 370 | $keep = array(); |
371 | - foreach($this->info['params'] as $name => $value) |
|
371 | + foreach ($this->info['params'] as $name => $value) |
|
372 | 372 | { |
373 | - if(!isset($this->excludedParams[$name])) { |
|
373 | + if (!isset($this->excludedParams[$name])) { |
|
374 | 374 | $keep[$name] = $value; |
375 | 375 | } |
376 | 376 | } |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public function getParam(string $name) : string |
398 | 398 | { |
399 | - if(isset($this->info['params'][$name])) { |
|
399 | + if (isset($this->info['params'][$name])) { |
|
400 | 400 | return $this->info['params'][$name]; |
401 | 401 | } |
402 | 402 | |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | */ |
416 | 416 | public function excludeParam(string $name, string $reason) : URLInfo |
417 | 417 | { |
418 | - if(!isset($this->excludedParams[$name])) |
|
418 | + if (!isset($this->excludedParams[$name])) |
|
419 | 419 | { |
420 | 420 | $this->excludedParams[$name] = $reason; |
421 | 421 | $this->setParamExclusion(); |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | |
442 | 442 | public function getTypeLabel() : string |
443 | 443 | { |
444 | - if(!isset(self::$typeLabels)) |
|
444 | + if (!isset(self::$typeLabels)) |
|
445 | 445 | { |
446 | 446 | self::$typeLabels = array( |
447 | 447 | self::TYPE_EMAIL => t('Email'), |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | |
454 | 454 | $type = $this->getType(); |
455 | 455 | |
456 | - if(!isset(self::$typeLabels[$type])) |
|
456 | + if (!isset(self::$typeLabels[$type])) |
|
457 | 457 | { |
458 | 458 | throw new BaseException( |
459 | 459 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | * @param bool $highlight |
474 | 474 | * @return URLInfo |
475 | 475 | */ |
476 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
476 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
477 | 477 | { |
478 | 478 | $this->highlightExcluded = $highlight; |
479 | 479 | return $this; |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | * @see URLInfo::isParamExclusionEnabled() |
522 | 522 | * @see URLInfo::setHighlightExcluded() |
523 | 523 | */ |
524 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
524 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
525 | 525 | { |
526 | 526 | $this->paramExclusion = $enabled; |
527 | 527 | return $this; |
@@ -547,13 +547,13 @@ discard block |
||
547 | 547 | */ |
548 | 548 | public function containsExcludedParams() : bool |
549 | 549 | { |
550 | - if(empty($this->excludedParams)) { |
|
550 | + if (empty($this->excludedParams)) { |
|
551 | 551 | return false; |
552 | 552 | } |
553 | 553 | |
554 | 554 | $names = array_keys($this->info['params']); |
555 | - foreach($names as $name) { |
|
556 | - if(isset($this->excludedParams[$name])) { |
|
555 | + foreach ($names as $name) { |
|
556 | + if (isset($this->excludedParams[$name])) { |
|
557 | 557 | return true; |
558 | 558 | } |
559 | 559 | } |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | |
570 | 570 | public function offsetSet($offset, $value) |
571 | 571 | { |
572 | - if(in_array($offset, $this->infoKeys)) { |
|
572 | + if (in_array($offset, $this->infoKeys)) { |
|
573 | 573 | $this->info[$offset] = $value; |
574 | 574 | } |
575 | 575 | } |
@@ -586,11 +586,11 @@ discard block |
||
586 | 586 | |
587 | 587 | public function offsetGet($offset) |
588 | 588 | { |
589 | - if($offset === 'port') { |
|
589 | + if ($offset === 'port') { |
|
590 | 590 | return $this->getPort(); |
591 | 591 | } |
592 | 592 | |
593 | - if(in_array($offset, $this->infoKeys)) { |
|
593 | + if (in_array($offset, $this->infoKeys)) { |
|
594 | 594 | return $this->getInfoKey($offset); |
595 | 595 | } |
596 | 596 | |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | requireCURL(); |
628 | 628 | |
629 | 629 | $ch = curl_init(); |
630 | - if($ch === false) |
|
630 | + if ($ch === false) |
|
631 | 631 | { |
632 | 632 | throw new BaseException( |
633 | 633 | 'Could not initialize a new cURL instance.', |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | $contents = file_get_contents($file); |
108 | 108 | |
109 | - if($contents === false) |
|
109 | + if ($contents === false) |
|
110 | 110 | { |
111 | 111 | throw new FileHelper_Exception( |
112 | 112 | 'Cannot load serialized content from file.', |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | $result = @unserialize($contents); |
122 | 122 | |
123 | - if($result !== false) { |
|
123 | + if ($result !== false) { |
|
124 | 124 | return $result; |
125 | 125 | } |
126 | 126 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | public static function deleteTree($rootFolder) |
138 | 138 | { |
139 | - if(!file_exists($rootFolder)) { |
|
139 | + if (!file_exists($rootFolder)) { |
|
140 | 140 | return true; |
141 | 141 | } |
142 | 142 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public static function createFolder($path) |
179 | 179 | { |
180 | - if(is_dir($path) || mkdir($path, 0777, true)) { |
|
180 | + if (is_dir($path) || mkdir($path, 0777, true)) { |
|
181 | 181 | return; |
182 | 182 | } |
183 | 183 | |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | |
213 | 213 | if ($item->isDir()) |
214 | 214 | { |
215 | - FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName); |
|
215 | + FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target.'/'.$baseName); |
|
216 | 216 | } |
217 | - else if($item->isFile()) |
|
217 | + else if ($item->isFile()) |
|
218 | 218 | { |
219 | - self::copyFile($itemPath, $target . '/' . $baseName); |
|
219 | + self::copyFile($itemPath, $target.'/'.$baseName); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | { |
242 | 242 | self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND); |
243 | 243 | |
244 | - if(!is_readable($sourcePath)) |
|
244 | + if (!is_readable($sourcePath)) |
|
245 | 245 | { |
246 | 246 | throw new FileHelper_Exception( |
247 | 247 | sprintf('Source file [%s] to copy is not readable.', basename($sourcePath)), |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | |
256 | 256 | $targetFolder = dirname($targetPath); |
257 | 257 | |
258 | - if(!file_exists($targetFolder)) |
|
258 | + if (!file_exists($targetFolder)) |
|
259 | 259 | { |
260 | 260 | self::createFolder($targetFolder); |
261 | 261 | } |
262 | - else if(!is_writable($targetFolder)) |
|
262 | + else if (!is_writable($targetFolder)) |
|
263 | 263 | { |
264 | 264 | throw new FileHelper_Exception( |
265 | 265 | sprintf('Target folder [%s] is not writable.', basename($targetFolder)), |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | ); |
272 | 272 | } |
273 | 273 | |
274 | - if(copy($sourcePath, $targetPath)) { |
|
274 | + if (copy($sourcePath, $targetPath)) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
@@ -298,11 +298,11 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public static function deleteFile(string $filePath) : void |
300 | 300 | { |
301 | - if(!file_exists($filePath)) { |
|
301 | + if (!file_exists($filePath)) { |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | |
305 | - if(unlink($filePath)) { |
|
305 | + if (unlink($filePath)) { |
|
306 | 306 | return; |
307 | 307 | } |
308 | 308 | |
@@ -326,10 +326,10 @@ discard block |
||
326 | 326 | * @return \parseCSV |
327 | 327 | * @todo Move this to the CSV helper. |
328 | 328 | */ |
329 | - public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : \parseCSV |
|
329 | + public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : \parseCSV |
|
330 | 330 | { |
331 | - if($delimiter==='') { $delimiter = ';'; } |
|
332 | - if($enclosure==='') { $enclosure = '"'; } |
|
331 | + if ($delimiter === '') { $delimiter = ';'; } |
|
332 | + if ($enclosure === '') { $enclosure = '"'; } |
|
333 | 333 | |
334 | 334 | $parser = new \parseCSV(null, null, null, array()); |
335 | 335 | |
@@ -357,11 +357,11 @@ discard block |
||
357 | 357 | * @see parseCSVFile() |
358 | 358 | * @see FileHelper::ERROR_PARSING_CSV |
359 | 359 | */ |
360 | - public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
360 | + public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
361 | 361 | { |
362 | 362 | $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading); |
363 | 363 | $result = $parser->parse_string(/** @scrutinizer ignore-type */ $csv); |
364 | - if(is_array($result)) { |
|
364 | + if (is_array($result)) { |
|
365 | 365 | return $result; |
366 | 366 | } |
367 | 367 | |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
390 | 390 | * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
391 | 391 | */ |
392 | - public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
392 | + public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
393 | 393 | { |
394 | 394 | $content = self::readContents($filePath); |
395 | 395 | |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | public static function detectMimeType(string $fileName) : ?string |
407 | 407 | { |
408 | 408 | $ext = self::getExtension($fileName); |
409 | - if(empty($ext)) { |
|
409 | + if (empty($ext)) { |
|
410 | 410 | return null; |
411 | 411 | } |
412 | 412 | |
@@ -427,11 +427,11 @@ discard block |
||
427 | 427 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
428 | 428 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
429 | 429 | */ |
430 | - public static function sendFile(string $filePath, $fileName = null, bool $asAttachment=true) |
|
430 | + public static function sendFile(string $filePath, $fileName = null, bool $asAttachment = true) |
|
431 | 431 | { |
432 | 432 | self::requireFileExists($filePath); |
433 | 433 | |
434 | - if(empty($fileName)) { |
|
434 | + if (empty($fileName)) { |
|
435 | 435 | $fileName = basename($filePath); |
436 | 436 | } |
437 | 437 | |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | |
450 | 450 | header("Cache-Control: public", true); |
451 | 451 | header("Content-Description: File Transfer", true); |
452 | - header("Content-Type: " . $mime, true); |
|
452 | + header("Content-Type: ".$mime, true); |
|
453 | 453 | |
454 | 454 | $disposition = 'inline'; |
455 | - if($asAttachment) { |
|
455 | + if ($asAttachment) { |
|
456 | 456 | $disposition = 'attachment'; |
457 | 457 | } |
458 | 458 | |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | requireCURL(); |
481 | 481 | |
482 | 482 | $ch = curl_init(); |
483 | - if($ch === false) |
|
483 | + if ($ch === false) |
|
484 | 484 | { |
485 | 485 | throw new FileHelper_Exception( |
486 | 486 | 'Could not initialize a new cURL instance.', |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | |
502 | 502 | $output = curl_exec($ch); |
503 | 503 | |
504 | - if($output === false) { |
|
504 | + if ($output === false) { |
|
505 | 505 | throw new FileHelper_Exception( |
506 | 506 | 'Unable to open URL', |
507 | 507 | sprintf( |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | |
516 | 516 | curl_close($ch); |
517 | 517 | |
518 | - if(is_string($output)) |
|
518 | + if (is_string($output)) |
|
519 | 519 | { |
520 | 520 | return $output; |
521 | 521 | } |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | */ |
538 | 538 | public static function isPHPFile($pathOrDirIterator) |
539 | 539 | { |
540 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
540 | + if (self::getExtension($pathOrDirIterator) == 'php') { |
|
541 | 541 | return true; |
542 | 542 | } |
543 | 543 | |
@@ -554,14 +554,14 @@ discard block |
||
554 | 554 | */ |
555 | 555 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
556 | 556 | { |
557 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
557 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
558 | 558 | $filename = $pathOrDirIterator->getFilename(); |
559 | 559 | } else { |
560 | 560 | $filename = basename($pathOrDirIterator); |
561 | 561 | } |
562 | 562 | |
563 | 563 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
564 | - if($lowercase) { |
|
564 | + if ($lowercase) { |
|
565 | 565 | $ext = mb_strtolower($ext); |
566 | 566 | } |
567 | 567 | |
@@ -583,13 +583,13 @@ discard block |
||
583 | 583 | public static function getFilename($pathOrDirIterator, $extension = true) |
584 | 584 | { |
585 | 585 | $path = $pathOrDirIterator; |
586 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
586 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
587 | 587 | $path = $pathOrDirIterator->getFilename(); |
588 | 588 | } |
589 | 589 | |
590 | 590 | $path = self::normalizePath($path); |
591 | 591 | |
592 | - if(!$extension) { |
|
592 | + if (!$extension) { |
|
593 | 593 | return pathinfo($path, PATHINFO_FILENAME); |
594 | 594 | } |
595 | 595 | |
@@ -607,12 +607,12 @@ discard block |
||
607 | 607 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
608 | 608 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
609 | 609 | */ |
610 | - public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
|
610 | + public static function parseJSONFile(string $file, $targetEncoding = null, $sourceEncoding = null) |
|
611 | 611 | { |
612 | 612 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
613 | 613 | |
614 | 614 | $content = file_get_contents($file); |
615 | - if(!$content) { |
|
615 | + if (!$content) { |
|
616 | 616 | throw new FileHelper_Exception( |
617 | 617 | 'Cannot get file contents', |
618 | 618 | sprintf( |
@@ -623,12 +623,12 @@ discard block |
||
623 | 623 | ); |
624 | 624 | } |
625 | 625 | |
626 | - if(isset($targetEncoding)) { |
|
626 | + if (isset($targetEncoding)) { |
|
627 | 627 | $content = mb_convert_encoding($content, $targetEncoding, $sourceEncoding); |
628 | 628 | } |
629 | 629 | |
630 | 630 | $json = json_decode($content, true); |
631 | - if($json === false || $json === NULL) { |
|
631 | + if ($json === false || $json === NULL) { |
|
632 | 632 | throw new FileHelper_Exception( |
633 | 633 | 'Cannot decode json data', |
634 | 634 | sprintf( |
@@ -668,13 +668,13 @@ discard block |
||
668 | 668 | |
669 | 669 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
670 | 670 | |
671 | - while(strstr($name, ' ')) { |
|
671 | + while (strstr($name, ' ')) { |
|
672 | 672 | $name = str_replace(' ', ' ', $name); |
673 | 673 | } |
674 | 674 | |
675 | 675 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
676 | 676 | |
677 | - while(strstr($name, '..')) { |
|
677 | + while (strstr($name, '..')) { |
|
678 | 678 | $name = str_replace('..', '.', $name); |
679 | 679 | } |
680 | 680 | |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | * @return array An indexed array with files. |
707 | 707 | * @see FileHelper::createFileFinder() |
708 | 708 | */ |
709 | - public static function findHTMLFiles(string $targetFolder, array $options=array()) : array |
|
709 | + public static function findHTMLFiles(string $targetFolder, array $options = array()) : array |
|
710 | 710 | { |
711 | 711 | return self::findFiles($targetFolder, array('html'), $options); |
712 | 712 | } |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | * @return array An indexed array of PHP files. |
724 | 724 | * @see FileHelper::createFileFinder() |
725 | 725 | */ |
726 | - public static function findPHPFiles(string $targetFolder, array $options=array()) : array |
|
726 | + public static function findPHPFiles(string $targetFolder, array $options = array()) : array |
|
727 | 727 | { |
728 | 728 | return self::findFiles($targetFolder, array('php'), $options); |
729 | 729 | } |
@@ -743,20 +743,20 @@ discard block |
||
743 | 743 | * @return array |
744 | 744 | * @see FileHelper::createFileFinder() |
745 | 745 | */ |
746 | - public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array |
|
746 | + public static function findFiles(string $targetFolder, array $extensions = array(), array $options = array(), array $files = array()) : array |
|
747 | 747 | { |
748 | 748 | $finder = self::createFileFinder($targetFolder); |
749 | 749 | |
750 | - if(isset($options['relative-path']) && $options['relative-path'] === true) |
|
750 | + if (isset($options['relative-path']) && $options['relative-path'] === true) |
|
751 | 751 | { |
752 | 752 | $finder->setPathmodeRelative(); |
753 | 753 | } |
754 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
754 | + else if (isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
755 | 755 | { |
756 | 756 | $finder->setPathmodeAbsolute(); |
757 | 757 | } |
758 | 758 | |
759 | - if(isset($options['strip-extension'])) |
|
759 | + if (isset($options['strip-extension'])) |
|
760 | 760 | { |
761 | 761 | $finder->stripExtensions(); |
762 | 762 | } |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | public static function detectUTFBom(string $filename) : ?string |
801 | 801 | { |
802 | 802 | $fp = fopen($filename, 'r'); |
803 | - if($fp === false) |
|
803 | + if ($fp === false) |
|
804 | 804 | { |
805 | 805 | throw new FileHelper_Exception( |
806 | 806 | 'Cannot open file for reading', |
@@ -815,10 +815,10 @@ discard block |
||
815 | 815 | |
816 | 816 | $boms = self::getUTFBOMs(); |
817 | 817 | |
818 | - foreach($boms as $bom => $value) |
|
818 | + foreach ($boms as $bom => $value) |
|
819 | 819 | { |
820 | 820 | $length = mb_strlen($value); |
821 | - if(mb_substr($text, 0, $length) == $value) { |
|
821 | + if (mb_substr($text, 0, $length) == $value) { |
|
822 | 822 | return $bom; |
823 | 823 | } |
824 | 824 | } |
@@ -837,13 +837,13 @@ discard block |
||
837 | 837 | */ |
838 | 838 | public static function getUTFBOMs() |
839 | 839 | { |
840 | - if(!isset(self::$utfBoms)) { |
|
840 | + if (!isset(self::$utfBoms)) { |
|
841 | 841 | self::$utfBoms = array( |
842 | - 'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF), |
|
843 | - 'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00), |
|
844 | - 'UTF16-BE' => chr(0xFE) . chr(0xFF), |
|
845 | - 'UTF16-LE' => chr(0xFF) . chr(0xFE), |
|
846 | - 'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF) |
|
842 | + 'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF), |
|
843 | + 'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00), |
|
844 | + 'UTF16-BE' => chr(0xFE).chr(0xFF), |
|
845 | + 'UTF16-LE' => chr(0xFF).chr(0xFE), |
|
846 | + 'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF) |
|
847 | 847 | ); |
848 | 848 | } |
849 | 849 | |
@@ -864,7 +864,7 @@ discard block |
||
864 | 864 | $encodings = self::getKnownUnicodeEncodings(); |
865 | 865 | |
866 | 866 | $keep = array(); |
867 | - foreach($encodings as $string) |
|
867 | + foreach ($encodings as $string) |
|
868 | 868 | { |
869 | 869 | $withHyphen = str_replace('UTF', 'UTF-', $string); |
870 | 870 | |
@@ -911,16 +911,16 @@ discard block |
||
911 | 911 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
912 | 912 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
913 | 913 | */ |
914 | - public static function saveAsJSON($data, string $file, bool $pretty=false) |
|
914 | + public static function saveAsJSON($data, string $file, bool $pretty = false) |
|
915 | 915 | { |
916 | 916 | $options = null; |
917 | - if($pretty) { |
|
917 | + if ($pretty) { |
|
918 | 918 | $options = JSON_PRETTY_PRINT; |
919 | 919 | } |
920 | 920 | |
921 | 921 | $json = json_encode($data, $options); |
922 | 922 | |
923 | - if($json===false) |
|
923 | + if ($json === false) |
|
924 | 924 | { |
925 | 925 | $errorCode = json_last_error(); |
926 | 926 | |
@@ -946,12 +946,12 @@ discard block |
||
946 | 946 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
947 | 947 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
948 | 948 | */ |
949 | - public static function saveFile(string $filePath, string $content='') : void |
|
949 | + public static function saveFile(string $filePath, string $content = '') : void |
|
950 | 950 | { |
951 | 951 | // target file already exists |
952 | - if(file_exists($filePath)) |
|
952 | + if (file_exists($filePath)) |
|
953 | 953 | { |
954 | - if(!is_writable($filePath)) |
|
954 | + if (!is_writable($filePath)) |
|
955 | 955 | { |
956 | 956 | throw new FileHelper_Exception( |
957 | 957 | sprintf('Cannot save file: target file [%s] exists, but is not writable.', basename($filePath)), |
@@ -971,7 +971,7 @@ discard block |
||
971 | 971 | // create the folder as needed |
972 | 972 | self::createFolder($targetFolder); |
973 | 973 | |
974 | - if(!is_writable($targetFolder)) |
|
974 | + if (!is_writable($targetFolder)) |
|
975 | 975 | { |
976 | 976 | throw new FileHelper_Exception( |
977 | 977 | sprintf('Cannot save file: target folder [%s] is not writable.', basename($targetFolder)), |
@@ -984,7 +984,7 @@ discard block |
||
984 | 984 | } |
985 | 985 | } |
986 | 986 | |
987 | - if(file_put_contents($filePath, $content) !== false) { |
|
987 | + if (file_put_contents($filePath, $content) !== false) { |
|
988 | 988 | return; |
989 | 989 | } |
990 | 990 | |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | { |
1023 | 1023 | static $checked = array(); |
1024 | 1024 | |
1025 | - if(isset($checked[$command])) { |
|
1025 | + if (isset($checked[$command])) { |
|
1026 | 1026 | return $checked[$command]; |
1027 | 1027 | } |
1028 | 1028 | |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | |
1036 | 1036 | $os = strtolower(PHP_OS_FAMILY); |
1037 | 1037 | |
1038 | - if(!isset($osCommands[$os])) |
|
1038 | + if (!isset($osCommands[$os])) |
|
1039 | 1039 | { |
1040 | 1040 | throw new FileHelper_Exception( |
1041 | 1041 | 'Unsupported OS for CLI commands', |
@@ -1061,7 +1061,7 @@ discard block |
||
1061 | 1061 | $pipes |
1062 | 1062 | ); |
1063 | 1063 | |
1064 | - if($process === false) { |
|
1064 | + if ($process === false) { |
|
1065 | 1065 | $checked[$command] = false; |
1066 | 1066 | return false; |
1067 | 1067 | } |
@@ -1092,7 +1092,7 @@ discard block |
||
1092 | 1092 | */ |
1093 | 1093 | public static function checkPHPFileSyntax($path) |
1094 | 1094 | { |
1095 | - if(!self::canMakePHPCalls()) { |
|
1095 | + if (!self::canMakePHPCalls()) { |
|
1096 | 1096 | return true; |
1097 | 1097 | } |
1098 | 1098 | |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | // when the validation is successful, the first entry |
1104 | 1104 | // in the array contains the success message. When it |
1105 | 1105 | // is invalid, the first entry is always empty. |
1106 | - if(!empty($output[0])) { |
|
1106 | + if (!empty($output[0])) { |
|
1107 | 1107 | return true; |
1108 | 1108 | } |
1109 | 1109 | |
@@ -1124,7 +1124,7 @@ discard block |
||
1124 | 1124 | public static function getModifiedDate($path) |
1125 | 1125 | { |
1126 | 1126 | $time = filemtime($path); |
1127 | - if($time !== false) { |
|
1127 | + if ($time !== false) { |
|
1128 | 1128 | $date = new \DateTime(); |
1129 | 1129 | $date->setTimestamp($time); |
1130 | 1130 | return $date; |
@@ -1153,7 +1153,7 @@ discard block |
||
1153 | 1153 | */ |
1154 | 1154 | public static function getSubfolders($targetFolder, $options = array()) |
1155 | 1155 | { |
1156 | - if(!is_dir($targetFolder)) |
|
1156 | + if (!is_dir($targetFolder)) |
|
1157 | 1157 | { |
1158 | 1158 | throw new FileHelper_Exception( |
1159 | 1159 | 'Target folder does not exist', |
@@ -1177,29 +1177,29 @@ discard block |
||
1177 | 1177 | |
1178 | 1178 | $d = new \DirectoryIterator($targetFolder); |
1179 | 1179 | |
1180 | - foreach($d as $item) |
|
1180 | + foreach ($d as $item) |
|
1181 | 1181 | { |
1182 | - if($item->isDir() && !$item->isDot()) |
|
1182 | + if ($item->isDir() && !$item->isDot()) |
|
1183 | 1183 | { |
1184 | 1184 | $name = $item->getFilename(); |
1185 | 1185 | |
1186 | - if(!$options['absolute-path']) { |
|
1186 | + if (!$options['absolute-path']) { |
|
1187 | 1187 | $result[] = $name; |
1188 | 1188 | } else { |
1189 | 1189 | $result[] = $targetFolder.'/'.$name; |
1190 | 1190 | } |
1191 | 1191 | |
1192 | - if(!$options['recursive']) |
|
1192 | + if (!$options['recursive']) |
|
1193 | 1193 | { |
1194 | 1194 | continue; |
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | $subs = self::getSubfolders($targetFolder.'/'.$name, $options); |
1198 | - foreach($subs as $sub) |
|
1198 | + foreach ($subs as $sub) |
|
1199 | 1199 | { |
1200 | 1200 | $relative = $name.'/'.$sub; |
1201 | 1201 | |
1202 | - if(!$options['absolute-path']) { |
|
1202 | + if (!$options['absolute-path']) { |
|
1203 | 1203 | $result[] = $relative; |
1204 | 1204 | } else { |
1205 | 1205 | $result[] = $targetFolder.'/'.$relative; |
@@ -1267,7 +1267,7 @@ discard block |
||
1267 | 1267 | * @param int $depth The folder depth to reduce the path to |
1268 | 1268 | * @return string |
1269 | 1269 | */ |
1270 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
1270 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
1271 | 1271 | { |
1272 | 1272 | $path = self::normalizePath($path); |
1273 | 1273 | |
@@ -1275,17 +1275,17 @@ discard block |
||
1275 | 1275 | $tokens = array_filter($tokens); // remove empty entries (trailing slash for example) |
1276 | 1276 | $tokens = array_values($tokens); // re-index keys |
1277 | 1277 | |
1278 | - if(empty($tokens)) { |
|
1278 | + if (empty($tokens)) { |
|
1279 | 1279 | return ''; |
1280 | 1280 | } |
1281 | 1281 | |
1282 | 1282 | // remove the drive if present |
1283 | - if(strstr($tokens[0], ':')) { |
|
1283 | + if (strstr($tokens[0], ':')) { |
|
1284 | 1284 | array_shift($tokens); |
1285 | 1285 | } |
1286 | 1286 | |
1287 | 1287 | // path was only the drive |
1288 | - if(count($tokens) == 0) { |
|
1288 | + if (count($tokens) == 0) { |
|
1289 | 1289 | return ''; |
1290 | 1290 | } |
1291 | 1291 | |
@@ -1294,8 +1294,8 @@ discard block |
||
1294 | 1294 | |
1295 | 1295 | // reduce the path to the specified depth |
1296 | 1296 | $length = count($tokens); |
1297 | - if($length > $depth) { |
|
1298 | - $tokens = array_slice($tokens, $length-$depth); |
|
1297 | + if ($length > $depth) { |
|
1298 | + $tokens = array_slice($tokens, $length - $depth); |
|
1299 | 1299 | } |
1300 | 1300 | |
1301 | 1301 | // append the last element again |
@@ -1343,14 +1343,14 @@ discard block |
||
1343 | 1343 | * |
1344 | 1344 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
1345 | 1345 | */ |
1346 | - public static function requireFileExists(string $path, $errorCode=null) : string |
|
1346 | + public static function requireFileExists(string $path, $errorCode = null) : string |
|
1347 | 1347 | { |
1348 | 1348 | $result = realpath($path); |
1349 | - if($result !== false) { |
|
1349 | + if ($result !== false) { |
|
1350 | 1350 | return $result; |
1351 | 1351 | } |
1352 | 1352 | |
1353 | - if($errorCode === null) { |
|
1353 | + if ($errorCode === null) { |
|
1354 | 1354 | $errorCode = self::ERROR_FILE_DOES_NOT_EXIST; |
1355 | 1355 | } |
1356 | 1356 | |
@@ -1379,15 +1379,15 @@ discard block |
||
1379 | 1379 | |
1380 | 1380 | $file = new \SplFileObject($path); |
1381 | 1381 | |
1382 | - if($file->eof()) { |
|
1382 | + if ($file->eof()) { |
|
1383 | 1383 | return ''; |
1384 | 1384 | } |
1385 | 1385 | |
1386 | - $targetLine = $lineNumber-1; |
|
1386 | + $targetLine = $lineNumber - 1; |
|
1387 | 1387 | |
1388 | 1388 | $file->seek($targetLine); |
1389 | 1389 | |
1390 | - if($file->key() !== $targetLine) { |
|
1390 | + if ($file->key() !== $targetLine) { |
|
1391 | 1391 | return null; |
1392 | 1392 | } |
1393 | 1393 | |
@@ -1413,7 +1413,7 @@ discard block |
||
1413 | 1413 | $number = $spl->key(); |
1414 | 1414 | |
1415 | 1415 | // if seeking to the end the cursor is still at 0, there are no lines. |
1416 | - if($number === 0) |
|
1416 | + if ($number === 0) |
|
1417 | 1417 | { |
1418 | 1418 | // since it's a very small file, to get reliable results, |
1419 | 1419 | // we read its contents and use that to determine what |
@@ -1421,13 +1421,13 @@ discard block |
||
1421 | 1421 | // that this is not pactical to solve with the SplFileObject. |
1422 | 1422 | $content = file_get_contents($path); |
1423 | 1423 | |
1424 | - if(empty($content)) { |
|
1424 | + if (empty($content)) { |
|
1425 | 1425 | return 0; |
1426 | 1426 | } |
1427 | 1427 | } |
1428 | 1428 | |
1429 | 1429 | // return the line number we were able to reach + 1 (key is zero-based) |
1430 | - return $number+1; |
|
1430 | + return $number + 1; |
|
1431 | 1431 | } |
1432 | 1432 | |
1433 | 1433 | /** |
@@ -1474,13 +1474,13 @@ discard block |
||
1474 | 1474 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
1475 | 1475 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
1476 | 1476 | */ |
1477 | - public static function readLines(string $filePath, int $amount=0) : array |
|
1477 | + public static function readLines(string $filePath, int $amount = 0) : array |
|
1478 | 1478 | { |
1479 | 1479 | self::requireFileExists($filePath); |
1480 | 1480 | |
1481 | 1481 | $fn = fopen($filePath, "r"); |
1482 | 1482 | |
1483 | - if($fn === false) |
|
1483 | + if ($fn === false) |
|
1484 | 1484 | { |
1485 | 1485 | throw new FileHelper_Exception( |
1486 | 1486 | 'Could not open file for reading.', |
@@ -1496,25 +1496,25 @@ discard block |
||
1496 | 1496 | $counter = 0; |
1497 | 1497 | $first = true; |
1498 | 1498 | |
1499 | - while(!feof($fn)) |
|
1499 | + while (!feof($fn)) |
|
1500 | 1500 | { |
1501 | 1501 | $counter++; |
1502 | 1502 | |
1503 | 1503 | $line = fgets($fn); |
1504 | 1504 | |
1505 | 1505 | // can happen with zero length files |
1506 | - if($line === false) { |
|
1506 | + if ($line === false) { |
|
1507 | 1507 | continue; |
1508 | 1508 | } |
1509 | 1509 | |
1510 | 1510 | // the first line may contain a unicode BOM marker. |
1511 | - if($first) { |
|
1511 | + if ($first) { |
|
1512 | 1512 | $line = ConvertHelper::stripUTFBom($line); |
1513 | 1513 | } |
1514 | 1514 | |
1515 | 1515 | $result[] = $line; |
1516 | 1516 | |
1517 | - if($amount > 0 && $counter == $amount) { |
|
1517 | + if ($amount > 0 && $counter == $amount) { |
|
1518 | 1518 | break; |
1519 | 1519 | } |
1520 | 1520 | } |
@@ -1540,7 +1540,7 @@ discard block |
||
1540 | 1540 | |
1541 | 1541 | $result = file_get_contents($filePath); |
1542 | 1542 | |
1543 | - if($result !== false) { |
|
1543 | + if ($result !== false) { |
|
1544 | 1544 | return $result; |
1545 | 1545 | } |
1546 | 1546 |