@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | const TYPE_PHONE = 'phone'; |
20 | 20 | const TYPE_URL = 'url'; |
21 | 21 | |
22 | - /** |
|
23 | - * The original URL that was passed to the constructor. |
|
24 | - * @var string |
|
25 | - */ |
|
22 | + /** |
|
23 | + * The original URL that was passed to the constructor. |
|
24 | + * @var string |
|
25 | + */ |
|
26 | 26 | protected $rawURL; |
27 | 27 | |
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | 31 | protected $info; |
32 | 32 | |
33 | 33 | protected $isEmail = false; |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | |
39 | 39 | protected $isPhone = false; |
40 | 40 | |
41 | - /** |
|
42 | - * @var string[] |
|
43 | - */ |
|
41 | + /** |
|
42 | + * @var string[] |
|
43 | + */ |
|
44 | 44 | protected $knownSchemes = array( |
45 | 45 | 'ftp', |
46 | 46 | 'http', |
@@ -51,36 +51,36 @@ discard block |
||
51 | 51 | 'file' |
52 | 52 | ); |
53 | 53 | |
54 | - /** |
|
55 | - * @var array |
|
56 | - */ |
|
54 | + /** |
|
55 | + * @var array |
|
56 | + */ |
|
57 | 57 | protected $error; |
58 | 58 | |
59 | - /** |
|
60 | - * @var array |
|
61 | - */ |
|
59 | + /** |
|
60 | + * @var array |
|
61 | + */ |
|
62 | 62 | protected $params = array(); |
63 | 63 | |
64 | - /** |
|
65 | - * @var string[] |
|
66 | - */ |
|
64 | + /** |
|
65 | + * @var string[] |
|
66 | + */ |
|
67 | 67 | protected $excludedParams = array(); |
68 | 68 | |
69 | - /** |
|
70 | - * @var bool |
|
71 | - * @see URLInfo::setParamExclusion() |
|
72 | - */ |
|
69 | + /** |
|
70 | + * @var bool |
|
71 | + * @see URLInfo::setParamExclusion() |
|
72 | + */ |
|
73 | 73 | protected $paramExclusion = false; |
74 | 74 | |
75 | - /** |
|
76 | - * @var array |
|
77 | - * @see URLInfo::getTypeLabel() |
|
78 | - */ |
|
75 | + /** |
|
76 | + * @var array |
|
77 | + * @see URLInfo::getTypeLabel() |
|
78 | + */ |
|
79 | 79 | protected static $typeLabels; |
80 | 80 | |
81 | - /** |
|
82 | - * @var bool |
|
83 | - */ |
|
81 | + /** |
|
82 | + * @var bool |
|
83 | + */ |
|
84 | 84 | protected $highlightExcluded = false; |
85 | 85 | |
86 | 86 | protected $infoKeys = array( |
@@ -177,13 +177,13 @@ discard block |
||
177 | 177 | $this->isValid = true; |
178 | 178 | } |
179 | 179 | |
180 | - /** |
|
181 | - * Filters an URL: removes control characters and the |
|
182 | - * like to have a clean URL to work with. |
|
183 | - * |
|
184 | - * @param string $url |
|
185 | - * @return string |
|
186 | - */ |
|
180 | + /** |
|
181 | + * Filters an URL: removes control characters and the |
|
182 | + * like to have a clean URL to work with. |
|
183 | + * |
|
184 | + * @param string $url |
|
185 | + * @return string |
|
186 | + */ |
|
187 | 187 | public static function filterURL(string $url) |
188 | 188 | { |
189 | 189 | // fix ampersands if it comes from HTML |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | return $url; |
207 | 207 | } |
208 | 208 | |
209 | - /** |
|
210 | - * Goes through all information in the parse_url result |
|
211 | - * array, and attempts to fix any user errors in formatting |
|
212 | - * that can be recovered from, mostly regarding stray spaces. |
|
213 | - */ |
|
209 | + /** |
|
210 | + * Goes through all information in the parse_url result |
|
211 | + * array, and attempts to fix any user errors in formatting |
|
212 | + * that can be recovered from, mostly regarding stray spaces. |
|
213 | + */ |
|
214 | 214 | protected function filterParsed() |
215 | 215 | { |
216 | 216 | foreach($this->info as $key => $val) |
@@ -294,12 +294,12 @@ discard block |
||
294 | 294 | return $this->isPhone; |
295 | 295 | } |
296 | 296 | |
297 | - /** |
|
298 | - * Whether the URL is a regular URL, not one of the |
|
299 | - * other types like a phone number or email address. |
|
300 | - * |
|
301 | - * @return bool |
|
302 | - */ |
|
297 | + /** |
|
298 | + * Whether the URL is a regular URL, not one of the |
|
299 | + * other types like a phone number or email address. |
|
300 | + * |
|
301 | + * @return bool |
|
302 | + */ |
|
303 | 303 | public function isURL() : bool |
304 | 304 | { |
305 | 305 | $host = $this->getHost(); |
@@ -311,20 +311,20 @@ discard block |
||
311 | 311 | return $this->isValid; |
312 | 312 | } |
313 | 313 | |
314 | - /** |
|
315 | - * Retrieves the host name, or an empty string if none is present. |
|
316 | - * |
|
317 | - * @return string |
|
318 | - */ |
|
314 | + /** |
|
315 | + * Retrieves the host name, or an empty string if none is present. |
|
316 | + * |
|
317 | + * @return string |
|
318 | + */ |
|
319 | 319 | public function getHost() : string |
320 | 320 | { |
321 | 321 | return $this->getInfoKey('host'); |
322 | 322 | } |
323 | 323 | |
324 | - /** |
|
325 | - * Retrieves the path, or an empty string if none is present. |
|
326 | - * @return string |
|
327 | - */ |
|
324 | + /** |
|
325 | + * Retrieves the path, or an empty string if none is present. |
|
326 | + * @return string |
|
327 | + */ |
|
328 | 328 | public function getPath() : string |
329 | 329 | { |
330 | 330 | return $this->getInfoKey('path'); |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | return $this->getInfoKey('scheme'); |
341 | 341 | } |
342 | 342 | |
343 | - /** |
|
344 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
345 | - * @return int |
|
346 | - */ |
|
343 | + /** |
|
344 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
345 | + * @return int |
|
346 | + */ |
|
347 | 347 | public function getPort() : int |
348 | 348 | { |
349 | 349 | $port = $this->getInfoKey('port'); |
@@ -354,13 +354,13 @@ discard block |
||
354 | 354 | return -1; |
355 | 355 | } |
356 | 356 | |
357 | - /** |
|
358 | - * Retrieves the raw query string, or an empty string if none is present. |
|
359 | - * |
|
360 | - * @return string |
|
361 | - * |
|
362 | - * @see URLInfo::getParams() |
|
363 | - */ |
|
357 | + /** |
|
358 | + * Retrieves the raw query string, or an empty string if none is present. |
|
359 | + * |
|
360 | + * @return string |
|
361 | + * |
|
362 | + * @see URLInfo::getParams() |
|
363 | + */ |
|
364 | 364 | public function getQuery() : string |
365 | 365 | { |
366 | 366 | return $this->getInfoKey('query'); |
@@ -376,20 +376,20 @@ discard block |
||
376 | 376 | return $this->getInfoKey('pass'); |
377 | 377 | } |
378 | 378 | |
379 | - /** |
|
380 | - * Whether the URL contains a port number. |
|
381 | - * @return bool |
|
382 | - */ |
|
379 | + /** |
|
380 | + * Whether the URL contains a port number. |
|
381 | + * @return bool |
|
382 | + */ |
|
383 | 383 | public function hasPort() : bool |
384 | 384 | { |
385 | 385 | return $this->getPort() !== -1; |
386 | 386 | } |
387 | 387 | |
388 | - /** |
|
389 | - * Alias for the hasParams() method. |
|
390 | - * @return bool |
|
391 | - * @see URLInfo::hasParams() |
|
392 | - */ |
|
388 | + /** |
|
389 | + * Alias for the hasParams() method. |
|
390 | + * @return bool |
|
391 | + * @see URLInfo::hasParams() |
|
392 | + */ |
|
393 | 393 | public function hasQuery() : bool |
394 | 394 | { |
395 | 395 | return $this->hasParams(); |
@@ -470,25 +470,25 @@ discard block |
||
470 | 470 | return $normalized; |
471 | 471 | } |
472 | 472 | |
473 | - /** |
|
474 | - * Creates a hash of the URL, which can be used for comparisons. |
|
475 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
476 | - * the same links with a different parameter order will have the |
|
477 | - * same hash. |
|
478 | - * |
|
479 | - * @return string |
|
480 | - */ |
|
473 | + /** |
|
474 | + * Creates a hash of the URL, which can be used for comparisons. |
|
475 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
476 | + * the same links with a different parameter order will have the |
|
477 | + * same hash. |
|
478 | + * |
|
479 | + * @return string |
|
480 | + */ |
|
481 | 481 | public function getHash() |
482 | 482 | { |
483 | 483 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
484 | 484 | } |
485 | 485 | |
486 | - /** |
|
487 | - * Highlights the URL using HTML tags with specific highlighting |
|
488 | - * class names. |
|
489 | - * |
|
490 | - * @return string Will return an empty string if the URL is not valid. |
|
491 | - */ |
|
486 | + /** |
|
487 | + * Highlights the URL using HTML tags with specific highlighting |
|
488 | + * class names. |
|
489 | + * |
|
490 | + * @return string Will return an empty string if the URL is not valid. |
|
491 | + */ |
|
492 | 492 | public function getHighlighted() : string |
493 | 493 | { |
494 | 494 | if(!$this->isValid) { |
@@ -670,15 +670,15 @@ discard block |
||
670 | 670 | return count($params); |
671 | 671 | } |
672 | 672 | |
673 | - /** |
|
674 | - * Retrieves all parameters specified in the url, |
|
675 | - * if any, as an associative array. |
|
676 | - * |
|
677 | - * NOTE: Ignores parameters that have been added |
|
678 | - * to the excluded parameters list. |
|
679 | - * |
|
680 | - * @return array |
|
681 | - */ |
|
673 | + /** |
|
674 | + * Retrieves all parameters specified in the url, |
|
675 | + * if any, as an associative array. |
|
676 | + * |
|
677 | + * NOTE: Ignores parameters that have been added |
|
678 | + * to the excluded parameters list. |
|
679 | + * |
|
680 | + * @return array |
|
681 | + */ |
|
682 | 682 | public function getParams() : array |
683 | 683 | { |
684 | 684 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -695,26 +695,26 @@ discard block |
||
695 | 695 | return $keep; |
696 | 696 | } |
697 | 697 | |
698 | - /** |
|
699 | - * Retrieves the names of all parameters present in the URL, if any. |
|
700 | - * @return string[] |
|
701 | - */ |
|
698 | + /** |
|
699 | + * Retrieves the names of all parameters present in the URL, if any. |
|
700 | + * @return string[] |
|
701 | + */ |
|
702 | 702 | public function getParamNames() : array |
703 | 703 | { |
704 | 704 | $params = $this->getParams(); |
705 | 705 | return array_keys($params); |
706 | 706 | } |
707 | 707 | |
708 | - /** |
|
709 | - * Excludes an URL parameter entirely if present: |
|
710 | - * the parser will act as if the parameter was not |
|
711 | - * even present in the source URL, effectively |
|
712 | - * stripping it. |
|
713 | - * |
|
714 | - * @param string $name |
|
715 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
716 | - * @return URLInfo |
|
717 | - */ |
|
708 | + /** |
|
709 | + * Excludes an URL parameter entirely if present: |
|
710 | + * the parser will act as if the parameter was not |
|
711 | + * even present in the source URL, effectively |
|
712 | + * stripping it. |
|
713 | + * |
|
714 | + * @param string $name |
|
715 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
716 | + * @return URLInfo |
|
717 | + */ |
|
718 | 718 | public function excludeParam(string $name, string $reason) : URLInfo |
719 | 719 | { |
720 | 720 | if(!isset($this->excludedParams[$name])) |
@@ -779,25 +779,25 @@ discard block |
||
779 | 779 | return self::$typeLabels[$this->getType()]; |
780 | 780 | } |
781 | 781 | |
782 | - /** |
|
783 | - * Whether excluded parameters should be highlighted in |
|
784 | - * a different color in the URL when using the |
|
785 | - * {@link URLInfo::getHighlighted()} method. |
|
786 | - * |
|
787 | - * @param bool $highlight |
|
788 | - * @return URLInfo |
|
789 | - */ |
|
782 | + /** |
|
783 | + * Whether excluded parameters should be highlighted in |
|
784 | + * a different color in the URL when using the |
|
785 | + * {@link URLInfo::getHighlighted()} method. |
|
786 | + * |
|
787 | + * @param bool $highlight |
|
788 | + * @return URLInfo |
|
789 | + */ |
|
790 | 790 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
791 | 791 | { |
792 | 792 | $this->highlightExcluded = $highlight; |
793 | 793 | return $this; |
794 | 794 | } |
795 | 795 | |
796 | - /** |
|
797 | - * Returns an array with all relevant URL information. |
|
798 | - * |
|
799 | - * @return array |
|
800 | - */ |
|
796 | + /** |
|
797 | + * Returns an array with all relevant URL information. |
|
798 | + * |
|
799 | + * @return array |
|
800 | + */ |
|
801 | 801 | public function toArray() : array |
802 | 802 | { |
803 | 803 | return array( |
@@ -841,24 +841,24 @@ discard block |
||
841 | 841 | return $this; |
842 | 842 | } |
843 | 843 | |
844 | - /** |
|
845 | - * Whether the parameter exclusion mode is enabled: |
|
846 | - * In this case, if any parameters have been added to the |
|
847 | - * exclusion list, all relevant methods will exclude these. |
|
848 | - * |
|
849 | - * @return bool |
|
850 | - */ |
|
844 | + /** |
|
845 | + * Whether the parameter exclusion mode is enabled: |
|
846 | + * In this case, if any parameters have been added to the |
|
847 | + * exclusion list, all relevant methods will exclude these. |
|
848 | + * |
|
849 | + * @return bool |
|
850 | + */ |
|
851 | 851 | public function isParamExclusionEnabled() : bool |
852 | 852 | { |
853 | 853 | return $this->paramExclusion; |
854 | 854 | } |
855 | 855 | |
856 | - /** |
|
857 | - * Checks whether the link contains any parameters that |
|
858 | - * are on the list of excluded parameters. |
|
859 | - * |
|
860 | - * @return bool |
|
861 | - */ |
|
856 | + /** |
|
857 | + * Checks whether the link contains any parameters that |
|
858 | + * are on the list of excluded parameters. |
|
859 | + * |
|
860 | + * @return bool |
|
861 | + */ |
|
862 | 862 | public function containsExcludedParams() : bool |
863 | 863 | { |
864 | 864 | if(empty($this->excludedParams)) { |
@@ -117,26 +117,26 @@ discard block |
||
117 | 117 | |
118 | 118 | $this->filterParsed(); |
119 | 119 | |
120 | - if($this->detectEmail()) { |
|
120 | + if ($this->detectEmail()) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | - if($this->detectFragmentLink()) { |
|
124 | + if ($this->detectFragmentLink()) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | - if($this->detectPhoneLink()) { |
|
128 | + if ($this->detectPhoneLink()) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | 131 | |
132 | - if(!$this->isValid) { |
|
132 | + if (!$this->isValid) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // no scheme found: it may be an email address without the mailto: |
137 | 137 | // It can't be a variable, since without the scheme it would already |
138 | 138 | // have been recognized as a vaiable only link. |
139 | - if(!isset($this->info['scheme'])) { |
|
139 | + if (!isset($this->info['scheme'])) { |
|
140 | 140 | $this->setError( |
141 | 141 | self::ERROR_MISSING_SCHEME, |
142 | 142 | t('Cannot determine the link\'s scheme, e.g. %1$s.', 'http') |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | return; |
146 | 146 | } |
147 | 147 | |
148 | - if(!in_array($this->info['scheme'], $this->knownSchemes)) { |
|
148 | + if (!in_array($this->info['scheme'], $this->knownSchemes)) { |
|
149 | 149 | $this->setError( |
150 | 150 | self::ERROR_INVALID_SCHEME, |
151 | - t('The scheme %1$s is not supported for links.', $this->info['scheme']) . ' ' . |
|
151 | + t('The scheme %1$s is not supported for links.', $this->info['scheme']).' '. |
|
152 | 152 | t('Valid schemes are: %1$s.', implode(', ', $this->knownSchemes)) |
153 | 153 | ); |
154 | 154 | $this->isValid = false; |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | // every link needs a host. This case can happen for ex, if |
159 | 159 | // the link starts with a typo with only one slash, like: |
160 | 160 | // "http:/hostname" |
161 | - if(!isset($this->info['host'])) { |
|
161 | + if (!isset($this->info['host'])) { |
|
162 | 162 | $this->setError( |
163 | 163 | self::ERROR_MISSING_HOST, |
164 | - t('Cannot determine the link\'s host name.') . ' ' . |
|
164 | + t('Cannot determine the link\'s host name.').' '. |
|
165 | 165 | t('This usually happens when there\'s a typo somewhere.') |
166 | 166 | ); |
167 | 167 | $this->isValid = false; |
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | - if(!empty($this->info['query'])) |
|
171 | + if (!empty($this->info['query'])) |
|
172 | 172 | { |
173 | 173 | $this->params = \AppUtils\ConvertHelper::parseQueryString($this->info['query']); |
174 | 174 | ksort($this->params); |
@@ -213,30 +213,30 @@ discard block |
||
213 | 213 | */ |
214 | 214 | protected function filterParsed() |
215 | 215 | { |
216 | - foreach($this->info as $key => $val) |
|
216 | + foreach ($this->info as $key => $val) |
|
217 | 217 | { |
218 | - if(is_string($val)) { |
|
218 | + if (is_string($val)) { |
|
219 | 219 | $this->info[$key] = trim($val); |
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - if(isset($this->info['host'])) { |
|
223 | + if (isset($this->info['host'])) { |
|
224 | 224 | $this->info['host'] = str_replace(' ', '', $this->info['host']); |
225 | 225 | } |
226 | 226 | |
227 | - if(isset($this->info['path'])) { |
|
227 | + if (isset($this->info['path'])) { |
|
228 | 228 | $this->info['path'] = str_replace(' ', '', $this->info['path']); |
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | protected function detectEmail() |
233 | 233 | { |
234 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
234 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
235 | 235 | $this->isEmail = true; |
236 | 236 | return true; |
237 | 237 | } |
238 | 238 | |
239 | - if(isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
239 | + if (isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
240 | 240 | { |
241 | 241 | $this->info['scheme'] = 'email'; |
242 | 242 | $this->isEmail = true; |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | |
249 | 249 | protected function detectFragmentLink() |
250 | 250 | { |
251 | - if(isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
251 | + if (isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
252 | 252 | $this->isFragment = true; |
253 | 253 | return true; |
254 | 254 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | |
259 | 259 | protected function detectPhoneLink() |
260 | 260 | { |
261 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
261 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
262 | 262 | $this->isPhone = true; |
263 | 263 | return true; |
264 | 264 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | */ |
273 | 273 | public function isSecure() |
274 | 274 | { |
275 | - if(isset($this->info['scheme']) && $this->info['scheme']=='https') { |
|
275 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'https') { |
|
276 | 276 | return true; |
277 | 277 | } |
278 | 278 | |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | public function getPort() : int |
348 | 348 | { |
349 | 349 | $port = $this->getInfoKey('port'); |
350 | - if(!empty($port)) { |
|
350 | + if (!empty($port)) { |
|
351 | 351 | return (int)$port; |
352 | 352 | } |
353 | 353 | |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | |
428 | 428 | protected function getInfoKey(string $name) : string |
429 | 429 | { |
430 | - if(isset($this->info[$name])) { |
|
430 | + if (isset($this->info[$name])) { |
|
431 | 431 | return (string)$this->info[$name]; |
432 | 432 | } |
433 | 433 | |
@@ -436,34 +436,34 @@ discard block |
||
436 | 436 | |
437 | 437 | public function getNormalized() : string |
438 | 438 | { |
439 | - if(!$this->isValid) { |
|
439 | + if (!$this->isValid) { |
|
440 | 440 | return ''; |
441 | 441 | } |
442 | 442 | |
443 | - if($this->isFragment === true) |
|
443 | + if ($this->isFragment === true) |
|
444 | 444 | { |
445 | 445 | return '#'.$this->getFragment(); |
446 | 446 | } |
447 | - else if($this->isPhone === true) |
|
447 | + else if ($this->isPhone === true) |
|
448 | 448 | { |
449 | 449 | return 'tel://'.$this->getHost(); |
450 | 450 | } |
451 | - else if($this->isEmail === true) |
|
451 | + else if ($this->isEmail === true) |
|
452 | 452 | { |
453 | 453 | return 'mailto:'.$this->getPath(); |
454 | 454 | } |
455 | 455 | |
456 | 456 | $normalized = $this->info['scheme'].'://'.$this->info['host']; |
457 | - if(isset($this->info['path'])) { |
|
457 | + if (isset($this->info['path'])) { |
|
458 | 458 | $normalized .= $this->info['path']; |
459 | 459 | } |
460 | 460 | |
461 | 461 | $params = $this->getParams(); |
462 | - if(!empty($params)) { |
|
462 | + if (!empty($params)) { |
|
463 | 463 | $normalized .= '?'.http_build_query($params); |
464 | 464 | } |
465 | 465 | |
466 | - if(isset($this->info['fragment'])) { |
|
466 | + if (isset($this->info['fragment'])) { |
|
467 | 467 | $normalized .= '#'.$this->info['fragment']; |
468 | 468 | } |
469 | 469 | |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | */ |
492 | 492 | public function getHighlighted() : string |
493 | 493 | { |
494 | - if(!$this->isValid) { |
|
494 | + if (!$this->isValid) { |
|
495 | 495 | return ''; |
496 | 496 | } |
497 | 497 | |
498 | - if($this->isEmail) { |
|
498 | + if ($this->isEmail) { |
|
499 | 499 | return sprintf( |
500 | 500 | '<span class="link-scheme scheme-mailto">mailto:</span>'. |
501 | 501 | '<span class="link-host">%s</span>', |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | ); |
504 | 504 | } |
505 | 505 | |
506 | - if($this->isFragment) { |
|
506 | + if ($this->isFragment) { |
|
507 | 507 | return sprintf( |
508 | 508 | '<span class="link-fragment-sign">#</span>'. |
509 | 509 | '<span class="link-fragment-value">%s</span>', |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | ); |
512 | 512 | } |
513 | 513 | |
514 | - if($this->hasScheme()) |
|
514 | + if ($this->hasScheme()) |
|
515 | 515 | { |
516 | 516 | $result = sprintf( |
517 | 517 | '<span class="link-scheme scheme-%1$s">'. |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | |
524 | 524 | $result .= '<span class="link-component double-slashes">//</span>'; |
525 | 525 | |
526 | - if($this->hasUsername()) |
|
526 | + if ($this->hasUsername()) |
|
527 | 527 | { |
528 | 528 | $result .= sprintf( |
529 | 529 | '<span class="link-credentials">%s</span>'. |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | ); |
536 | 536 | } |
537 | 537 | |
538 | - if($this->hasHost()) |
|
538 | + if ($this->hasHost()) |
|
539 | 539 | { |
540 | 540 | $result .= |
541 | 541 | sprintf( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | ); |
545 | 545 | } |
546 | 546 | |
547 | - if($this->hasPort()) |
|
547 | + if ($this->hasPort()) |
|
548 | 548 | { |
549 | 549 | $result .= sprintf( |
550 | 550 | '<span class="link-component port-separator">:</span>'. |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | ); |
554 | 554 | } |
555 | 555 | |
556 | - if($this->hasPath()) |
|
556 | + if ($this->hasPath()) |
|
557 | 557 | { |
558 | 558 | $path = str_replace(array(';', '='), array(';<wbr>', '=<wbr>'), $this->getPath()); |
559 | 559 | $tokens = explode('/', $path); |
@@ -564,11 +564,11 @@ discard block |
||
564 | 564 | ); |
565 | 565 | } |
566 | 566 | |
567 | - if(!empty($this->params)) |
|
567 | + if (!empty($this->params)) |
|
568 | 568 | { |
569 | 569 | $tokens = array(); |
570 | 570 | |
571 | - foreach($this->params as $param => $value) |
|
571 | + foreach ($this->params as $param => $value) |
|
572 | 572 | { |
573 | 573 | $parts = sprintf( |
574 | 574 | '<span class="link-param-name">%s</span>'. |
@@ -586,10 +586,10 @@ discard block |
||
586 | 586 | $tag = ''; |
587 | 587 | |
588 | 588 | // is parameter exclusion enabled, and is this an excluded parameter? |
589 | - if($this->paramExclusion && isset($this->excludedParams[$param])) |
|
589 | + if ($this->paramExclusion && isset($this->excludedParams[$param])) |
|
590 | 590 | { |
591 | 591 | // display the excluded parameter, but highlight it |
592 | - if($this->highlightExcluded) |
|
592 | + if ($this->highlightExcluded) |
|
593 | 593 | { |
594 | 594 | $tooltip = $this->excludedParams[$param]; |
595 | 595 | |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | '<span class="link-component query-sign">?</span>'.implode('<span class="link-component param-separator">&</span>', $tokens); |
620 | 620 | } |
621 | 621 | |
622 | - if(isset($this->info['fragment'])) { |
|
622 | + if (isset($this->info['fragment'])) { |
|
623 | 623 | $result .= sprintf( |
624 | 624 | '<span class="link-fragment-sign">#</span>'. |
625 | 625 | '<span class="link-fragment">%s</span>', |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | |
643 | 643 | public function getErrorMessage() : string |
644 | 644 | { |
645 | - if(isset($this->error)) { |
|
645 | + if (isset($this->error)) { |
|
646 | 646 | return $this->error['message']; |
647 | 647 | } |
648 | 648 | |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | |
652 | 652 | public function getErrorCode() : int |
653 | 653 | { |
654 | - if(isset($this->error)) { |
|
654 | + if (isset($this->error)) { |
|
655 | 655 | return $this->error['code']; |
656 | 656 | } |
657 | 657 | |
@@ -681,13 +681,13 @@ discard block |
||
681 | 681 | */ |
682 | 682 | public function getParams() : array |
683 | 683 | { |
684 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
684 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
685 | 685 | return $this->params; |
686 | 686 | } |
687 | 687 | |
688 | 688 | $keep = array(); |
689 | - foreach($this->params as $name => $value) { |
|
690 | - if(!isset($this->excludedParams[$name])) { |
|
689 | + foreach ($this->params as $name => $value) { |
|
690 | + if (!isset($this->excludedParams[$name])) { |
|
691 | 691 | $keep[$name] = $value; |
692 | 692 | } |
693 | 693 | } |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | */ |
718 | 718 | public function excludeParam(string $name, string $reason) : URLInfo |
719 | 719 | { |
720 | - if(!isset($this->excludedParams[$name])) |
|
720 | + if (!isset($this->excludedParams[$name])) |
|
721 | 721 | { |
722 | 722 | $this->excludedParams[$name] = $reason; |
723 | 723 | $this->setParamExclusion(); |
@@ -738,15 +738,15 @@ discard block |
||
738 | 738 | */ |
739 | 739 | public function getType() : string |
740 | 740 | { |
741 | - if($this->isEmail) { |
|
741 | + if ($this->isEmail) { |
|
742 | 742 | return self::TYPE_EMAIL; |
743 | 743 | } |
744 | 744 | |
745 | - if($this->isFragment) { |
|
745 | + if ($this->isFragment) { |
|
746 | 746 | return self::TYPE_FRAGMENT; |
747 | 747 | } |
748 | 748 | |
749 | - if($this->isPhone) { |
|
749 | + if ($this->isPhone) { |
|
750 | 750 | return self::TYPE_PHONE; |
751 | 751 | } |
752 | 752 | |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | |
756 | 756 | public function getTypeLabel() : string |
757 | 757 | { |
758 | - if(!isset(self::$typeLabels)) |
|
758 | + if (!isset(self::$typeLabels)) |
|
759 | 759 | { |
760 | 760 | self::$typeLabels = array( |
761 | 761 | self::TYPE_EMAIL => t('Email'), |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | |
768 | 768 | $type = $this->getType(); |
769 | 769 | |
770 | - if(!isset(self::$typeLabels[$type])) |
|
770 | + if (!isset(self::$typeLabels[$type])) |
|
771 | 771 | { |
772 | 772 | throw new BaseException( |
773 | 773 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -787,7 +787,7 @@ discard block |
||
787 | 787 | * @param bool $highlight |
788 | 788 | * @return URLInfo |
789 | 789 | */ |
790 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
790 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
791 | 791 | { |
792 | 792 | $this->highlightExcluded = $highlight; |
793 | 793 | return $this; |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | * @see URLInfo::isParamExclusionEnabled() |
836 | 836 | * @see URLInfo::setHighlightExcluded() |
837 | 837 | */ |
838 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
838 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
839 | 839 | { |
840 | 840 | $this->paramExclusion = $enabled; |
841 | 841 | return $this; |
@@ -861,13 +861,13 @@ discard block |
||
861 | 861 | */ |
862 | 862 | public function containsExcludedParams() : bool |
863 | 863 | { |
864 | - if(empty($this->excludedParams)) { |
|
864 | + if (empty($this->excludedParams)) { |
|
865 | 865 | return false; |
866 | 866 | } |
867 | 867 | |
868 | 868 | $names = array_keys($this->params); |
869 | - foreach($names as $name) { |
|
870 | - if(isset($this->excludedParams[$name])) { |
|
869 | + foreach ($names as $name) { |
|
870 | + if (isset($this->excludedParams[$name])) { |
|
871 | 871 | return true; |
872 | 872 | } |
873 | 873 | } |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | |
884 | 884 | public function offsetSet($offset, $value) |
885 | 885 | { |
886 | - if(in_array($offset, $this->infoKeys)) { |
|
886 | + if (in_array($offset, $this->infoKeys)) { |
|
887 | 887 | $this->info[$offset] = $value; |
888 | 888 | } |
889 | 889 | } |
@@ -900,11 +900,11 @@ discard block |
||
900 | 900 | |
901 | 901 | public function offsetGet($offset) |
902 | 902 | { |
903 | - if($offset === 'port') { |
|
903 | + if ($offset === 'port') { |
|
904 | 904 | return $this->getPort(); |
905 | 905 | } |
906 | 906 | |
907 | - if(in_array($offset, $this->infoKeys)) { |
|
907 | + if (in_array($offset, $this->infoKeys)) { |
|
908 | 908 | return $this->getInfoKey($offset); |
909 | 909 | } |
910 | 910 | |
@@ -915,7 +915,7 @@ discard block |
||
915 | 915 | { |
916 | 916 | $cssFolder = realpath(__DIR__.'/../css'); |
917 | 917 | |
918 | - if($cssFolder === false) { |
|
918 | + if ($cssFolder === false) { |
|
919 | 919 | throw new BaseException( |
920 | 920 | 'Cannot find package CSS folder.', |
921 | 921 | null, |
@@ -443,12 +443,10 @@ discard block |
||
443 | 443 | if($this->isFragment === true) |
444 | 444 | { |
445 | 445 | return '#'.$this->getFragment(); |
446 | - } |
|
447 | - else if($this->isPhone === true) |
|
446 | + } else if($this->isPhone === true) |
|
448 | 447 | { |
449 | 448 | return 'tel://'.$this->getHost(); |
450 | - } |
|
451 | - else if($this->isEmail === true) |
|
449 | + } else if($this->isEmail === true) |
|
452 | 450 | { |
453 | 451 | return 'mailto:'.$this->getPath(); |
454 | 452 | } |
@@ -598,13 +596,11 @@ discard block |
||
598 | 596 | $tooltip, |
599 | 597 | $parts |
600 | 598 | ); |
601 | - } |
|
602 | - else |
|
599 | + } else |
|
603 | 600 | { |
604 | 601 | continue; |
605 | 602 | } |
606 | - } |
|
607 | - else |
|
603 | + } else |
|
608 | 604 | { |
609 | 605 | $tag = sprintf( |
610 | 606 | '<span class="link-param">%s</span>', |
@@ -422,16 +422,16 @@ discard block |
||
422 | 422 | return $bytes . ' ' . t('B'); |
423 | 423 | } |
424 | 424 | |
425 | - /** |
|
426 | - * Cuts a text to the specified length if it is longer than the |
|
427 | - * target length. Appends a text to signify it has been cut at |
|
428 | - * the end of the string. |
|
429 | - * |
|
430 | - * @param string $text |
|
431 | - * @param int $targetLength |
|
432 | - * @param string $append |
|
433 | - * @return string |
|
434 | - */ |
|
425 | + /** |
|
426 | + * Cuts a text to the specified length if it is longer than the |
|
427 | + * target length. Appends a text to signify it has been cut at |
|
428 | + * the end of the string. |
|
429 | + * |
|
430 | + * @param string $text |
|
431 | + * @param int $targetLength |
|
432 | + * @param string $append |
|
433 | + * @return string |
|
434 | + */ |
|
435 | 435 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
436 | 436 | { |
437 | 437 | $length = mb_strlen($text); |
@@ -501,27 +501,27 @@ discard block |
||
501 | 501 | return self::$booleanStrings[$string]; |
502 | 502 | } |
503 | 503 | |
504 | - /** |
|
505 | - * Whether the specified string is a boolean string or boolean value. |
|
506 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
507 | - * |
|
508 | - * @param mixed $string |
|
509 | - * @return bool |
|
510 | - * @deprecated |
|
511 | - * @see ConvertHelper::isBoolean() |
|
512 | - */ |
|
504 | + /** |
|
505 | + * Whether the specified string is a boolean string or boolean value. |
|
506 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
507 | + * |
|
508 | + * @param mixed $string |
|
509 | + * @return bool |
|
510 | + * @deprecated |
|
511 | + * @see ConvertHelper::isBoolean() |
|
512 | + */ |
|
513 | 513 | public static function isBooleanString($string) : bool |
514 | 514 | { |
515 | 515 | return self::isBoolean($string); |
516 | 516 | } |
517 | 517 | |
518 | - /** |
|
519 | - * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
520 | - * |
|
521 | - * @param string $text |
|
522 | - * @return string |
|
523 | - * @deprecated |
|
524 | - */ |
|
518 | + /** |
|
519 | + * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
520 | + * |
|
521 | + * @param string $text |
|
522 | + * @return string |
|
523 | + * @deprecated |
|
524 | + */ |
|
525 | 525 | public static function text_makeXMLCompliant($text) |
526 | 526 | { |
527 | 527 | return XMLHelper::string2xml($text); |
@@ -623,13 +623,13 @@ discard block |
||
623 | 623 | return $translit->convert($string); |
624 | 624 | } |
625 | 625 | |
626 | - /** |
|
627 | - * Retrieves the HEX character codes for all control |
|
628 | - * characters that the {@link stripControlCharacters()} |
|
629 | - * method will remove. |
|
630 | - * |
|
631 | - * @return string[] |
|
632 | - */ |
|
626 | + /** |
|
627 | + * Retrieves the HEX character codes for all control |
|
628 | + * characters that the {@link stripControlCharacters()} |
|
629 | + * method will remove. |
|
630 | + * |
|
631 | + * @return string[] |
|
632 | + */ |
|
633 | 633 | public static function getControlCharactersAsHex() |
634 | 634 | { |
635 | 635 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
@@ -665,13 +665,13 @@ discard block |
||
665 | 665 | return $stack; |
666 | 666 | } |
667 | 667 | |
668 | - /** |
|
669 | - * Retrieves an array of all control characters that |
|
670 | - * the {@link stripControlCharacters()} method will |
|
671 | - * remove, as the actual UTF-8 characters. |
|
672 | - * |
|
673 | - * @return string[] |
|
674 | - */ |
|
668 | + /** |
|
669 | + * Retrieves an array of all control characters that |
|
670 | + * the {@link stripControlCharacters()} method will |
|
671 | + * remove, as the actual UTF-8 characters. |
|
672 | + * |
|
673 | + * @return string[] |
|
674 | + */ |
|
675 | 675 | public static function getControlCharactersAsUTF8() |
676 | 676 | { |
677 | 677 | $chars = self::getControlCharactersAsHex(); |
@@ -684,12 +684,12 @@ discard block |
||
684 | 684 | return $result; |
685 | 685 | } |
686 | 686 | |
687 | - /** |
|
688 | - * Retrieves all control characters as JSON encoded |
|
689 | - * characters, e.g. "\u200b". |
|
690 | - * |
|
691 | - * @return string[] |
|
692 | - */ |
|
687 | + /** |
|
688 | + * Retrieves all control characters as JSON encoded |
|
689 | + * characters, e.g. "\u200b". |
|
690 | + * |
|
691 | + * @return string[] |
|
692 | + */ |
|
693 | 693 | public static function getControlCharactersAsJSON() |
694 | 694 | { |
695 | 695 | $chars = self::getControlCharactersAsHex(); |
@@ -757,20 +757,20 @@ discard block |
||
757 | 757 | return preg_replace(self::$controlCharsRegex, '', $string); |
758 | 758 | } |
759 | 759 | |
760 | - /** |
|
761 | - * Converts a unicode character to the PHPO notation. |
|
762 | - * |
|
763 | - * Example: |
|
764 | - * |
|
765 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
766 | - * |
|
767 | - * Returns |
|
768 | - * |
|
769 | - * <pre>\x0</pre> |
|
770 | - * |
|
771 | - * @param string $unicodeChar |
|
772 | - * @return string |
|
773 | - */ |
|
760 | + /** |
|
761 | + * Converts a unicode character to the PHPO notation. |
|
762 | + * |
|
763 | + * Example: |
|
764 | + * |
|
765 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
766 | + * |
|
767 | + * Returns |
|
768 | + * |
|
769 | + * <pre>\x0</pre> |
|
770 | + * |
|
771 | + * @param string $unicodeChar |
|
772 | + * @return string |
|
773 | + */ |
|
774 | 774 | public static function unicodeChar2php($unicodeChar) |
775 | 775 | { |
776 | 776 | $unicodeChar = json_decode($unicodeChar); |
@@ -893,25 +893,25 @@ discard block |
||
893 | 893 | return 'false'; |
894 | 894 | } |
895 | 895 | |
896 | - /** |
|
897 | - * Converts an associative array with attribute name > value pairs |
|
898 | - * to an attribute string that can be used in an HTML tag. Empty |
|
899 | - * attribute values are ignored. |
|
900 | - * |
|
901 | - * Example: |
|
902 | - * |
|
903 | - * array2attributeString(array( |
|
904 | - * 'id' => 45, |
|
905 | - * 'href' => 'http://www.mistralys.com' |
|
906 | - * )); |
|
907 | - * |
|
908 | - * Result: |
|
909 | - * |
|
910 | - * id="45" href="http://www.mistralys.com" |
|
911 | - * |
|
912 | - * @param array $array |
|
913 | - * @return string |
|
914 | - */ |
|
896 | + /** |
|
897 | + * Converts an associative array with attribute name > value pairs |
|
898 | + * to an attribute string that can be used in an HTML tag. Empty |
|
899 | + * attribute values are ignored. |
|
900 | + * |
|
901 | + * Example: |
|
902 | + * |
|
903 | + * array2attributeString(array( |
|
904 | + * 'id' => 45, |
|
905 | + * 'href' => 'http://www.mistralys.com' |
|
906 | + * )); |
|
907 | + * |
|
908 | + * Result: |
|
909 | + * |
|
910 | + * id="45" href="http://www.mistralys.com" |
|
911 | + * |
|
912 | + * @param array $array |
|
913 | + * @return string |
|
914 | + */ |
|
915 | 915 | public static function array2attributeString($array) |
916 | 916 | { |
917 | 917 | $tokens = array(); |
@@ -930,14 +930,14 @@ discard block |
||
930 | 930 | return ' '.implode(' ', $tokens); |
931 | 931 | } |
932 | 932 | |
933 | - /** |
|
934 | - * Converts a string so it can safely be used in a javascript |
|
935 | - * statement in an HTML tag: uses single quotes around the string |
|
936 | - * and encodes all special characters as needed. |
|
937 | - * |
|
938 | - * @param string $string |
|
939 | - * @return string |
|
940 | - */ |
|
933 | + /** |
|
934 | + * Converts a string so it can safely be used in a javascript |
|
935 | + * statement in an HTML tag: uses single quotes around the string |
|
936 | + * and encodes all special characters as needed. |
|
937 | + * |
|
938 | + * @param string $string |
|
939 | + * @return string |
|
940 | + */ |
|
941 | 941 | public static function string2attributeJS($string, $quoted=true) |
942 | 942 | { |
943 | 943 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
@@ -948,15 +948,15 @@ discard block |
||
948 | 948 | return $converted; |
949 | 949 | } |
950 | 950 | |
951 | - /** |
|
952 | - * Checks if the specified string is a boolean value, which |
|
953 | - * includes string representations of boolean values, like |
|
954 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
955 | - * or <code>false</code>. |
|
956 | - * |
|
957 | - * @param string|boolean $value |
|
958 | - * @return boolean |
|
959 | - */ |
|
951 | + /** |
|
952 | + * Checks if the specified string is a boolean value, which |
|
953 | + * includes string representations of boolean values, like |
|
954 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
955 | + * or <code>false</code>. |
|
956 | + * |
|
957 | + * @param string|boolean $value |
|
958 | + * @return boolean |
|
959 | + */ |
|
960 | 960 | public static function isBoolean($value) |
961 | 961 | { |
962 | 962 | if(is_bool($value)) { |
@@ -970,12 +970,12 @@ discard block |
||
970 | 970 | return array_key_exists($value, self::$booleanStrings); |
971 | 971 | } |
972 | 972 | |
973 | - /** |
|
974 | - * Converts an associative array to an HTML style attribute value string. |
|
975 | - * |
|
976 | - * @param string $subject |
|
977 | - * @return string |
|
978 | - */ |
|
973 | + /** |
|
974 | + * Converts an associative array to an HTML style attribute value string. |
|
975 | + * |
|
976 | + * @param string $subject |
|
977 | + * @return string |
|
978 | + */ |
|
979 | 979 | public static function array2styleString($subject) |
980 | 980 | { |
981 | 981 | $tokens = array(); |
@@ -986,23 +986,23 @@ discard block |
||
986 | 986 | return implode(';', $tokens); |
987 | 987 | } |
988 | 988 | |
989 | - /** |
|
990 | - * Converts a DateTime object to a timestamp, which |
|
991 | - * is PHP 5.2 compatible. |
|
992 | - * |
|
993 | - * @param \DateTime $date |
|
994 | - * @return integer |
|
995 | - */ |
|
989 | + /** |
|
990 | + * Converts a DateTime object to a timestamp, which |
|
991 | + * is PHP 5.2 compatible. |
|
992 | + * |
|
993 | + * @param \DateTime $date |
|
994 | + * @return integer |
|
995 | + */ |
|
996 | 996 | public static function date2timestamp(\DateTime $date) |
997 | 997 | { |
998 | 998 | return $date->format('U'); |
999 | 999 | } |
1000 | 1000 | |
1001 | - /** |
|
1002 | - * Converts a timestamp into a DateTime instance. |
|
1003 | - * @param int $timestamp |
|
1004 | - * @return \DateTime |
|
1005 | - */ |
|
1001 | + /** |
|
1002 | + * Converts a timestamp into a DateTime instance. |
|
1003 | + * @param int $timestamp |
|
1004 | + * @return \DateTime |
|
1005 | + */ |
|
1006 | 1006 | public static function timestamp2date($timestamp) |
1007 | 1007 | { |
1008 | 1008 | $date = new \DateTime(); |
@@ -1010,13 +1010,13 @@ discard block |
||
1010 | 1010 | return $date; |
1011 | 1011 | } |
1012 | 1012 | |
1013 | - /** |
|
1014 | - * Strips an absolute path to a file within the application |
|
1015 | - * to make the path relative to the application root path. |
|
1016 | - * |
|
1017 | - * @param string $path |
|
1018 | - * @return string |
|
1019 | - */ |
|
1013 | + /** |
|
1014 | + * Strips an absolute path to a file within the application |
|
1015 | + * to make the path relative to the application root path. |
|
1016 | + * |
|
1017 | + * @param string $path |
|
1018 | + * @return string |
|
1019 | + */ |
|
1020 | 1020 | public static function fileRelativize($path) |
1021 | 1021 | { |
1022 | 1022 | $path = str_replace('\\', '/', $path); |
@@ -1028,22 +1028,22 @@ discard block |
||
1028 | 1028 | |
1029 | 1029 | const JS_REGEX_JSON = 'json'; |
1030 | 1030 | |
1031 | - /** |
|
1032 | - * Takes a regular expression and attempts to convert it to |
|
1033 | - * its javascript equivalent. Returns an array containing the |
|
1034 | - * format string itself (without start and end characters), |
|
1035 | - * and the modifiers. |
|
1036 | - * |
|
1037 | - * This is intended to be used with the RegExp object, for ex: |
|
1038 | - * |
|
1039 | - * <script> |
|
1040 | - * var expression = <?php echo json_encode(ConvertHelper::regex2js('/ab+c/i')) ?>; |
|
1041 | - * var reg = new RegExp(expression.format, expression.modifiers); |
|
1042 | - * </script> |
|
1043 | - * |
|
1044 | - * @param string $regex |
|
1045 | - * @return array |
|
1046 | - */ |
|
1031 | + /** |
|
1032 | + * Takes a regular expression and attempts to convert it to |
|
1033 | + * its javascript equivalent. Returns an array containing the |
|
1034 | + * format string itself (without start and end characters), |
|
1035 | + * and the modifiers. |
|
1036 | + * |
|
1037 | + * This is intended to be used with the RegExp object, for ex: |
|
1038 | + * |
|
1039 | + * <script> |
|
1040 | + * var expression = <?php echo json_encode(ConvertHelper::regex2js('/ab+c/i')) ?>; |
|
1041 | + * var reg = new RegExp(expression.format, expression.modifiers); |
|
1042 | + * </script> |
|
1043 | + * |
|
1044 | + * @param string $regex |
|
1045 | + * @return array |
|
1046 | + */ |
|
1047 | 1047 | public static function regex2js($regex, $return=self::JS_REGEX_OBJECT) |
1048 | 1048 | { |
1049 | 1049 | $regex = trim($regex); |
@@ -1089,12 +1089,12 @@ discard block |
||
1089 | 1089 | ); |
1090 | 1090 | } |
1091 | 1091 | |
1092 | - /** |
|
1093 | - * Strips all known UTF byte order marks from the specified string. |
|
1094 | - * |
|
1095 | - * @param string $string |
|
1096 | - * @return string |
|
1097 | - */ |
|
1092 | + /** |
|
1093 | + * Strips all known UTF byte order marks from the specified string. |
|
1094 | + * |
|
1095 | + * @param string $string |
|
1096 | + * @return string |
|
1097 | + */ |
|
1098 | 1098 | public static function stripUTFBom($string) |
1099 | 1099 | { |
1100 | 1100 | $boms = FileHelper::getUTFBOMs(); |
@@ -1109,13 +1109,13 @@ discard block |
||
1109 | 1109 | return $string; |
1110 | 1110 | } |
1111 | 1111 | |
1112 | - /** |
|
1113 | - * Converts a string to valid utf8, regardless |
|
1114 | - * of the string's encoding(s). |
|
1115 | - * |
|
1116 | - * @param string $string |
|
1117 | - * @return string |
|
1118 | - */ |
|
1112 | + /** |
|
1113 | + * Converts a string to valid utf8, regardless |
|
1114 | + * of the string's encoding(s). |
|
1115 | + * |
|
1116 | + * @param string $string |
|
1117 | + * @return string |
|
1118 | + */ |
|
1119 | 1119 | public static function string2utf8($string) |
1120 | 1120 | { |
1121 | 1121 | if(!self::isStringASCII($string)) { |
@@ -1125,15 +1125,15 @@ discard block |
||
1125 | 1125 | return $string; |
1126 | 1126 | } |
1127 | 1127 | |
1128 | - /** |
|
1129 | - * Checks whether the specified string is an ASCII |
|
1130 | - * string, without any special or UTF8 characters. |
|
1131 | - * Note: empty strings and NULL are considered ASCII. |
|
1132 | - * Any variable types other than strings are not. |
|
1133 | - * |
|
1134 | - * @param string $string |
|
1135 | - * @return boolean |
|
1136 | - */ |
|
1128 | + /** |
|
1129 | + * Checks whether the specified string is an ASCII |
|
1130 | + * string, without any special or UTF8 characters. |
|
1131 | + * Note: empty strings and NULL are considered ASCII. |
|
1132 | + * Any variable types other than strings are not. |
|
1133 | + * |
|
1134 | + * @param string $string |
|
1135 | + * @return boolean |
|
1136 | + */ |
|
1137 | 1137 | public static function isStringASCII($string) |
1138 | 1138 | { |
1139 | 1139 | if($string === '' || $string === NULL) { |
@@ -1158,22 +1158,22 @@ discard block |
||
1158 | 1158 | return $url; |
1159 | 1159 | } |
1160 | 1160 | |
1161 | - /** |
|
1162 | - * Calculates a percentage match of the source string with the target string. |
|
1163 | - * |
|
1164 | - * Options are: |
|
1165 | - * |
|
1166 | - * - maxLevenshtein, default: 10 |
|
1167 | - * Any levenshtein results above this value are ignored. |
|
1168 | - * |
|
1169 | - * - precision, default: 1 |
|
1170 | - * The precision of the percentage float value |
|
1171 | - * |
|
1172 | - * @param string $source |
|
1173 | - * @param string $target |
|
1174 | - * @param array $options |
|
1175 | - * @return float |
|
1176 | - */ |
|
1161 | + /** |
|
1162 | + * Calculates a percentage match of the source string with the target string. |
|
1163 | + * |
|
1164 | + * Options are: |
|
1165 | + * |
|
1166 | + * - maxLevenshtein, default: 10 |
|
1167 | + * Any levenshtein results above this value are ignored. |
|
1168 | + * |
|
1169 | + * - precision, default: 1 |
|
1170 | + * The precision of the percentage float value |
|
1171 | + * |
|
1172 | + * @param string $source |
|
1173 | + * @param string $target |
|
1174 | + * @param array $options |
|
1175 | + * @return float |
|
1176 | + */ |
|
1177 | 1177 | public static function matchString($source, $target, $options=array()) |
1178 | 1178 | { |
1179 | 1179 | $defaults = array( |
@@ -1257,14 +1257,14 @@ discard block |
||
1257 | 1257 | |
1258 | 1258 | const INTERVAL_SECONDS = 'seconds'; |
1259 | 1259 | |
1260 | - /** |
|
1261 | - * Calculates the total amount of days / hours / minutes or seconds |
|
1262 | - * of a date interval object and returns the value. |
|
1263 | - * |
|
1264 | - * @param \DateInterval $interval |
|
1265 | - * @param string $unit |
|
1266 | - * @return integer |
|
1267 | - */ |
|
1260 | + /** |
|
1261 | + * Calculates the total amount of days / hours / minutes or seconds |
|
1262 | + * of a date interval object and returns the value. |
|
1263 | + * |
|
1264 | + * @param \DateInterval $interval |
|
1265 | + * @param string $unit |
|
1266 | + * @return integer |
|
1267 | + */ |
|
1268 | 1268 | public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) |
1269 | 1269 | { |
1270 | 1270 | $total = $interval->format('%a'); |
@@ -1302,13 +1302,13 @@ discard block |
||
1302 | 1302 | 'Sunday' |
1303 | 1303 | ); |
1304 | 1304 | |
1305 | - /** |
|
1306 | - * Converts a date to the corresponding day name. |
|
1307 | - * |
|
1308 | - * @param \DateTime $date |
|
1309 | - * @param string $short |
|
1310 | - * @return string|NULL |
|
1311 | - */ |
|
1305 | + /** |
|
1306 | + * Converts a date to the corresponding day name. |
|
1307 | + * |
|
1308 | + * @param \DateTime $date |
|
1309 | + * @param string $short |
|
1310 | + * @return string|NULL |
|
1311 | + */ |
|
1312 | 1312 | public static function date2dayName(\DateTime $date, $short=false) |
1313 | 1313 | { |
1314 | 1314 | $day = $date->format('l'); |
@@ -1323,21 +1323,21 @@ discard block |
||
1323 | 1323 | return null; |
1324 | 1324 | } |
1325 | 1325 | |
1326 | - /** |
|
1327 | - * Retrieves a list of english day names. |
|
1328 | - * @return string[] |
|
1329 | - */ |
|
1326 | + /** |
|
1327 | + * Retrieves a list of english day names. |
|
1328 | + * @return string[] |
|
1329 | + */ |
|
1330 | 1330 | public static function getDayNamesInvariant() |
1331 | 1331 | { |
1332 | 1332 | return self::$daysInvariant; |
1333 | 1333 | } |
1334 | 1334 | |
1335 | - /** |
|
1336 | - * Retrieves the day names list for the current locale. |
|
1337 | - * |
|
1338 | - * @param string $short |
|
1339 | - * @return string[] |
|
1340 | - */ |
|
1335 | + /** |
|
1336 | + * Retrieves the day names list for the current locale. |
|
1337 | + * |
|
1338 | + * @param string $short |
|
1339 | + * @return string[] |
|
1340 | + */ |
|
1341 | 1341 | public static function getDayNames($short=false) |
1342 | 1342 | { |
1343 | 1343 | if($short) { |
@@ -1397,25 +1397,25 @@ discard block |
||
1397 | 1397 | return $last; |
1398 | 1398 | } |
1399 | 1399 | |
1400 | - /** |
|
1401 | - * Splits a string into an array of all characters it is composed of. |
|
1402 | - * Spaces and newlines (both \r and \n) are also considered single |
|
1403 | - * characters. UTF-8 character safe. |
|
1404 | - * |
|
1405 | - * @param string $string |
|
1406 | - * @return string[] |
|
1407 | - */ |
|
1400 | + /** |
|
1401 | + * Splits a string into an array of all characters it is composed of. |
|
1402 | + * Spaces and newlines (both \r and \n) are also considered single |
|
1403 | + * characters. UTF-8 character safe. |
|
1404 | + * |
|
1405 | + * @param string $string |
|
1406 | + * @return string[] |
|
1407 | + */ |
|
1408 | 1408 | public static function string2array($string) |
1409 | 1409 | { |
1410 | 1410 | return preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
1411 | 1411 | } |
1412 | 1412 | |
1413 | - /** |
|
1414 | - * Checks whether the specified string contains HTML code. |
|
1415 | - * |
|
1416 | - * @param string $string |
|
1417 | - * @return boolean |
|
1418 | - */ |
|
1413 | + /** |
|
1414 | + * Checks whether the specified string contains HTML code. |
|
1415 | + * |
|
1416 | + * @param string $string |
|
1417 | + * @return boolean |
|
1418 | + */ |
|
1419 | 1419 | public static function isStringHTML($string) |
1420 | 1420 | { |
1421 | 1421 | if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
@@ -1430,18 +1430,18 @@ discard block |
||
1430 | 1430 | return false; |
1431 | 1431 | } |
1432 | 1432 | |
1433 | - /** |
|
1434 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
1435 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
1436 | - * are no calculated correctly. |
|
1437 | - * |
|
1438 | - * @param string $str |
|
1439 | - * @param int $width |
|
1440 | - * @param string $break |
|
1441 | - * @param bool $cut |
|
1442 | - * @return string |
|
1443 | - * @see https://stackoverflow.com/a/4988494/2298192 |
|
1444 | - */ |
|
1433 | + /** |
|
1434 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
1435 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
1436 | + * are no calculated correctly. |
|
1437 | + * |
|
1438 | + * @param string $str |
|
1439 | + * @param int $width |
|
1440 | + * @param string $break |
|
1441 | + * @param bool $cut |
|
1442 | + * @return string |
|
1443 | + * @see https://stackoverflow.com/a/4988494/2298192 |
|
1444 | + */ |
|
1445 | 1445 | public static function wordwrap($str, $width = 75, $break = "\n", $cut = false) |
1446 | 1446 | { |
1447 | 1447 | $lines = explode($break, $str); |
@@ -1487,27 +1487,27 @@ discard block |
||
1487 | 1487 | return implode($break, $lines); |
1488 | 1488 | } |
1489 | 1489 | |
1490 | - /** |
|
1491 | - * Calculates the byte length of a string, taking into |
|
1492 | - * account any unicode characters. |
|
1493 | - * |
|
1494 | - * @param string $string |
|
1495 | - * @return int |
|
1496 | - * @see https://stackoverflow.com/a/9718273/2298192 |
|
1497 | - */ |
|
1490 | + /** |
|
1491 | + * Calculates the byte length of a string, taking into |
|
1492 | + * account any unicode characters. |
|
1493 | + * |
|
1494 | + * @param string $string |
|
1495 | + * @return int |
|
1496 | + * @see https://stackoverflow.com/a/9718273/2298192 |
|
1497 | + */ |
|
1498 | 1498 | public static function string2bytes($string) |
1499 | 1499 | { |
1500 | 1500 | return mb_strlen($string, '8bit'); |
1501 | 1501 | } |
1502 | 1502 | |
1503 | - /** |
|
1504 | - * Creates a short, 8-character long hash for the specified string. |
|
1505 | - * |
|
1506 | - * WARNING: Not cryptographically safe. |
|
1507 | - * |
|
1508 | - * @param string $string |
|
1509 | - * @return string |
|
1510 | - */ |
|
1503 | + /** |
|
1504 | + * Creates a short, 8-character long hash for the specified string. |
|
1505 | + * |
|
1506 | + * WARNING: Not cryptographically safe. |
|
1507 | + * |
|
1508 | + * @param string $string |
|
1509 | + * @return string |
|
1510 | + */ |
|
1511 | 1511 | public static function string2shortHash($string) |
1512 | 1512 | { |
1513 | 1513 | return hash('crc32', $string, false); |
@@ -1533,23 +1533,23 @@ discard block |
||
1533 | 1533 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
1534 | 1534 | } |
1535 | 1535 | |
1536 | - /** |
|
1537 | - * Parses the specified query string like the native |
|
1538 | - * function <code>parse_str</code>, without the key |
|
1539 | - * naming limitations. |
|
1540 | - * |
|
1541 | - * Using parse_str, dots or spaces in key names are |
|
1542 | - * replaced by underscores. This method keeps all names |
|
1543 | - * intact. |
|
1544 | - * |
|
1545 | - * It still uses the parse_str implementation as it |
|
1546 | - * is tested and tried, but fixes the parameter names |
|
1547 | - * after parsing, as needed. |
|
1548 | - * |
|
1549 | - * @param string $queryString |
|
1550 | - * @return array |
|
1551 | - * @see https://www.php.net/manual/en/function.parse-str.php |
|
1552 | - */ |
|
1536 | + /** |
|
1537 | + * Parses the specified query string like the native |
|
1538 | + * function <code>parse_str</code>, without the key |
|
1539 | + * naming limitations. |
|
1540 | + * |
|
1541 | + * Using parse_str, dots or spaces in key names are |
|
1542 | + * replaced by underscores. This method keeps all names |
|
1543 | + * intact. |
|
1544 | + * |
|
1545 | + * It still uses the parse_str implementation as it |
|
1546 | + * is tested and tried, but fixes the parameter names |
|
1547 | + * after parsing, as needed. |
|
1548 | + * |
|
1549 | + * @param string $queryString |
|
1550 | + * @return array |
|
1551 | + * @see https://www.php.net/manual/en/function.parse-str.php |
|
1552 | + */ |
|
1553 | 1553 | public static function parseQueryString(string $queryString) : array |
1554 | 1554 | { |
1555 | 1555 | // allow HTML entities notation |
@@ -1588,16 +1588,16 @@ discard block |
||
1588 | 1588 | $placeholders = array(); |
1589 | 1589 | foreach($paramNames as $paramName) |
1590 | 1590 | { |
1591 | - // create a unique placeholder name |
|
1592 | - $placeholder = '__PLACEHOLDER'.$counter.'__'; |
|
1591 | + // create a unique placeholder name |
|
1592 | + $placeholder = '__PLACEHOLDER'.$counter.'__'; |
|
1593 | 1593 | |
1594 | - // store the placeholder name to replace later |
|
1595 | - $table[$placeholder] = $paramName; |
|
1594 | + // store the placeholder name to replace later |
|
1595 | + $table[$placeholder] = $paramName; |
|
1596 | 1596 | |
1597 | - // add the placeholder to replace in the query string before parsing |
|
1598 | - $placeholders[$paramName.'='] = $placeholder.'='; |
|
1597 | + // add the placeholder to replace in the query string before parsing |
|
1598 | + $placeholders[$paramName.'='] = $placeholder.'='; |
|
1599 | 1599 | |
1600 | - $counter++; |
|
1600 | + $counter++; |
|
1601 | 1601 | } |
1602 | 1602 | |
1603 | 1603 | // next challenge: replacing the parameter names by placeholders |
@@ -1624,24 +1624,24 @@ discard block |
||
1624 | 1624 | |
1625 | 1625 | foreach($parsed as $name => $value) |
1626 | 1626 | { |
1627 | - $keep[$table[$name]] = $value; |
|
1627 | + $keep[$table[$name]] = $value; |
|
1628 | 1628 | } |
1629 | 1629 | |
1630 | 1630 | |
1631 | 1631 | return $keep; |
1632 | 1632 | } |
1633 | 1633 | |
1634 | - /** |
|
1635 | - * Searches for needle in the specified string, and returns a list |
|
1636 | - * of all occurrences, including the matched string. The matched |
|
1637 | - * string is useful when doing a case insensitive search, as it |
|
1638 | - * shows the exact matched case of needle. |
|
1639 | - * |
|
1640 | - * @param string $needle |
|
1641 | - * @param string $haystack |
|
1642 | - * @param bool $caseInsensitive |
|
1643 | - * @return ConvertHelper_StringMatch[] |
|
1644 | - */ |
|
1634 | + /** |
|
1635 | + * Searches for needle in the specified string, and returns a list |
|
1636 | + * of all occurrences, including the matched string. The matched |
|
1637 | + * string is useful when doing a case insensitive search, as it |
|
1638 | + * shows the exact matched case of needle. |
|
1639 | + * |
|
1640 | + * @param string $needle |
|
1641 | + * @param string $haystack |
|
1642 | + * @param bool $caseInsensitive |
|
1643 | + * @return ConvertHelper_StringMatch[] |
|
1644 | + */ |
|
1645 | 1645 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
1646 | 1646 | { |
1647 | 1647 | if($needle === '') { |
@@ -1667,14 +1667,14 @@ discard block |
||
1667 | 1667 | return $positions; |
1668 | 1668 | } |
1669 | 1669 | |
1670 | - /** |
|
1671 | - * Like explode, but trims all entries, and removes |
|
1672 | - * empty entries from the resulting array. |
|
1673 | - * |
|
1674 | - * @param string $delimiter |
|
1675 | - * @param string $string |
|
1676 | - * @return string[] |
|
1677 | - */ |
|
1670 | + /** |
|
1671 | + * Like explode, but trims all entries, and removes |
|
1672 | + * empty entries from the resulting array. |
|
1673 | + * |
|
1674 | + * @param string $delimiter |
|
1675 | + * @param string $string |
|
1676 | + * @return string[] |
|
1677 | + */ |
|
1678 | 1678 | public static function explodeTrim(string $delimiter, string $string) : array |
1679 | 1679 | { |
1680 | 1680 | if(empty($string) || empty($delimiter)) { |
@@ -1696,12 +1696,12 @@ discard block |
||
1696 | 1696 | |
1697 | 1697 | protected static $eolChars; |
1698 | 1698 | |
1699 | - /** |
|
1700 | - * Detects the most used end-of-line character in the subject string. |
|
1701 | - * |
|
1702 | - * @param string $str The string to check. |
|
1703 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
1704 | - */ |
|
1699 | + /** |
|
1700 | + * Detects the most used end-of-line character in the subject string. |
|
1701 | + * |
|
1702 | + * @param string $str The string to check. |
|
1703 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
1704 | + */ |
|
1705 | 1705 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
1706 | 1706 | { |
1707 | 1707 | if(empty($subjectString)) { |
@@ -1710,27 +1710,27 @@ discard block |
||
1710 | 1710 | |
1711 | 1711 | if(!isset(self::$eolChars)) |
1712 | 1712 | { |
1713 | - self::$eolChars = array( |
|
1714 | - array( |
|
1715 | - 'char' => chr(hexdec('0d')).chr(hexdec('0a')), |
|
1716 | - 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
1717 | - 'description' => t('Carriage return followed by a line feed'), |
|
1718 | - ), |
|
1719 | - array( |
|
1720 | - 'char' => chr(hexdec('0a')).chr(hexdec('0d')), |
|
1721 | - 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
1722 | - 'description' => t('Line feed followed by a carriage return'), |
|
1723 | - ), |
|
1724 | - array( |
|
1725 | - 'char' => chr(hexdec('0a')), |
|
1726 | - 'type' => ConvertHelper_EOL::TYPE_LF, |
|
1727 | - 'description' => t('Line feed'), |
|
1728 | - ), |
|
1729 | - array( |
|
1730 | - 'char' => chr(hexdec('0d')), |
|
1731 | - 'type' => ConvertHelper_EOL::TYPE_CR, |
|
1732 | - 'description' => t('Carriage Return'), |
|
1733 | - ), |
|
1713 | + self::$eolChars = array( |
|
1714 | + array( |
|
1715 | + 'char' => chr(hexdec('0d')).chr(hexdec('0a')), |
|
1716 | + 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
1717 | + 'description' => t('Carriage return followed by a line feed'), |
|
1718 | + ), |
|
1719 | + array( |
|
1720 | + 'char' => chr(hexdec('0a')).chr(hexdec('0d')), |
|
1721 | + 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
1722 | + 'description' => t('Line feed followed by a carriage return'), |
|
1723 | + ), |
|
1724 | + array( |
|
1725 | + 'char' => chr(hexdec('0a')), |
|
1726 | + 'type' => ConvertHelper_EOL::TYPE_LF, |
|
1727 | + 'description' => t('Line feed'), |
|
1728 | + ), |
|
1729 | + array( |
|
1730 | + 'char' => chr(hexdec('0d')), |
|
1731 | + 'type' => ConvertHelper_EOL::TYPE_CR, |
|
1732 | + 'description' => t('Carriage Return'), |
|
1733 | + ), |
|
1734 | 1734 | ); |
1735 | 1735 | } |
1736 | 1736 | |
@@ -1758,13 +1758,13 @@ discard block |
||
1758 | 1758 | ); |
1759 | 1759 | } |
1760 | 1760 | |
1761 | - /** |
|
1762 | - * Removes the specified keys from the target array, |
|
1763 | - * if they exist. |
|
1764 | - * |
|
1765 | - * @param array $array |
|
1766 | - * @param array $keys |
|
1767 | - */ |
|
1761 | + /** |
|
1762 | + * Removes the specified keys from the target array, |
|
1763 | + * if they exist. |
|
1764 | + * |
|
1765 | + * @param array $array |
|
1766 | + * @param array $keys |
|
1767 | + */ |
|
1768 | 1768 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
1769 | 1769 | { |
1770 | 1770 | foreach($keys as $key) |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $amount = substr_count($line, "\t") - $min; |
69 | 69 | $line = trim($line); |
70 | 70 | if ($amount >= 1) { |
71 | - $line = str_repeat("\t", $amount) . $line; |
|
71 | + $line = str_repeat("\t", $amount).$line; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | $converted[] = $line; |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | |
141 | 141 | // specifically handle zero |
142 | 142 | if ($seconds <= 0) { |
143 | - return '0 ' . t('seconds'); |
|
143 | + return '0 '.t('seconds'); |
|
144 | 144 | } |
145 | 145 | |
146 | - if($seconds < 1) { |
|
146 | + if ($seconds < 1) { |
|
147 | 147 | return t('less than a second'); |
148 | 148 | } |
149 | 149 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | foreach ($units as $def) { |
152 | 152 | $quot = intval($seconds / $def['value']); |
153 | 153 | if ($quot) { |
154 | - $item = $quot . ' '; |
|
154 | + $item = $quot.' '; |
|
155 | 155 | if (abs($quot) > 1) { |
156 | 156 | $item .= $def['plural']; |
157 | 157 | } else { |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | return $last; |
169 | 169 | } |
170 | 170 | |
171 | - return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
|
171 | + return implode(', ', $tokens).' '.t('and').' '.$last; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public static function duration2string($datefrom, $dateto = -1) |
187 | 187 | { |
188 | - if($datefrom instanceof \DateTime) { |
|
188 | + if ($datefrom instanceof \DateTime) { |
|
189 | 189 | $datefrom = ConvertHelper::date2timestamp($datefrom); |
190 | 190 | } |
191 | 191 | |
192 | - if($dateto instanceof \DateTime) { |
|
192 | + if ($dateto instanceof \DateTime) { |
|
193 | 193 | $dateto = ConvertHelper::date2timestamp($dateto); |
194 | 194 | } |
195 | 195 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $difference = $dateto - $datefrom; |
210 | 210 | |
211 | 211 | $future = false; |
212 | - if($difference < 0) { |
|
212 | + if ($difference < 0) { |
|
213 | 213 | $difference = $difference * -1; |
214 | 214 | $future = true; |
215 | 215 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | $datediff--; |
288 | 288 | } |
289 | 289 | |
290 | - if($future) { |
|
290 | + if ($future) { |
|
291 | 291 | $res = ($datediff == 1) ? t('In one month', $datediff) : t('In %1s months', $datediff); |
292 | 292 | } else { |
293 | 293 | $res = ($datediff == 1) ? t('One month ago', $datediff) : t('%1s months ago', $datediff); |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | |
297 | 297 | case "y": |
298 | 298 | $datediff = floor($difference / 60 / 60 / 24 / 365); |
299 | - if($future) { |
|
299 | + if ($future) { |
|
300 | 300 | $res = ($datediff == 1) ? t('In one year', $datediff) : t('In %1s years', $datediff); |
301 | 301 | } else { |
302 | 302 | $res = ($datediff == 1) ? t('One year ago', $datediff) : t('%1s years ago', $datediff); |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | |
306 | 306 | case "d": |
307 | 307 | $datediff = floor($difference / 60 / 60 / 24); |
308 | - if($future) { |
|
308 | + if ($future) { |
|
309 | 309 | $res = ($datediff == 1) ? t('In one day', $datediff) : t('In %1s days', $datediff); |
310 | 310 | } else { |
311 | 311 | $res = ($datediff == 1) ? t('One day ago', $datediff) : t('%1s days ago', $datediff); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | |
315 | 315 | case "ww": |
316 | 316 | $datediff = floor($difference / 60 / 60 / 24 / 7); |
317 | - if($future) { |
|
317 | + if ($future) { |
|
318 | 318 | $res = ($datediff == 1) ? t('In one week', $datediff) : t('In %1s weeks', $datediff); |
319 | 319 | } else { |
320 | 320 | $res = ($datediff == 1) ? t('One week ago', $datediff) : t('%1s weeks ago', $datediff); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | |
324 | 324 | case "h": |
325 | 325 | $datediff = floor($difference / 60 / 60); |
326 | - if($future) { |
|
326 | + if ($future) { |
|
327 | 327 | $res = ($datediff == 1) ? t('In one hour', $datediff) : t('In %1s hours', $datediff); |
328 | 328 | } else { |
329 | 329 | $res = ($datediff == 1) ? t('One hour ago', $datediff) : t('%1s hours ago', $datediff); |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | |
333 | 333 | case "n": |
334 | 334 | $datediff = floor($difference / 60); |
335 | - if($future) { |
|
335 | + if ($future) { |
|
336 | 336 | $res = ($datediff == 1) ? t('In one minute', $datediff) : t('In %1s minutes', $datediff); |
337 | 337 | } else { |
338 | 338 | $res = ($datediff == 1) ? t('One minute ago', $datediff) : t('%1s minutes ago', $datediff); |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | |
342 | 342 | case "s": |
343 | 343 | $datediff = $difference; |
344 | - if($future) { |
|
344 | + if ($future) { |
|
345 | 345 | $res = ($datediff == 1) ? t('In one second', $datediff) : t('In %1s seconds', $datediff); |
346 | 346 | } else { |
347 | 347 | $res = ($datediff == 1) ? t('One second ago', $datediff) : t('%1s seconds ago', $datediff); |
@@ -364,9 +364,9 @@ discard block |
||
364 | 364 | return $geshi->parse_code(); |
365 | 365 | } |
366 | 366 | |
367 | - public static function highlight_xml($xml, $formatSource=false) |
|
367 | + public static function highlight_xml($xml, $formatSource = false) |
|
368 | 368 | { |
369 | - if($formatSource) |
|
369 | + if ($formatSource) |
|
370 | 370 | { |
371 | 371 | $dom = new \DOMDocument(); |
372 | 372 | $dom->loadXML($xml); |
@@ -404,22 +404,22 @@ discard block |
||
404 | 404 | $terabyte = $gigabyte * 1024; |
405 | 405 | |
406 | 406 | if (($bytes >= 0) && ($bytes < $kilobyte)) { |
407 | - return $bytes . ' ' . t('B'); |
|
407 | + return $bytes.' '.t('B'); |
|
408 | 408 | |
409 | 409 | } elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) { |
410 | - return round($bytes / $kilobyte, $precision) . ' ' . t('Kb'); |
|
410 | + return round($bytes / $kilobyte, $precision).' '.t('Kb'); |
|
411 | 411 | |
412 | 412 | } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) { |
413 | - return round($bytes / $megabyte, $precision) . ' ' . t('Mb'); |
|
413 | + return round($bytes / $megabyte, $precision).' '.t('Mb'); |
|
414 | 414 | |
415 | 415 | } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) { |
416 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Gb'); |
|
416 | + return round($bytes / $gigabyte, $precision).' '.t('Gb'); |
|
417 | 417 | |
418 | 418 | } elseif ($bytes >= $terabyte) { |
419 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Tb'); |
|
419 | + return round($bytes / $gigabyte, $precision).' '.t('Tb'); |
|
420 | 420 | } |
421 | 421 | |
422 | - return $bytes . ' ' . t('B'); |
|
422 | + return $bytes.' '.t('B'); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -439,34 +439,34 @@ discard block |
||
439 | 439 | return $text; |
440 | 440 | } |
441 | 441 | |
442 | - $text = trim(mb_substr($text, 0, $targetLength)) . $append; |
|
442 | + $text = trim(mb_substr($text, 0, $targetLength)).$append; |
|
443 | 443 | |
444 | 444 | return $text; |
445 | 445 | } |
446 | 446 | |
447 | - public static function var_dump($var, $html=true) |
|
447 | + public static function var_dump($var, $html = true) |
|
448 | 448 | { |
449 | 449 | $info = parseVariable($var); |
450 | 450 | |
451 | - if($html) { |
|
451 | + if ($html) { |
|
452 | 452 | return $info->toHTML(); |
453 | 453 | } |
454 | 454 | |
455 | 455 | return $info->toString(); |
456 | 456 | } |
457 | 457 | |
458 | - public static function print_r($var, $return=false, $html=true) |
|
458 | + public static function print_r($var, $return = false, $html = true) |
|
459 | 459 | { |
460 | 460 | $result = self::var_dump($var, $html); |
461 | 461 | |
462 | - if($html) { |
|
462 | + if ($html) { |
|
463 | 463 | $result = |
464 | 464 | '<pre style="background:#fff;color:#333;padding:16px;border:solid 1px #bbb;border-radius:4px">'. |
465 | 465 | $result. |
466 | 466 | '</pre>'; |
467 | 467 | } |
468 | 468 | |
469 | - if($return) { |
|
469 | + if ($return) { |
|
470 | 470 | return $result; |
471 | 471 | } |
472 | 472 | |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | |
487 | 487 | public static function string2bool($string) |
488 | 488 | { |
489 | - if($string === '' || $string === null) { |
|
489 | + if ($string === '' || $string === null) { |
|
490 | 490 | return false; |
491 | 491 | } |
492 | 492 | |
@@ -541,10 +541,10 @@ discard block |
||
541 | 541 | public static function date2listLabel(\DateTime $date, $includeTime = false, $shortMonth = false) |
542 | 542 | { |
543 | 543 | $today = new \DateTime(); |
544 | - if($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
544 | + if ($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
545 | 545 | $label = t('Today'); |
546 | 546 | } else { |
547 | - $label = $date->format('d') . '. ' . self::month2string($date->format('m'), $shortMonth) . ' '; |
|
547 | + $label = $date->format('d').'. '.self::month2string($date->format('m'), $shortMonth).' '; |
|
548 | 548 | if ($date->format('Y') != date('Y')) { |
549 | 549 | $label .= $date->format('Y'); |
550 | 550 | } |
@@ -635,28 +635,28 @@ discard block |
||
635 | 635 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
636 | 636 | |
637 | 637 | $stack = array(); |
638 | - foreach(self::$controlChars as $char) |
|
638 | + foreach (self::$controlChars as $char) |
|
639 | 639 | { |
640 | 640 | $tokens = explode('-', $char); |
641 | 641 | $start = $tokens[0]; |
642 | 642 | $end = $tokens[1]; |
643 | 643 | $prefix = substr($start, 0, 3); |
644 | 644 | $range = array(); |
645 | - foreach($hexAlphabet as $number) { |
|
645 | + foreach ($hexAlphabet as $number) { |
|
646 | 646 | $range[] = $prefix.$number; |
647 | 647 | } |
648 | 648 | |
649 | 649 | $use = false; |
650 | - foreach($range as $number) { |
|
651 | - if($number == $start) { |
|
650 | + foreach ($range as $number) { |
|
651 | + if ($number == $start) { |
|
652 | 652 | $use = true; |
653 | 653 | } |
654 | 654 | |
655 | - if($use) { |
|
655 | + if ($use) { |
|
656 | 656 | $stack[] = $number; |
657 | 657 | } |
658 | 658 | |
659 | - if($number == $end) { |
|
659 | + if ($number == $end) { |
|
660 | 660 | break; |
661 | 661 | } |
662 | 662 | } |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | $chars = self::getControlCharactersAsHex(); |
678 | 678 | |
679 | 679 | $result = array(); |
680 | - foreach($chars as $char) { |
|
680 | + foreach ($chars as $char) { |
|
681 | 681 | $result[] = hex2bin($char); |
682 | 682 | } |
683 | 683 | |
@@ -695,14 +695,14 @@ discard block |
||
695 | 695 | $chars = self::getControlCharactersAsHex(); |
696 | 696 | |
697 | 697 | $result = array(); |
698 | - foreach($chars as $char) { |
|
698 | + foreach ($chars as $char) { |
|
699 | 699 | $result[] = '\u'.strtolower($char); |
700 | 700 | } |
701 | 701 | |
702 | 702 | return $result; |
703 | 703 | } |
704 | 704 | |
705 | - protected static $controlChars = array( |
|
705 | + protected static $controlChars = array( |
|
706 | 706 | '0000-0008', // control chars |
707 | 707 | '000E-000F', // control chars |
708 | 708 | '0010-001F', // control chars |
@@ -724,11 +724,11 @@ discard block |
||
724 | 724 | */ |
725 | 725 | public static function stripControlCharacters($string) |
726 | 726 | { |
727 | - if(empty($string)) { |
|
727 | + if (empty($string)) { |
|
728 | 728 | return $string; |
729 | 729 | } |
730 | 730 | |
731 | - if(!is_string($string)) { |
|
731 | + if (!is_string($string)) { |
|
732 | 732 | throw new ConvertHelper_Exception( |
733 | 733 | 'Subject is not a string', |
734 | 734 | sprintf( |
@@ -740,14 +740,14 @@ discard block |
||
740 | 740 | } |
741 | 741 | |
742 | 742 | // create the regex from the unicode characters list |
743 | - if(!isset(self::$controlCharsRegex)) |
|
743 | + if (!isset(self::$controlCharsRegex)) |
|
744 | 744 | { |
745 | 745 | $chars = self::getControlCharactersAsHex(); |
746 | 746 | |
747 | 747 | // we use the notation \x{0000} to specify the unicode character key |
748 | 748 | // in the regular expression. |
749 | 749 | $stack = array(); |
750 | - foreach($chars as $char) { |
|
750 | + foreach ($chars as $char) { |
|
751 | 751 | $stack[] = '\x{'.$char.'}'; |
752 | 752 | } |
753 | 753 | |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | $ordInt = ord($octet); |
782 | 782 | // Convert from int (base 10) to hex (base 16), for PHP \x syntax |
783 | 783 | $ordHex = base_convert($ordInt, 10, 16); |
784 | - $output .= '\x' . $ordHex; |
|
784 | + $output .= '\x'.$ordHex; |
|
785 | 785 | } |
786 | 786 | return $output; |
787 | 787 | } |
@@ -813,19 +813,19 @@ discard block |
||
813 | 813 | |
814 | 814 | protected static function convertScalarForComparison($scalar) |
815 | 815 | { |
816 | - if($scalar === '' || is_null($scalar)) { |
|
816 | + if ($scalar === '' || is_null($scalar)) { |
|
817 | 817 | return null; |
818 | 818 | } |
819 | 819 | |
820 | - if(is_bool($scalar)) { |
|
820 | + if (is_bool($scalar)) { |
|
821 | 821 | return self::bool2string($scalar); |
822 | 822 | } |
823 | 823 | |
824 | - if(is_array($scalar)) { |
|
824 | + if (is_array($scalar)) { |
|
825 | 825 | $scalar = md5(serialize($scalar)); |
826 | 826 | } |
827 | 827 | |
828 | - if($scalar !== null && !is_scalar($scalar)) { |
|
828 | + if ($scalar !== null && !is_scalar($scalar)) { |
|
829 | 829 | throw new ConvertHelper_Exception( |
830 | 830 | 'Not a scalar value in comparison', |
831 | 831 | null, |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | public static function bool2string($boolean, $yesno = false) |
875 | 875 | { |
876 | 876 | // allow 'yes', 'true', 'no', 'false' string notations as well |
877 | - if(!is_bool($boolean)) { |
|
877 | + if (!is_bool($boolean)) { |
|
878 | 878 | $boolean = self::string2bool($boolean); |
879 | 879 | } |
880 | 880 | |
@@ -915,15 +915,15 @@ discard block |
||
915 | 915 | public static function array2attributeString($array) |
916 | 916 | { |
917 | 917 | $tokens = array(); |
918 | - foreach($array as $attr => $value) { |
|
919 | - if($value == '' || $value == null) { |
|
918 | + foreach ($array as $attr => $value) { |
|
919 | + if ($value == '' || $value == null) { |
|
920 | 920 | continue; |
921 | 921 | } |
922 | 922 | |
923 | 923 | $tokens[] = $attr.'="'.$value.'"'; |
924 | 924 | } |
925 | 925 | |
926 | - if(empty($tokens)) { |
|
926 | + if (empty($tokens)) { |
|
927 | 927 | return ''; |
928 | 928 | } |
929 | 929 | |
@@ -938,10 +938,10 @@ discard block |
||
938 | 938 | * @param string $string |
939 | 939 | * @return string |
940 | 940 | */ |
941 | - public static function string2attributeJS($string, $quoted=true) |
|
941 | + public static function string2attributeJS($string, $quoted = true) |
|
942 | 942 | { |
943 | 943 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
944 | - if($quoted) { |
|
944 | + if ($quoted) { |
|
945 | 945 | $converted = "'".$converted."'"; |
946 | 946 | } |
947 | 947 | |
@@ -959,11 +959,11 @@ discard block |
||
959 | 959 | */ |
960 | 960 | public static function isBoolean($value) |
961 | 961 | { |
962 | - if(is_bool($value)) { |
|
962 | + if (is_bool($value)) { |
|
963 | 963 | return true; |
964 | 964 | } |
965 | 965 | |
966 | - if(!is_scalar($value)) { |
|
966 | + if (!is_scalar($value)) { |
|
967 | 967 | return false; |
968 | 968 | } |
969 | 969 | |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | public static function array2styleString($subject) |
980 | 980 | { |
981 | 981 | $tokens = array(); |
982 | - foreach($subject as $name => $value) { |
|
982 | + foreach ($subject as $name => $value) { |
|
983 | 983 | $tokens[] = $name.':'.$value; |
984 | 984 | } |
985 | 985 | |
@@ -1044,7 +1044,7 @@ discard block |
||
1044 | 1044 | * @param string $regex |
1045 | 1045 | * @return array |
1046 | 1046 | */ |
1047 | - public static function regex2js($regex, $return=self::JS_REGEX_OBJECT) |
|
1047 | + public static function regex2js($regex, $return = self::JS_REGEX_OBJECT) |
|
1048 | 1048 | { |
1049 | 1049 | $regex = trim($regex); |
1050 | 1050 | $separator = substr($regex, 0, 1); |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | array_shift($parts); |
1053 | 1053 | |
1054 | 1054 | $modifiers = array_pop($parts); |
1055 | - if($modifiers == $separator) { |
|
1055 | + if ($modifiers == $separator) { |
|
1056 | 1056 | $modifiers = ''; |
1057 | 1057 | } |
1058 | 1058 | |
@@ -1068,14 +1068,14 @@ discard block |
||
1068 | 1068 | // convert the anchors that are not supported in js regexes |
1069 | 1069 | $format = str_replace(array('\\A', '\\Z', '\\z'), array('^', '$', ''), $format); |
1070 | 1070 | |
1071 | - if($return==self::JS_REGEX_JSON) { |
|
1071 | + if ($return == self::JS_REGEX_JSON) { |
|
1072 | 1072 | return json_encode(array( |
1073 | 1073 | 'format' => $format, |
1074 | 1074 | 'modifiers' => $modifiers |
1075 | 1075 | )); |
1076 | 1076 | } |
1077 | 1077 | |
1078 | - if(!empty($modifiers)) { |
|
1078 | + if (!empty($modifiers)) { |
|
1079 | 1079 | return sprintf( |
1080 | 1080 | 'new RegExp(%s, %s)', |
1081 | 1081 | json_encode($format), |
@@ -1098,10 +1098,10 @@ discard block |
||
1098 | 1098 | public static function stripUTFBom($string) |
1099 | 1099 | { |
1100 | 1100 | $boms = FileHelper::getUTFBOMs(); |
1101 | - foreach($boms as $bomChars) { |
|
1101 | + foreach ($boms as $bomChars) { |
|
1102 | 1102 | $length = mb_strlen($bomChars); |
1103 | 1103 | $text = mb_substr($string, 0, $length); |
1104 | - if($text==$bomChars) { |
|
1104 | + if ($text == $bomChars) { |
|
1105 | 1105 | return mb_substr($string, $length); |
1106 | 1106 | } |
1107 | 1107 | } |
@@ -1118,7 +1118,7 @@ discard block |
||
1118 | 1118 | */ |
1119 | 1119 | public static function string2utf8($string) |
1120 | 1120 | { |
1121 | - if(!self::isStringASCII($string)) { |
|
1121 | + if (!self::isStringASCII($string)) { |
|
1122 | 1122 | return \ForceUTF8\Encoding::toUTF8($string); |
1123 | 1123 | } |
1124 | 1124 | |
@@ -1136,11 +1136,11 @@ discard block |
||
1136 | 1136 | */ |
1137 | 1137 | public static function isStringASCII($string) |
1138 | 1138 | { |
1139 | - if($string === '' || $string === NULL) { |
|
1139 | + if ($string === '' || $string === NULL) { |
|
1140 | 1140 | return true; |
1141 | 1141 | } |
1142 | 1142 | |
1143 | - if(!is_string($string)) { |
|
1143 | + if (!is_string($string)) { |
|
1144 | 1144 | return false; |
1145 | 1145 | } |
1146 | 1146 | |
@@ -1174,7 +1174,7 @@ discard block |
||
1174 | 1174 | * @param array $options |
1175 | 1175 | * @return float |
1176 | 1176 | */ |
1177 | - public static function matchString($source, $target, $options=array()) |
|
1177 | + public static function matchString($source, $target, $options = array()) |
|
1178 | 1178 | { |
1179 | 1179 | $defaults = array( |
1180 | 1180 | 'maxLevenshtein' => 10, |
@@ -1184,12 +1184,12 @@ discard block |
||
1184 | 1184 | $options = array_merge($defaults, $options); |
1185 | 1185 | |
1186 | 1186 | // avoid doing this via levenshtein |
1187 | - if($source == $target) { |
|
1187 | + if ($source == $target) { |
|
1188 | 1188 | return 100; |
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | $diff = levenshtein($source, $target); |
1192 | - if($diff > $options['maxLevenshtein']) { |
|
1192 | + if ($diff > $options['maxLevenshtein']) { |
|
1193 | 1193 | return 0; |
1194 | 1194 | } |
1195 | 1195 | |
@@ -1203,8 +1203,8 @@ discard block |
||
1203 | 1203 | |
1204 | 1204 | $offset = 0; |
1205 | 1205 | $keep = array(); |
1206 | - foreach($tokens as $token) { |
|
1207 | - if($interval->$token > 0) { |
|
1206 | + foreach ($tokens as $token) { |
|
1207 | + if ($interval->$token > 0) { |
|
1208 | 1208 | $keep = array_slice($tokens, $offset); |
1209 | 1209 | break; |
1210 | 1210 | } |
@@ -1213,16 +1213,16 @@ discard block |
||
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | $parts = array(); |
1216 | - foreach($keep as $token) |
|
1216 | + foreach ($keep as $token) |
|
1217 | 1217 | { |
1218 | 1218 | $value = $interval->$token; |
1219 | 1219 | $label = ''; |
1220 | 1220 | |
1221 | 1221 | $suffix = 'p'; |
1222 | - if($value == 1) { $suffix = 's'; } |
|
1222 | + if ($value == 1) { $suffix = 's'; } |
|
1223 | 1223 | $token .= $suffix; |
1224 | 1224 | |
1225 | - switch($token) { |
|
1225 | + switch ($token) { |
|
1226 | 1226 | case 'ys': $label = t('1 year'); break; |
1227 | 1227 | case 'yp': $label = t('%1$s years', $value); break; |
1228 | 1228 | case 'ms': $label = t('1 month'); break; |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | $parts[] = $label; |
1241 | 1241 | } |
1242 | 1242 | |
1243 | - if(count($parts) == 1) { |
|
1243 | + if (count($parts) == 1) { |
|
1244 | 1244 | return $parts[0]; |
1245 | 1245 | } |
1246 | 1246 | |
@@ -1265,23 +1265,23 @@ discard block |
||
1265 | 1265 | * @param string $unit |
1266 | 1266 | * @return integer |
1267 | 1267 | */ |
1268 | - public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) |
|
1268 | + public static function interval2total(\DateInterval $interval, $unit = self::INTERVAL_SECONDS) |
|
1269 | 1269 | { |
1270 | 1270 | $total = $interval->format('%a'); |
1271 | 1271 | if ($unit == self::INTERVAL_DAYS) { |
1272 | 1272 | return $total; |
1273 | 1273 | } |
1274 | 1274 | |
1275 | - $total = ($total * 24) + ($interval->h ); |
|
1275 | + $total = ($total * 24) + ($interval->h); |
|
1276 | 1276 | if ($unit == self::INTERVAL_HOURS) { |
1277 | 1277 | return $total; |
1278 | 1278 | } |
1279 | 1279 | |
1280 | - $total = ($total * 60) + ($interval->i ); |
|
1280 | + $total = ($total * 60) + ($interval->i); |
|
1281 | 1281 | if ($unit == self::INTERVAL_MINUTES) |
1282 | 1282 | return $total; |
1283 | 1283 | |
1284 | - $total = ($total * 60) + ($interval->s ); |
|
1284 | + $total = ($total * 60) + ($interval->s); |
|
1285 | 1285 | if ($unit == self::INTERVAL_SECONDS) |
1286 | 1286 | return $total; |
1287 | 1287 | |
@@ -1309,13 +1309,13 @@ discard block |
||
1309 | 1309 | * @param string $short |
1310 | 1310 | * @return string|NULL |
1311 | 1311 | */ |
1312 | - public static function date2dayName(\DateTime $date, $short=false) |
|
1312 | + public static function date2dayName(\DateTime $date, $short = false) |
|
1313 | 1313 | { |
1314 | 1314 | $day = $date->format('l'); |
1315 | 1315 | $invariant = self::getDayNamesInvariant(); |
1316 | 1316 | |
1317 | 1317 | $idx = array_search($day, $invariant); |
1318 | - if($idx !== false) { |
|
1318 | + if ($idx !== false) { |
|
1319 | 1319 | $localized = self::getDayNames($short); |
1320 | 1320 | return $localized[$idx]; |
1321 | 1321 | } |
@@ -1338,10 +1338,10 @@ discard block |
||
1338 | 1338 | * @param string $short |
1339 | 1339 | * @return string[] |
1340 | 1340 | */ |
1341 | - public static function getDayNames($short=false) |
|
1341 | + public static function getDayNames($short = false) |
|
1342 | 1342 | { |
1343 | - if($short) { |
|
1344 | - if(!isset(self::$daysShort)) { |
|
1343 | + if ($short) { |
|
1344 | + if (!isset(self::$daysShort)) { |
|
1345 | 1345 | self::$daysShort = array( |
1346 | 1346 | t('Mon'), |
1347 | 1347 | t('Tue'), |
@@ -1356,7 +1356,7 @@ discard block |
||
1356 | 1356 | return self::$daysShort; |
1357 | 1357 | } |
1358 | 1358 | |
1359 | - if(!isset(self::$days)) { |
|
1359 | + if (!isset(self::$days)) { |
|
1360 | 1360 | self::$days = array( |
1361 | 1361 | t('Monday'), |
1362 | 1362 | t('Tuesday'), |
@@ -1381,17 +1381,17 @@ discard block |
||
1381 | 1381 | */ |
1382 | 1382 | public static function implodeWithAnd(array $list, $sep = ', ', $conjunction = null) |
1383 | 1383 | { |
1384 | - if(empty($list)) { |
|
1384 | + if (empty($list)) { |
|
1385 | 1385 | return ''; |
1386 | 1386 | } |
1387 | 1387 | |
1388 | - if(empty($conjunction)) { |
|
1388 | + if (empty($conjunction)) { |
|
1389 | 1389 | $conjunction = t('and'); |
1390 | 1390 | } |
1391 | 1391 | |
1392 | 1392 | $last = array_pop($list); |
1393 | - if($list) { |
|
1394 | - return implode($sep, $list) . $conjunction . ' ' . $last; |
|
1393 | + if ($list) { |
|
1394 | + return implode($sep, $list).$conjunction.' '.$last; |
|
1395 | 1395 | } |
1396 | 1396 | |
1397 | 1397 | return $last; |
@@ -1418,12 +1418,12 @@ discard block |
||
1418 | 1418 | */ |
1419 | 1419 | public static function isStringHTML($string) |
1420 | 1420 | { |
1421 | - if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
1421 | + if (preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
1422 | 1422 | return true; |
1423 | 1423 | } |
1424 | 1424 | |
1425 | 1425 | $decoded = html_entity_decode($string); |
1426 | - if($decoded !== $string) { |
|
1426 | + if ($decoded !== $string) { |
|
1427 | 1427 | return true; |
1428 | 1428 | } |
1429 | 1429 | |
@@ -1560,7 +1560,7 @@ discard block |
||
1560 | 1560 | // extract parameter names from the query string |
1561 | 1561 | $result = array(); |
1562 | 1562 | preg_match_all('/&?([^&]+)=.*/sixU', $queryString, $result, PREG_PATTERN_ORDER); |
1563 | - if(isset($result[1])) { |
|
1563 | + if (isset($result[1])) { |
|
1564 | 1564 | $paramNames = $result[1]; |
1565 | 1565 | } |
1566 | 1566 | |
@@ -1581,12 +1581,12 @@ discard block |
||
1581 | 1581 | // possible naming conflicts like having both parameters "foo.bar" |
1582 | 1582 | // and "foo_bar" in the query string: since "foo.bar" would be converted |
1583 | 1583 | // to "foo_bar", one of the two would be replaced. |
1584 | - if($fixRequired) |
|
1584 | + if ($fixRequired) |
|
1585 | 1585 | { |
1586 | 1586 | $counter = 1; |
1587 | 1587 | $table = array(); |
1588 | 1588 | $placeholders = array(); |
1589 | - foreach($paramNames as $paramName) |
|
1589 | + foreach ($paramNames as $paramName) |
|
1590 | 1590 | { |
1591 | 1591 | // create a unique placeholder name |
1592 | 1592 | $placeholder = '__PLACEHOLDER'.$counter.'__'; |
@@ -1616,13 +1616,13 @@ discard block |
||
1616 | 1616 | parse_str($queryString, $parsed); |
1617 | 1617 | |
1618 | 1618 | // do any of the parameter names need to be fixed? |
1619 | - if(!$fixRequired) { |
|
1619 | + if (!$fixRequired) { |
|
1620 | 1620 | return $parsed; |
1621 | 1621 | } |
1622 | 1622 | |
1623 | 1623 | $keep = array(); |
1624 | 1624 | |
1625 | - foreach($parsed as $name => $value) |
|
1625 | + foreach ($parsed as $name => $value) |
|
1626 | 1626 | { |
1627 | 1627 | $keep[$table[$name]] = $value; |
1628 | 1628 | } |
@@ -1642,14 +1642,14 @@ discard block |
||
1642 | 1642 | * @param bool $caseInsensitive |
1643 | 1643 | * @return ConvertHelper_StringMatch[] |
1644 | 1644 | */ |
1645 | - public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
|
1645 | + public static function findString(string $needle, string $haystack, bool $caseInsensitive = false) |
|
1646 | 1646 | { |
1647 | - if($needle === '') { |
|
1647 | + if ($needle === '') { |
|
1648 | 1648 | return array(); |
1649 | 1649 | } |
1650 | 1650 | |
1651 | 1651 | $function = 'mb_strpos'; |
1652 | - if($caseInsensitive) { |
|
1652 | + if ($caseInsensitive) { |
|
1653 | 1653 | $function = 'mb_stripos'; |
1654 | 1654 | } |
1655 | 1655 | |
@@ -1657,7 +1657,7 @@ discard block |
||
1657 | 1657 | $positions = array(); |
1658 | 1658 | $length = mb_strlen($needle); |
1659 | 1659 | |
1660 | - while( ($pos = $function($haystack, $needle, $pos)) !== false) |
|
1660 | + while (($pos = $function($haystack, $needle, $pos)) !== false) |
|
1661 | 1661 | { |
1662 | 1662 | $match = mb_substr($haystack, $pos, $length); |
1663 | 1663 | $positions[] = new ConvertHelper_StringMatch($pos, $match); |
@@ -1677,7 +1677,7 @@ discard block |
||
1677 | 1677 | */ |
1678 | 1678 | public static function explodeTrim(string $delimiter, string $string) : array |
1679 | 1679 | { |
1680 | - if(empty($string) || empty($delimiter)) { |
|
1680 | + if (empty($string) || empty($delimiter)) { |
|
1681 | 1681 | return array(); |
1682 | 1682 | } |
1683 | 1683 | |
@@ -1685,8 +1685,8 @@ discard block |
||
1685 | 1685 | $tokens = array_map('trim', $tokens); |
1686 | 1686 | |
1687 | 1687 | $keep = array(); |
1688 | - foreach($tokens as $token) { |
|
1689 | - if($token !== '') { |
|
1688 | + foreach ($tokens as $token) { |
|
1689 | + if ($token !== '') { |
|
1690 | 1690 | $keep[] = $token; |
1691 | 1691 | } |
1692 | 1692 | } |
@@ -1704,11 +1704,11 @@ discard block |
||
1704 | 1704 | */ |
1705 | 1705 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
1706 | 1706 | { |
1707 | - if(empty($subjectString)) { |
|
1707 | + if (empty($subjectString)) { |
|
1708 | 1708 | return null; |
1709 | 1709 | } |
1710 | 1710 | |
1711 | - if(!isset(self::$eolChars)) |
|
1711 | + if (!isset(self::$eolChars)) |
|
1712 | 1712 | { |
1713 | 1713 | self::$eolChars = array( |
1714 | 1714 | array( |
@@ -1736,18 +1736,18 @@ discard block |
||
1736 | 1736 | |
1737 | 1737 | $max = 0; |
1738 | 1738 | $results = array(); |
1739 | - foreach(self::$eolChars as $def) |
|
1739 | + foreach (self::$eolChars as $def) |
|
1740 | 1740 | { |
1741 | 1741 | $amount = substr_count($subjectString, $def['char']); |
1742 | 1742 | |
1743 | - if($amount > $max) |
|
1743 | + if ($amount > $max) |
|
1744 | 1744 | { |
1745 | 1745 | $max = $amount; |
1746 | 1746 | $results[] = $def; |
1747 | 1747 | } |
1748 | 1748 | } |
1749 | 1749 | |
1750 | - if(empty($results)) { |
|
1750 | + if (empty($results)) { |
|
1751 | 1751 | return null; |
1752 | 1752 | } |
1753 | 1753 | |
@@ -1767,9 +1767,9 @@ discard block |
||
1767 | 1767 | */ |
1768 | 1768 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
1769 | 1769 | { |
1770 | - foreach($keys as $key) |
|
1770 | + foreach ($keys as $key) |
|
1771 | 1771 | { |
1772 | - if(array_key_exists($key, $array)) { |
|
1772 | + if (array_key_exists($key, $array)) { |
|
1773 | 1773 | unset($array[$key]); |
1774 | 1774 | } |
1775 | 1775 | } |
@@ -1278,12 +1278,14 @@ discard block |
||
1278 | 1278 | } |
1279 | 1279 | |
1280 | 1280 | $total = ($total * 60) + ($interval->i ); |
1281 | - if ($unit == self::INTERVAL_MINUTES) |
|
1282 | - return $total; |
|
1281 | + if ($unit == self::INTERVAL_MINUTES) { |
|
1282 | + return $total; |
|
1283 | + } |
|
1283 | 1284 | |
1284 | 1285 | $total = ($total * 60) + ($interval->s ); |
1285 | - if ($unit == self::INTERVAL_SECONDS) |
|
1286 | - return $total; |
|
1286 | + if ($unit == self::INTERVAL_SECONDS) { |
|
1287 | + return $total; |
|
1288 | + } |
|
1287 | 1289 | |
1288 | 1290 | return 0; |
1289 | 1291 | } |
@@ -1461,8 +1463,7 @@ discard block |
||
1461 | 1463 | if (mb_strlen($actual.$word) <= $width) |
1462 | 1464 | { |
1463 | 1465 | $actual .= $word.' '; |
1464 | - } |
|
1465 | - else |
|
1466 | + } else |
|
1466 | 1467 | { |
1467 | 1468 | if ($actual != '') { |
1468 | 1469 | $line .= rtrim($actual).$break; |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | return $this->setOption('separatorChar', $char); |
18 | 18 | } |
19 | 19 | |
20 | - public function setTrailingNewline($useNewline=true) |
|
20 | + public function setTrailingNewline($useNewline = true) |
|
21 | 21 | { |
22 | 22 | return $this->setOption('trailingNewline', $useNewline); |
23 | 23 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $args = $args[0]; |
39 | 39 | } |
40 | 40 | |
41 | - $this->lines[] = '"' . implode('"'.$this->getOption('separatorChar').'"', $args) . '"'; |
|
41 | + $this->lines[] = '"'.implode('"'.$this->getOption('separatorChar').'"', $args).'"'; |
|
42 | 42 | |
43 | 43 | return $this; |
44 | 44 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | $csv = implode(PHP_EOL, $this->lines); |
56 | 56 | |
57 | - if($this->getOption('trailingNewline')) { |
|
57 | + if ($this->getOption('trailingNewline')) { |
|
58 | 58 | $csv .= PHP_EOL; |
59 | 59 | } |
60 | 60 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | public function setOption($name, $value) |
67 | 67 | { |
68 | - if(!isset($this->options)) { |
|
68 | + if (!isset($this->options)) { |
|
69 | 69 | $this->options = $this->getDefaultOptions(); |
70 | 70 | } |
71 | 71 | |
@@ -75,20 +75,20 @@ discard block |
||
75 | 75 | |
76 | 76 | public function setOptions($options) |
77 | 77 | { |
78 | - foreach($options as $name => $value) { |
|
78 | + foreach ($options as $name => $value) { |
|
79 | 79 | $this->setOption($name, $value); |
80 | 80 | } |
81 | 81 | |
82 | 82 | return $this; |
83 | 83 | } |
84 | 84 | |
85 | - public function getOption($name, $default=null) |
|
85 | + public function getOption($name, $default = null) |
|
86 | 86 | { |
87 | - if(!isset($this->options)) { |
|
87 | + if (!isset($this->options)) { |
|
88 | 88 | $this->options = $this->getDefaultOptions(); |
89 | 89 | } |
90 | 90 | |
91 | - if(isset($this->options[$name])) { |
|
91 | + if (isset($this->options[$name])) { |
|
92 | 92 | return $this->options[$name]; |
93 | 93 | } |
94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | |
98 | 98 | public function hasOption($name) |
99 | 99 | { |
100 | - if(!isset($this->options)) { |
|
100 | + if (!isset($this->options)) { |
|
101 | 101 | $this->options = $this->getDefaultOptions(); |
102 | 102 | } |
103 | 103 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | public function getOptions() |
108 | 108 | { |
109 | - if(!isset($this->options)) { |
|
109 | + if (!isset($this->options)) { |
|
110 | 110 | $this->options = $this->getDefaultOptions(); |
111 | 111 | } |
112 | 112 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | public function isOption($name, $value) |
117 | 117 | { |
118 | - if($this->getOption($name) === $value) { |
|
118 | + if ($this->getOption($name) === $value) { |
|
119 | 119 | return true; |
120 | 120 | } |
121 | 121 |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | |
37 | 37 | protected $classes = array(); |
38 | 38 | |
39 | - /** |
|
40 | - * The namespace detected in the file, if any. |
|
41 | - * @var string |
|
42 | - */ |
|
39 | + /** |
|
40 | + * The namespace detected in the file, if any. |
|
41 | + * @var string |
|
42 | + */ |
|
43 | 43 | protected $namespace = ''; |
44 | 44 | |
45 | - /** |
|
46 | - * @param string $path The path to the PHP file to parse. |
|
47 | - * @throws FileHelper_Exception |
|
48 | - * @see FileHelper::findPHPClasses() |
|
49 | - */ |
|
45 | + /** |
|
46 | + * @param string $path The path to the PHP file to parse. |
|
47 | + * @throws FileHelper_Exception |
|
48 | + * @see FileHelper::findPHPClasses() |
|
49 | + */ |
|
50 | 50 | public function __construct(string $path) |
51 | 51 | { |
52 | 52 | $this->path = realpath($path); |
@@ -66,66 +66,66 @@ discard block |
||
66 | 66 | $this->parseFile(); |
67 | 67 | } |
68 | 68 | |
69 | - /** |
|
70 | - * The name of the namespace of the classes in the file, if any. |
|
71 | - * @return string |
|
72 | - */ |
|
69 | + /** |
|
70 | + * The name of the namespace of the classes in the file, if any. |
|
71 | + * @return string |
|
72 | + */ |
|
73 | 73 | public function getNamespace() : string |
74 | 74 | { |
75 | 75 | return $this->namespace; |
76 | 76 | } |
77 | 77 | |
78 | - /** |
|
79 | - * Whether the file contains a namespace. |
|
80 | - * @return bool |
|
81 | - */ |
|
78 | + /** |
|
79 | + * Whether the file contains a namespace. |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | 82 | public function hasNamespace() : bool |
83 | 83 | { |
84 | 84 | return !empty($this->namespace); |
85 | 85 | } |
86 | 86 | |
87 | - /** |
|
88 | - * The absolute path to the file. |
|
89 | - * @return string |
|
90 | - */ |
|
87 | + /** |
|
88 | + * The absolute path to the file. |
|
89 | + * @return string |
|
90 | + */ |
|
91 | 91 | public function getPath() : string |
92 | 92 | { |
93 | 93 | return $this->path; |
94 | 94 | } |
95 | 95 | |
96 | - /** |
|
97 | - * Whether any classes were found in the file. |
|
98 | - * @return bool |
|
99 | - */ |
|
96 | + /** |
|
97 | + * Whether any classes were found in the file. |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | 100 | public function hasClasses() : bool |
101 | 101 | { |
102 | 102 | return !empty($this->classes); |
103 | 103 | } |
104 | 104 | |
105 | - /** |
|
106 | - * The names of the classes that were found in the file (with namespace if any). |
|
107 | - * @return string[] |
|
108 | - */ |
|
105 | + /** |
|
106 | + * The names of the classes that were found in the file (with namespace if any). |
|
107 | + * @return string[] |
|
108 | + */ |
|
109 | 109 | public function getClassNames() : array |
110 | 110 | { |
111 | 111 | return array_keys($this->classes); |
112 | 112 | } |
113 | 113 | |
114 | - /** |
|
115 | - * Retrieves all classes that were detected in the file, |
|
116 | - * which can be used to retrieve more information about |
|
117 | - * them. |
|
118 | - * |
|
119 | - * @return FileHelper_PHPClassInfo_Class[] |
|
120 | - */ |
|
114 | + /** |
|
115 | + * Retrieves all classes that were detected in the file, |
|
116 | + * which can be used to retrieve more information about |
|
117 | + * them. |
|
118 | + * |
|
119 | + * @return FileHelper_PHPClassInfo_Class[] |
|
120 | + */ |
|
121 | 121 | public function getClasses() |
122 | 122 | { |
123 | 123 | return $this->classes; |
124 | 124 | } |
125 | 125 | |
126 | - /** |
|
127 | - * @throws FileHelper_Exception |
|
128 | - */ |
|
126 | + /** |
|
127 | + * @throws FileHelper_Exception |
|
128 | + */ |
|
129 | 129 | protected function parseFile() |
130 | 130 | { |
131 | 131 | $code = file_get_contents($this->path); |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - /** |
|
184 | - * Strips all whitespace from the string, replacing it with |
|
185 | - * regular spaces (newlines, tabs, etc.). |
|
186 | - * |
|
187 | - * @param string $string |
|
188 | - * @return string |
|
189 | - */ |
|
183 | + /** |
|
184 | + * Strips all whitespace from the string, replacing it with |
|
185 | + * regular spaces (newlines, tabs, etc.). |
|
186 | + * |
|
187 | + * @param string $string |
|
188 | + * @return string |
|
189 | + */ |
|
190 | 190 | protected function stripWhitespace(string $string) : string |
191 | 191 | { |
192 | 192 | return preg_replace('/[\s]/', ' ', $string); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | $this->path = realpath($path); |
53 | 53 | |
54 | - if($this->path === false) |
|
54 | + if ($this->path === false) |
|
55 | 55 | { |
56 | 56 | throw new FileHelper_Exception( |
57 | 57 | 'Cannot extract file information: file not found.', |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | { |
131 | 131 | $code = file_get_contents($this->path); |
132 | 132 | |
133 | - if($code === false) |
|
133 | + if ($code === false) |
|
134 | 134 | { |
135 | 135 | throw new FileHelper_Exception( |
136 | 136 | 'Cannot open file for parsing.', |
@@ -149,24 +149,24 @@ discard block |
||
149 | 149 | |
150 | 150 | $result = array(); |
151 | 151 | preg_match_all('/namespace[\s]+([^;]+);/six', $code, $result, PREG_PATTERN_ORDER); |
152 | - if(isset($result[0]) && isset($result[0][0])) { |
|
152 | + if (isset($result[0]) && isset($result[0][0])) { |
|
153 | 153 | $this->namespace = trim($result[1][0]); |
154 | 154 | } |
155 | 155 | |
156 | 156 | $result = array(); |
157 | 157 | preg_match_all('/(abstract|final)[\s]+class[\s]+([\sa-z0-9\\\\_,]+){|class[\s]+([\sa-z0-9\\\\_,]+){/six', $code, $result, PREG_PATTERN_ORDER); |
158 | 158 | |
159 | - if(!isset($result[0]) || !isset($result[0][0])) { |
|
159 | + if (!isset($result[0]) || !isset($result[0][0])) { |
|
160 | 160 | return; |
161 | 161 | } |
162 | 162 | |
163 | 163 | $indexes = array_keys($result[0]); |
164 | 164 | |
165 | - foreach($indexes as $idx) |
|
165 | + foreach ($indexes as $idx) |
|
166 | 166 | { |
167 | 167 | $keyword = $result[1][$idx]; |
168 | 168 | $declaration = $result[2][$idx]; |
169 | - if(empty($keyword)) { |
|
169 | + if (empty($keyword)) { |
|
170 | 170 | $declaration = $result[3][$idx]; |
171 | 171 | } |
172 | 172 |
@@ -12,9 +12,9 @@ |
||
12 | 12 | |
13 | 13 | const PATH_MODE_STRIP = 'strip'; |
14 | 14 | |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | 18 | protected $path; |
19 | 19 | |
20 | 20 | protected $options = array( |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace AppUtils; |
6 | 6 | |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | return $this; |
98 | 98 | } |
99 | 99 | |
100 | - protected function getOption($name, $default=null) |
|
100 | + protected function getOption($name, $default = null) |
|
101 | 101 | { |
102 | - if(isset($this->options[$name])) { |
|
102 | + if (isset($this->options[$name])) { |
|
103 | 103 | return $this->options[$name]; |
104 | 104 | } |
105 | 105 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | public function getAll() : array |
110 | 110 | { |
111 | - if(!isset($this->found)) { |
|
111 | + if (!isset($this->found)) { |
|
112 | 112 | $this->find($this->path, true); |
113 | 113 | } |
114 | 114 | |
@@ -133,25 +133,25 @@ discard block |
||
133 | 133 | |
134 | 134 | protected $found; |
135 | 135 | |
136 | - protected function find($path, $isRoot=false) |
|
136 | + protected function find($path, $isRoot = false) |
|
137 | 137 | { |
138 | - if($isRoot) { |
|
138 | + if ($isRoot) { |
|
139 | 139 | $this->found = array(); |
140 | 140 | } |
141 | 141 | |
142 | 142 | $d = new \DirectoryIterator($path); |
143 | - foreach($d as $item) |
|
143 | + foreach ($d as $item) |
|
144 | 144 | { |
145 | - if($item->isDir()) |
|
145 | + if ($item->isDir()) |
|
146 | 146 | { |
147 | - if($this->getOption('recursive') === true && !$item->isDot()) { |
|
147 | + if ($this->getOption('recursive') === true && !$item->isDot()) { |
|
148 | 148 | $this->find($item->getPathname()); |
149 | 149 | } |
150 | 150 | } |
151 | 151 | else |
152 | 152 | { |
153 | 153 | $file = $this->filterFile($item->getPathname()); |
154 | - if($file) { |
|
154 | + if ($file) { |
|
155 | 155 | $this->found[] = $file; |
156 | 156 | } |
157 | 157 | } |
@@ -167,20 +167,20 @@ discard block |
||
167 | 167 | $include = $this->getOption('include-extensions'); |
168 | 168 | $exclude = $this->getOption('exclude-extensions'); |
169 | 169 | |
170 | - if(!empty($include)) |
|
170 | + if (!empty($include)) |
|
171 | 171 | { |
172 | - if(!in_array($info['extension'], $include)) { |
|
172 | + if (!in_array($info['extension'], $include)) { |
|
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | } |
176 | - else if(!empty($exclude)) |
|
176 | + else if (!empty($exclude)) |
|
177 | 177 | { |
178 | - if(in_array($info['extension'], $exclude)) { |
|
178 | + if (in_array($info['extension'], $exclude)) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - switch($this->getOption('pathmode')) |
|
183 | + switch ($this->getOption('pathmode')) |
|
184 | 184 | { |
185 | 185 | case self::PATH_MODE_STRIP: |
186 | 186 | $path = basename($path); |
@@ -196,13 +196,13 @@ discard block |
||
196 | 196 | break; |
197 | 197 | } |
198 | 198 | |
199 | - if($this->getOption('strip-extensions') === true) |
|
199 | + if ($this->getOption('strip-extensions') === true) |
|
200 | 200 | { |
201 | 201 | $path = str_replace('.'.$info['extension'], '', $path); |
202 | 202 | } |
203 | 203 | |
204 | 204 | $replace = $this->getOption('slash-replacement'); |
205 | - if(!empty($replace)) { |
|
205 | + if (!empty($replace)) { |
|
206 | 206 | $path = str_replace('/', $replace, $path); |
207 | 207 | } |
208 | 208 |
@@ -147,8 +147,7 @@ discard block |
||
147 | 147 | if($this->getOption('recursive') === true && !$item->isDot()) { |
148 | 148 | $this->find($item->getPathname()); |
149 | 149 | } |
150 | - } |
|
151 | - else |
|
150 | + } else |
|
152 | 151 | { |
153 | 152 | $file = $this->filterFile($item->getPathname()); |
154 | 153 | if($file) { |
@@ -172,8 +171,7 @@ discard block |
||
172 | 171 | if(!in_array($info['extension'], $include)) { |
173 | 172 | return false; |
174 | 173 | } |
175 | - } |
|
176 | - else if(!empty($exclude)) |
|
174 | + } else if(!empty($exclude)) |
|
177 | 175 | { |
178 | 176 | if(in_array($info['extension'], $exclude)) { |
179 | 177 | return false; |
@@ -221,7 +221,7 @@ |
||
221 | 221 | */ |
222 | 222 | public static function getMime($extension) |
223 | 223 | { |
224 | - if(isset(self::$mimeTypes[$extension])) { |
|
224 | + if (isset(self::$mimeTypes[$extension])) { |
|
225 | 225 | return self::$mimeTypes[$extension]; |
226 | 226 | } |
227 | 227 |
@@ -22,51 +22,51 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class FileHelper_PHPClassInfo_Class |
24 | 24 | { |
25 | - /** |
|
26 | - * @var FileHelper_PHPClassInfo |
|
27 | - */ |
|
25 | + /** |
|
26 | + * @var FileHelper_PHPClassInfo |
|
27 | + */ |
|
28 | 28 | protected $info; |
29 | 29 | |
30 | - /** |
|
31 | - * @var bool |
|
32 | - */ |
|
30 | + /** |
|
31 | + * @var bool |
|
32 | + */ |
|
33 | 33 | protected $abstract = false; |
34 | 34 | |
35 | - /** |
|
36 | - * @var bool |
|
37 | - */ |
|
35 | + /** |
|
36 | + * @var bool |
|
37 | + */ |
|
38 | 38 | protected $final = false; |
39 | 39 | |
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | 43 | protected $extends = ''; |
44 | 44 | |
45 | - /** |
|
46 | - * @var string[] |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var string[] |
|
47 | + */ |
|
48 | 48 | protected $implements = array(); |
49 | 49 | |
50 | - /** |
|
51 | - * @var string |
|
52 | - */ |
|
50 | + /** |
|
51 | + * @var string |
|
52 | + */ |
|
53 | 53 | protected $name; |
54 | 54 | |
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | 58 | protected $declaration; |
59 | 59 | |
60 | - /** |
|
61 | - * @var string |
|
62 | - */ |
|
60 | + /** |
|
61 | + * @var string |
|
62 | + */ |
|
63 | 63 | protected $keyword; |
64 | 64 | |
65 | - /** |
|
66 | - * @param FileHelper_PHPClassInfo $info The class info instance. |
|
67 | - * @param string $declaration The full class declaration, e.g. "class SomeName extends SomeOtherClass". |
|
68 | - * @param string $keyword The class keyword, if any, i.e. "abstract" or "final". |
|
69 | - */ |
|
65 | + /** |
|
66 | + * @param FileHelper_PHPClassInfo $info The class info instance. |
|
67 | + * @param string $declaration The full class declaration, e.g. "class SomeName extends SomeOtherClass". |
|
68 | + * @param string $keyword The class keyword, if any, i.e. "abstract" or "final". |
|
69 | + */ |
|
70 | 70 | public function __construct(FileHelper_PHPClassInfo $info, string $declaration, string $keyword) |
71 | 71 | { |
72 | 72 | $this->info = $info; |
@@ -76,31 +76,31 @@ discard block |
||
76 | 76 | $this->analyzeCode(); |
77 | 77 | } |
78 | 78 | |
79 | - /** |
|
80 | - * Check if this class is a subclass of the specified |
|
81 | - * class name. |
|
82 | - * |
|
83 | - * @param string $className |
|
84 | - * @return bool |
|
85 | - */ |
|
79 | + /** |
|
80 | + * Check if this class is a subclass of the specified |
|
81 | + * class name. |
|
82 | + * |
|
83 | + * @param string $className |
|
84 | + * @return bool |
|
85 | + */ |
|
86 | 86 | public function isSublassOf(string $className) : bool |
87 | 87 | { |
88 | 88 | return is_subclass_of($this->getNameNS(), $className); |
89 | 89 | } |
90 | 90 | |
91 | - /** |
|
92 | - * The class name without namespace. |
|
93 | - * @return string |
|
94 | - */ |
|
91 | + /** |
|
92 | + * The class name without namespace. |
|
93 | + * @return string |
|
94 | + */ |
|
95 | 95 | public function getName() : string |
96 | 96 | { |
97 | 97 | return $this->name; |
98 | 98 | } |
99 | 99 | |
100 | - /** |
|
101 | - * The absolute class name with namespace (if any). |
|
102 | - * @return string |
|
103 | - */ |
|
100 | + /** |
|
101 | + * The absolute class name with namespace (if any). |
|
102 | + * @return string |
|
103 | + */ |
|
104 | 104 | public function getNameNS() : string |
105 | 105 | { |
106 | 106 | $name = $this->getName(); |
@@ -112,48 +112,48 @@ discard block |
||
112 | 112 | return $name; |
113 | 113 | } |
114 | 114 | |
115 | - /** |
|
116 | - * Whether it is an abstract class. |
|
117 | - * @return bool |
|
118 | - */ |
|
115 | + /** |
|
116 | + * Whether it is an abstract class. |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | 119 | public function isAbstract() : bool |
120 | 120 | { |
121 | 121 | return $this->abstract; |
122 | 122 | } |
123 | 123 | |
124 | - /** |
|
125 | - * Whether it is a final class. |
|
126 | - * @return bool |
|
127 | - */ |
|
124 | + /** |
|
125 | + * Whether it is a final class. |
|
126 | + * @return bool |
|
127 | + */ |
|
128 | 128 | public function isFinal() : bool |
129 | 129 | { |
130 | 130 | return $this->final; |
131 | 131 | } |
132 | 132 | |
133 | - /** |
|
134 | - * The name of the class that this class extends (with namespace, if specified). |
|
135 | - * @return string |
|
136 | - */ |
|
133 | + /** |
|
134 | + * The name of the class that this class extends (with namespace, if specified). |
|
135 | + * @return string |
|
136 | + */ |
|
137 | 137 | public function getExtends() : string |
138 | 138 | { |
139 | 139 | return $this->extends; |
140 | 140 | } |
141 | 141 | |
142 | - /** |
|
143 | - * A list of interfaces the class implements, if any. |
|
144 | - * @return array |
|
145 | - */ |
|
142 | + /** |
|
143 | + * A list of interfaces the class implements, if any. |
|
144 | + * @return array |
|
145 | + */ |
|
146 | 146 | public function getImplements() : array |
147 | 147 | { |
148 | 148 | return $this->implements; |
149 | 149 | } |
150 | 150 | |
151 | - /** |
|
152 | - * The class declaration string, with normalized spaces and sorted interface names. |
|
153 | - * NOTE: does not include the keyword "abstract" or "final". |
|
154 | - * |
|
155 | - * @return string |
|
156 | - */ |
|
151 | + /** |
|
152 | + * The class declaration string, with normalized spaces and sorted interface names. |
|
153 | + * NOTE: does not include the keyword "abstract" or "final". |
|
154 | + * |
|
155 | + * @return string |
|
156 | + */ |
|
157 | 157 | public function getDeclaration() : string |
158 | 158 | { |
159 | 159 | $parts = array(); |
@@ -173,10 +173,10 @@ discard block |
||
173 | 173 | return implode(' ', $parts); |
174 | 174 | } |
175 | 175 | |
176 | - /** |
|
177 | - * The keyword before "class", e.g. "abstract". |
|
178 | - * @return string |
|
179 | - */ |
|
176 | + /** |
|
177 | + * The keyword before "class", e.g. "abstract". |
|
178 | + * @return string |
|
179 | + */ |
|
180 | 180 | public function getKeyword() : string |
181 | 181 | { |
182 | 182 | return $this->keyword; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | { |
106 | 106 | $name = $this->getName(); |
107 | 107 | |
108 | - if($this->info->hasNamespace()) { |
|
108 | + if ($this->info->hasNamespace()) { |
|
109 | 109 | $name = $this->info->getNamespace().'\\'.$this->name; |
110 | 110 | } |
111 | 111 | |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | $parts[] = 'class'; |
161 | 161 | $parts[] = $this->getName(); |
162 | 162 | |
163 | - if(!empty($this->extends)) { |
|
163 | + if (!empty($this->extends)) { |
|
164 | 164 | $parts[] = 'extends'; |
165 | 165 | $parts[] = $this->extends; |
166 | 166 | } |
167 | 167 | |
168 | - if(!empty($this->implements)) { |
|
168 | + if (!empty($this->implements)) { |
|
169 | 169 | $parts[] = 'implements'; |
170 | 170 | $parts[] = implode(', ', $this->implements); |
171 | 171 | } |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | |
185 | 185 | protected function analyzeCode() |
186 | 186 | { |
187 | - if($this->keyword == 'abstract') { |
|
187 | + if ($this->keyword == 'abstract') { |
|
188 | 188 | $this->abstract = true; |
189 | - } else if($this->keyword == 'final') { |
|
189 | + } else if ($this->keyword == 'final') { |
|
190 | 190 | $this->final = true; |
191 | 191 | } |
192 | 192 | |
@@ -203,16 +203,16 @@ discard block |
||
203 | 203 | |
204 | 204 | $tokenName = 'none'; |
205 | 205 | |
206 | - foreach($parts as $part) |
|
206 | + foreach ($parts as $part) |
|
207 | 207 | { |
208 | 208 | $part = str_replace(',', '', $part); |
209 | 209 | $part = trim($part); |
210 | - if(empty($part)) { |
|
210 | + if (empty($part)) { |
|
211 | 211 | continue; |
212 | 212 | } |
213 | 213 | |
214 | 214 | $name = strtolower($part); |
215 | - if($name == 'extends' || $name == 'implements') { |
|
215 | + if ($name == 'extends' || $name == 'implements') { |
|
216 | 216 | $tokenName = $name; |
217 | 217 | continue; |
218 | 218 | } |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | |
223 | 223 | $this->implements = $tokens['implements']; |
224 | 224 | |
225 | - if(!empty($this->implements)) { |
|
225 | + if (!empty($this->implements)) { |
|
226 | 226 | usort($this->implements, function(string $a, string $b) { |
227 | 227 | return strnatcasecmp($a, $b); |
228 | 228 | }); |
229 | 229 | } |
230 | 230 | |
231 | - if(!empty($tokens['extends'])) { |
|
231 | + if (!empty($tokens['extends'])) { |
|
232 | 232 | $this->extends = $tokens['extends'][0]; |
233 | 233 | } |
234 | 234 | } |
@@ -18,23 +18,23 @@ discard block |
||
18 | 18 | |
19 | 19 | public function __construct(array $size) |
20 | 20 | { |
21 | - if(!isset($size['width'])) { |
|
21 | + if (!isset($size['width'])) { |
|
22 | 22 | $size['width'] = $size[0]; |
23 | 23 | } |
24 | 24 | |
25 | - if(!isset($size['height'])) { |
|
25 | + if (!isset($size['height'])) { |
|
26 | 26 | $size['height'] = $size[1]; |
27 | 27 | } |
28 | 28 | |
29 | - if(!isset($size[0])) { |
|
29 | + if (!isset($size[0])) { |
|
30 | 30 | $size[0] = $size['width']; |
31 | 31 | } |
32 | 32 | |
33 | - if(!isset($size[1])) { |
|
33 | + if (!isset($size[1])) { |
|
34 | 34 | $size[1] = $size['height']; |
35 | 35 | } |
36 | 36 | |
37 | - if(!isset($size['channels'])) { |
|
37 | + if (!isset($size['channels'])) { |
|
38 | 38 | $size['channels'] = 1; |
39 | 39 | } |
40 | 40 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | public function offsetGet($offset) |
70 | 70 | { |
71 | - if(isset($this->size[$offset])) { |
|
71 | + if (isset($this->size[$offset])) { |
|
72 | 72 | return $this->size[$offset]; |
73 | 73 | } |
74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | public function offsetSet($offset, $value) |
79 | 79 | { |
80 | - if(is_null($offset)) { |
|
80 | + if (is_null($offset)) { |
|
81 | 81 | $this->size[] = $value; |
82 | 82 | } else { |
83 | 83 | $this->size[$offset] = $value; |
@@ -58,32 +58,32 @@ discard block |
||
58 | 58 | |
59 | 59 | const ERROR_CANNOT_READ_FILE_CONTENTS = 340028; |
60 | 60 | |
61 | - /** |
|
62 | - * Opens a serialized file and returns the unserialized data. |
|
63 | - * |
|
64 | - * @param string $file |
|
65 | - * @throws FileHelper_Exception |
|
66 | - * @return array |
|
67 | - * @deprecated Use parseSerializedFile() instead. |
|
68 | - * @see FileHelper::parseSerializedFile() |
|
69 | - */ |
|
61 | + /** |
|
62 | + * Opens a serialized file and returns the unserialized data. |
|
63 | + * |
|
64 | + * @param string $file |
|
65 | + * @throws FileHelper_Exception |
|
66 | + * @return array |
|
67 | + * @deprecated Use parseSerializedFile() instead. |
|
68 | + * @see FileHelper::parseSerializedFile() |
|
69 | + */ |
|
70 | 70 | public static function openUnserialized(string $file) : array |
71 | 71 | { |
72 | 72 | return self::parseSerializedFile($file); |
73 | 73 | } |
74 | 74 | |
75 | - /** |
|
76 | - * Opens a serialized file and returns the unserialized data. |
|
77 | - * |
|
78 | - * @param string $file |
|
79 | - * @throws FileHelper_Exception |
|
80 | - * @return array |
|
81 | - * @see FileHelper::parseSerializedFile() |
|
82 | - * |
|
83 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
84 | - * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
85 | - * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
86 | - */ |
|
75 | + /** |
|
76 | + * Opens a serialized file and returns the unserialized data. |
|
77 | + * |
|
78 | + * @param string $file |
|
79 | + * @throws FileHelper_Exception |
|
80 | + * @return array |
|
81 | + * @see FileHelper::parseSerializedFile() |
|
82 | + * |
|
83 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
84 | + * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
85 | + * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
86 | + */ |
|
87 | 87 | public static function parseSerializedFile(string $file) |
88 | 88 | { |
89 | 89 | self::requireFileExists($file); |
@@ -152,13 +152,13 @@ discard block |
||
152 | 152 | return rmdir($rootFolder); |
153 | 153 | } |
154 | 154 | |
155 | - /** |
|
156 | - * Create a folder, if it does not exist yet. |
|
157 | - * |
|
158 | - * @param string $path |
|
159 | - * @throws FileHelper_Exception |
|
160 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
161 | - */ |
|
155 | + /** |
|
156 | + * Create a folder, if it does not exist yet. |
|
157 | + * |
|
158 | + * @param string $path |
|
159 | + * @throws FileHelper_Exception |
|
160 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
161 | + */ |
|
162 | 162 | public static function createFolder($path) |
163 | 163 | { |
164 | 164 | if(is_dir($path) || mkdir($path, 0777, true)) { |
@@ -205,22 +205,22 @@ discard block |
||
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
208 | - /** |
|
209 | - * Copies a file to the target location. Includes checks |
|
210 | - * for most error sources, like the source file not being |
|
211 | - * readable. Automatically creates the target folder if it |
|
212 | - * does not exist yet. |
|
213 | - * |
|
214 | - * @param string $sourcePath |
|
215 | - * @param string $targetPath |
|
216 | - * @throws FileHelper_Exception |
|
217 | - * |
|
218 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
219 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
220 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
221 | - * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
222 | - * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
223 | - */ |
|
208 | + /** |
|
209 | + * Copies a file to the target location. Includes checks |
|
210 | + * for most error sources, like the source file not being |
|
211 | + * readable. Automatically creates the target folder if it |
|
212 | + * does not exist yet. |
|
213 | + * |
|
214 | + * @param string $sourcePath |
|
215 | + * @param string $targetPath |
|
216 | + * @throws FileHelper_Exception |
|
217 | + * |
|
218 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
219 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
220 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
221 | + * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
222 | + * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
223 | + */ |
|
224 | 224 | public static function copyFile($sourcePath, $targetPath) |
225 | 225 | { |
226 | 226 | self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND); |
@@ -271,15 +271,15 @@ discard block |
||
271 | 271 | ); |
272 | 272 | } |
273 | 273 | |
274 | - /** |
|
275 | - * Deletes the target file. Ignored if it cannot be found, |
|
276 | - * and throws an exception if it fails. |
|
277 | - * |
|
278 | - * @param string $filePath |
|
279 | - * @throws FileHelper_Exception |
|
280 | - * |
|
281 | - * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
282 | - */ |
|
274 | + /** |
|
275 | + * Deletes the target file. Ignored if it cannot be found, |
|
276 | + * and throws an exception if it fails. |
|
277 | + * |
|
278 | + * @param string $filePath |
|
279 | + * @throws FileHelper_Exception |
|
280 | + * |
|
281 | + * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
282 | + */ |
|
283 | 283 | public static function deleteFile(string $filePath) : void |
284 | 284 | { |
285 | 285 | if(!file_exists($filePath)) { |
@@ -301,13 +301,13 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
304 | - * Creates a new CSV parser instance and returns it. |
|
305 | - * @param string $delimiter |
|
306 | - * @param string $enclosure |
|
307 | - * @param string $escape |
|
308 | - * @param string $heading |
|
309 | - * @return \parseCSV |
|
310 | - */ |
|
304 | + * Creates a new CSV parser instance and returns it. |
|
305 | + * @param string $delimiter |
|
306 | + * @param string $enclosure |
|
307 | + * @param string $escape |
|
308 | + * @param string $heading |
|
309 | + * @return \parseCSV |
|
310 | + */ |
|
311 | 311 | public static function createCSVParser($delimiter = ';', $enclosure = '"', $escape = '\\', $heading=false) |
312 | 312 | { |
313 | 313 | if($delimiter===null) { $delimiter = ';'; } |
@@ -481,31 +481,31 @@ discard block |
||
481 | 481 | return $output; |
482 | 482 | } |
483 | 483 | |
484 | - /** |
|
485 | - * Verifies whether the target file is a PHP file. The path |
|
486 | - * to the file can be a path to a file as a string, or a |
|
487 | - * DirectoryIterator object instance. |
|
488 | - * |
|
489 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
490 | - * @return boolean |
|
491 | - */ |
|
484 | + /** |
|
485 | + * Verifies whether the target file is a PHP file. The path |
|
486 | + * to the file can be a path to a file as a string, or a |
|
487 | + * DirectoryIterator object instance. |
|
488 | + * |
|
489 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
490 | + * @return boolean |
|
491 | + */ |
|
492 | 492 | public static function isPHPFile($pathOrDirIterator) |
493 | 493 | { |
494 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
495 | - return true; |
|
496 | - } |
|
494 | + if(self::getExtension($pathOrDirIterator) == 'php') { |
|
495 | + return true; |
|
496 | + } |
|
497 | 497 | |
498 | - return false; |
|
498 | + return false; |
|
499 | 499 | } |
500 | 500 | |
501 | - /** |
|
502 | - * Retrieves the extension of the specified file. Can be a path |
|
503 | - * to a file as a string, or a DirectoryIterator object instance. |
|
504 | - * |
|
505 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
506 | - * @param bool $lowercase |
|
507 | - * @return string |
|
508 | - */ |
|
501 | + /** |
|
502 | + * Retrieves the extension of the specified file. Can be a path |
|
503 | + * to a file as a string, or a DirectoryIterator object instance. |
|
504 | + * |
|
505 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
506 | + * @param bool $lowercase |
|
507 | + * @return string |
|
508 | + */ |
|
509 | 509 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
510 | 510 | { |
511 | 511 | if($pathOrDirIterator instanceof \DirectoryIterator) { |
@@ -516,51 +516,51 @@ discard block |
||
516 | 516 | |
517 | 517 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
518 | 518 | if($lowercase) { |
519 | - $ext = mb_strtolower($ext); |
|
519 | + $ext = mb_strtolower($ext); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | return $ext; |
523 | 523 | } |
524 | 524 | |
525 | - /** |
|
526 | - * Retrieves the file name from a path, with or without extension. |
|
527 | - * The path to the file can be a string, or a DirectoryIterator object |
|
528 | - * instance. |
|
529 | - * |
|
530 | - * In case of folders, behaves like the pathinfo function: returns |
|
531 | - * the name of the folder. |
|
532 | - * |
|
533 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
534 | - * @param bool $extension |
|
535 | - * @return string |
|
536 | - */ |
|
525 | + /** |
|
526 | + * Retrieves the file name from a path, with or without extension. |
|
527 | + * The path to the file can be a string, or a DirectoryIterator object |
|
528 | + * instance. |
|
529 | + * |
|
530 | + * In case of folders, behaves like the pathinfo function: returns |
|
531 | + * the name of the folder. |
|
532 | + * |
|
533 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
534 | + * @param bool $extension |
|
535 | + * @return string |
|
536 | + */ |
|
537 | 537 | public static function getFilename($pathOrDirIterator, $extension = true) |
538 | 538 | { |
539 | 539 | $path = $pathOrDirIterator; |
540 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
541 | - $path = $pathOrDirIterator->getFilename(); |
|
542 | - } |
|
540 | + if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
541 | + $path = $pathOrDirIterator->getFilename(); |
|
542 | + } |
|
543 | 543 | |
544 | - $path = self::normalizePath($path); |
|
544 | + $path = self::normalizePath($path); |
|
545 | 545 | |
546 | - if(!$extension) { |
|
547 | - return pathinfo($path, PATHINFO_FILENAME); |
|
548 | - } |
|
546 | + if(!$extension) { |
|
547 | + return pathinfo($path, PATHINFO_FILENAME); |
|
548 | + } |
|
549 | 549 | |
550 | - return pathinfo($path, PATHINFO_BASENAME); |
|
550 | + return pathinfo($path, PATHINFO_BASENAME); |
|
551 | 551 | } |
552 | 552 | |
553 | - /** |
|
554 | - * Tries to read the contents of the target file and |
|
555 | - * treat it as JSON to return the decoded JSON data. |
|
556 | - * |
|
557 | - * @param string $file |
|
558 | - * @throws FileHelper_Exception |
|
559 | - * @return array |
|
560 | - * |
|
561 | - * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
|
562 | - * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
|
563 | - */ |
|
553 | + /** |
|
554 | + * Tries to read the contents of the target file and |
|
555 | + * treat it as JSON to return the decoded JSON data. |
|
556 | + * |
|
557 | + * @param string $file |
|
558 | + * @throws FileHelper_Exception |
|
559 | + * @return array |
|
560 | + * |
|
561 | + * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
|
562 | + * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
|
563 | + */ |
|
564 | 564 | public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
565 | 565 | { |
566 | 566 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
@@ -596,16 +596,16 @@ discard block |
||
596 | 596 | return $json; |
597 | 597 | } |
598 | 598 | |
599 | - /** |
|
600 | - * Corrects common formatting mistakes when users enter |
|
601 | - * file names, like too many spaces, dots and the like. |
|
602 | - * |
|
603 | - * NOTE: if the file name contains a path, the path is |
|
604 | - * stripped, leaving only the file name. |
|
605 | - * |
|
606 | - * @param string $name |
|
607 | - * @return string |
|
608 | - */ |
|
599 | + /** |
|
600 | + * Corrects common formatting mistakes when users enter |
|
601 | + * file names, like too many spaces, dots and the like. |
|
602 | + * |
|
603 | + * NOTE: if the file name contains a path, the path is |
|
604 | + * stripped, leaving only the file name. |
|
605 | + * |
|
606 | + * @param string $name |
|
607 | + * @return string |
|
608 | + */ |
|
609 | 609 | public static function fixFileName(string $name) : string |
610 | 610 | { |
611 | 611 | $name = trim($name); |
@@ -635,40 +635,40 @@ discard block |
||
635 | 635 | return $name; |
636 | 636 | } |
637 | 637 | |
638 | - /** |
|
639 | - * Creates an instance of the file finder, which is an easier |
|
640 | - * alternative to the other manual findFile methods, since all |
|
641 | - * options can be set by chaining. |
|
642 | - * |
|
643 | - * @param string $path |
|
644 | - * @return FileHelper_FileFinder |
|
645 | - */ |
|
638 | + /** |
|
639 | + * Creates an instance of the file finder, which is an easier |
|
640 | + * alternative to the other manual findFile methods, since all |
|
641 | + * options can be set by chaining. |
|
642 | + * |
|
643 | + * @param string $path |
|
644 | + * @return FileHelper_FileFinder |
|
645 | + */ |
|
646 | 646 | public static function createFileFinder(string $path) : FileHelper_FileFinder |
647 | 647 | { |
648 | 648 | return new FileHelper_FileFinder($path); |
649 | 649 | } |
650 | 650 | |
651 | - /** |
|
652 | - * Searches for all HTML files in the target folder. |
|
653 | - * |
|
654 | - * @param string $targetFolder |
|
655 | - * @param array $options |
|
656 | - * @return string[] |
|
657 | - * @see FileHelper::createFileFinder() |
|
658 | - */ |
|
651 | + /** |
|
652 | + * Searches for all HTML files in the target folder. |
|
653 | + * |
|
654 | + * @param string $targetFolder |
|
655 | + * @param array $options |
|
656 | + * @return string[] |
|
657 | + * @see FileHelper::createFileFinder() |
|
658 | + */ |
|
659 | 659 | public static function findHTMLFiles($targetFolder, $options=array()) |
660 | 660 | { |
661 | 661 | return self::findFiles($targetFolder, array('html'), $options); |
662 | 662 | } |
663 | 663 | |
664 | - /** |
|
665 | - * Searches for all PHP files in the target folder. |
|
666 | - * |
|
667 | - * @param string $targetFolder |
|
668 | - * @param array $options |
|
669 | - * @return string[] |
|
670 | - * @see FileHelper::createFileFinder() |
|
671 | - */ |
|
664 | + /** |
|
665 | + * Searches for all PHP files in the target folder. |
|
666 | + * |
|
667 | + * @param string $targetFolder |
|
668 | + * @param array $options |
|
669 | + * @return string[] |
|
670 | + * @see FileHelper::createFileFinder() |
|
671 | + */ |
|
672 | 672 | public static function findPHPFiles($targetFolder, $options=array()) |
673 | 673 | { |
674 | 674 | return self::findFiles($targetFolder, array('php'), $options); |
@@ -754,13 +754,13 @@ discard block |
||
754 | 754 | return $files; |
755 | 755 | } |
756 | 756 | |
757 | - /** |
|
758 | - * Removes the extension from the specified path or file name, |
|
759 | - * if any, and returns the name without the extension. |
|
760 | - * |
|
761 | - * @param string $filename |
|
762 | - * @return sTring |
|
763 | - */ |
|
757 | + /** |
|
758 | + * Removes the extension from the specified path or file name, |
|
759 | + * if any, and returns the name without the extension. |
|
760 | + * |
|
761 | + * @param string $filename |
|
762 | + * @return sTring |
|
763 | + */ |
|
764 | 764 | public static function removeExtension(string $filename) : string |
765 | 765 | { |
766 | 766 | // normalize paths to allow windows style slashes even on nix servers |
@@ -769,22 +769,22 @@ discard block |
||
769 | 769 | return pathinfo($filename, PATHINFO_FILENAME); |
770 | 770 | } |
771 | 771 | |
772 | - /** |
|
773 | - * Detects the UTF BOM in the target file, if any. Returns |
|
774 | - * the encoding matching the BOM, which can be any of the |
|
775 | - * following: |
|
776 | - * |
|
777 | - * <ul> |
|
778 | - * <li>UTF32-BE</li> |
|
779 | - * <li>UTF32-LE</li> |
|
780 | - * <li>UTF16-BE</li> |
|
781 | - * <li>UTF16-LE</li> |
|
782 | - * <li>UTF8</li> |
|
783 | - * </ul> |
|
784 | - * |
|
785 | - * @param string $filename |
|
786 | - * @return string|NULL |
|
787 | - */ |
|
772 | + /** |
|
773 | + * Detects the UTF BOM in the target file, if any. Returns |
|
774 | + * the encoding matching the BOM, which can be any of the |
|
775 | + * following: |
|
776 | + * |
|
777 | + * <ul> |
|
778 | + * <li>UTF32-BE</li> |
|
779 | + * <li>UTF32-LE</li> |
|
780 | + * <li>UTF16-BE</li> |
|
781 | + * <li>UTF16-LE</li> |
|
782 | + * <li>UTF8</li> |
|
783 | + * </ul> |
|
784 | + * |
|
785 | + * @param string $filename |
|
786 | + * @return string|NULL |
|
787 | + */ |
|
788 | 788 | public static function detectUTFBom(string $filename) |
789 | 789 | { |
790 | 790 | $fp = fopen($filename, 'r'); |
@@ -804,13 +804,13 @@ discard block |
||
804 | 804 | |
805 | 805 | protected static $utfBoms; |
806 | 806 | |
807 | - /** |
|
808 | - * Retrieves a list of all UTF byte order mark character |
|
809 | - * sequences, as an assocative array with UTF encoding => bom sequence |
|
810 | - * pairs. |
|
811 | - * |
|
812 | - * @return array |
|
813 | - */ |
|
807 | + /** |
|
808 | + * Retrieves a list of all UTF byte order mark character |
|
809 | + * sequences, as an assocative array with UTF encoding => bom sequence |
|
810 | + * pairs. |
|
811 | + * |
|
812 | + * @return array |
|
813 | + */ |
|
814 | 814 | public static function getUTFBOMs() |
815 | 815 | { |
816 | 816 | if(!isset(self::$utfBoms)) { |
@@ -826,15 +826,15 @@ discard block |
||
826 | 826 | return self::$utfBoms; |
827 | 827 | } |
828 | 828 | |
829 | - /** |
|
830 | - * Checks whether the specified encoding is a valid |
|
831 | - * unicode encoding, for example "UTF16-LE" or "UTF8". |
|
832 | - * Also accounts for alternate way to write the, like |
|
833 | - * "UTF-8", and omitting little/big endian suffixes. |
|
834 | - * |
|
835 | - * @param string $encoding |
|
836 | - * @return boolean |
|
837 | - */ |
|
829 | + /** |
|
830 | + * Checks whether the specified encoding is a valid |
|
831 | + * unicode encoding, for example "UTF16-LE" or "UTF8". |
|
832 | + * Also accounts for alternate way to write the, like |
|
833 | + * "UTF-8", and omitting little/big endian suffixes. |
|
834 | + * |
|
835 | + * @param string $encoding |
|
836 | + * @return boolean |
|
837 | + */ |
|
838 | 838 | public static function isValidUnicodeEncoding(string $encoding) : bool |
839 | 839 | { |
840 | 840 | $encodings = self::getKnownUnicodeEncodings(); |
@@ -853,22 +853,22 @@ discard block |
||
853 | 853 | return in_array($encoding, $keep); |
854 | 854 | } |
855 | 855 | |
856 | - /** |
|
857 | - * Retrieves a list of all known unicode file encodings. |
|
858 | - * @return array |
|
859 | - */ |
|
856 | + /** |
|
857 | + * Retrieves a list of all known unicode file encodings. |
|
858 | + * @return array |
|
859 | + */ |
|
860 | 860 | public static function getKnownUnicodeEncodings() |
861 | 861 | { |
862 | 862 | return array_keys(self::getUTFBOMs()); |
863 | 863 | } |
864 | 864 | |
865 | - /** |
|
866 | - * Normalizes the slash style in a file or folder path, |
|
867 | - * by replacing any antislashes with forward slashes. |
|
868 | - * |
|
869 | - * @param string $path |
|
870 | - * @return string |
|
871 | - */ |
|
865 | + /** |
|
866 | + * Normalizes the slash style in a file or folder path, |
|
867 | + * by replacing any antislashes with forward slashes. |
|
868 | + * |
|
869 | + * @param string $path |
|
870 | + * @return string |
|
871 | + */ |
|
872 | 872 | public static function normalizePath($path) |
873 | 873 | { |
874 | 874 | if(is_string($path)) { |
@@ -905,18 +905,18 @@ discard block |
||
905 | 905 | } |
906 | 906 | } |
907 | 907 | |
908 | - /** |
|
909 | - * Saves the specified content to the target file, creating |
|
910 | - * the file and the folder as necessary. |
|
911 | - * |
|
912 | - * @param string $filePath |
|
913 | - * @param string $content |
|
914 | - * @throws FileHelper_Exception |
|
915 | - * |
|
916 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
917 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
918 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
919 | - */ |
|
908 | + /** |
|
909 | + * Saves the specified content to the target file, creating |
|
910 | + * the file and the folder as necessary. |
|
911 | + * |
|
912 | + * @param string $filePath |
|
913 | + * @param string $content |
|
914 | + * @throws FileHelper_Exception |
|
915 | + * |
|
916 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
917 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
918 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
919 | + */ |
|
920 | 920 | public static function saveFile(string $filePath, string $content='') : void |
921 | 921 | { |
922 | 922 | // target file already exists |
@@ -969,12 +969,12 @@ discard block |
||
969 | 969 | ); |
970 | 970 | } |
971 | 971 | |
972 | - /** |
|
973 | - * Checks whether it is possible to run PHP command |
|
974 | - * line commands. |
|
975 | - * |
|
976 | - * @return boolean |
|
977 | - */ |
|
972 | + /** |
|
973 | + * Checks whether it is possible to run PHP command |
|
974 | + * line commands. |
|
975 | + * |
|
976 | + * @return boolean |
|
977 | + */ |
|
978 | 978 | public static function canMakePHPCalls() : bool |
979 | 979 | { |
980 | 980 | return self::cliCommandExists('php'); |
@@ -1049,16 +1049,16 @@ discard block |
||
1049 | 1049 | return $result; |
1050 | 1050 | } |
1051 | 1051 | |
1052 | - /** |
|
1053 | - * Validates a PHP file's syntax. |
|
1054 | - * |
|
1055 | - * NOTE: This will fail silently if the PHP command line |
|
1056 | - * is not available. Use {@link FileHelper::canMakePHPCalls()} |
|
1057 | - * to check this beforehand as needed. |
|
1058 | - * |
|
1059 | - * @param string $path |
|
1060 | - * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise. |
|
1061 | - */ |
|
1052 | + /** |
|
1053 | + * Validates a PHP file's syntax. |
|
1054 | + * |
|
1055 | + * NOTE: This will fail silently if the PHP command line |
|
1056 | + * is not available. Use {@link FileHelper::canMakePHPCalls()} |
|
1057 | + * to check this beforehand as needed. |
|
1058 | + * |
|
1059 | + * @param string $path |
|
1060 | + * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise. |
|
1061 | + */ |
|
1062 | 1062 | public static function checkPHPFileSyntax($path) |
1063 | 1063 | { |
1064 | 1064 | if(!self::canMakePHPCalls()) { |
@@ -1082,14 +1082,14 @@ discard block |
||
1082 | 1082 | return $output; |
1083 | 1083 | } |
1084 | 1084 | |
1085 | - /** |
|
1086 | - * Retrieves the last modified date for the specified file or folder. |
|
1087 | - * |
|
1088 | - * Note: If the target does not exist, returns null. |
|
1089 | - * |
|
1090 | - * @param string $path |
|
1091 | - * @return \DateTime|NULL |
|
1092 | - */ |
|
1085 | + /** |
|
1086 | + * Retrieves the last modified date for the specified file or folder. |
|
1087 | + * |
|
1088 | + * Note: If the target does not exist, returns null. |
|
1089 | + * |
|
1090 | + * @param string $path |
|
1091 | + * @return \DateTime|NULL |
|
1092 | + */ |
|
1093 | 1093 | public static function getModifiedDate($path) |
1094 | 1094 | { |
1095 | 1095 | $time = filemtime($path); |
@@ -1102,22 +1102,22 @@ discard block |
||
1102 | 1102 | return null; |
1103 | 1103 | } |
1104 | 1104 | |
1105 | - /** |
|
1106 | - * Retrieves the names of all subfolders in the specified path. |
|
1107 | - * |
|
1108 | - * Available options: |
|
1109 | - * |
|
1110 | - * - recursive: true/false |
|
1111 | - * Whether to search for subfolders recursively. |
|
1112 | - * |
|
1113 | - * - absolute-paths: true/false |
|
1114 | - * Whether to return a list of absolute paths. |
|
1115 | - * |
|
1116 | - * @param string $targetFolder |
|
1117 | - * @param array $options |
|
1118 | - * @throws FileHelper_Exception |
|
1119 | - * @return string[] |
|
1120 | - */ |
|
1105 | + /** |
|
1106 | + * Retrieves the names of all subfolders in the specified path. |
|
1107 | + * |
|
1108 | + * Available options: |
|
1109 | + * |
|
1110 | + * - recursive: true/false |
|
1111 | + * Whether to search for subfolders recursively. |
|
1112 | + * |
|
1113 | + * - absolute-paths: true/false |
|
1114 | + * Whether to return a list of absolute paths. |
|
1115 | + * |
|
1116 | + * @param string $targetFolder |
|
1117 | + * @param array $options |
|
1118 | + * @throws FileHelper_Exception |
|
1119 | + * @return string[] |
|
1120 | + */ |
|
1121 | 1121 | public static function getSubfolders($targetFolder, $options = array()) |
1122 | 1122 | { |
1123 | 1123 | if(!is_dir($targetFolder)) |
@@ -1178,16 +1178,16 @@ discard block |
||
1178 | 1178 | return $result; |
1179 | 1179 | } |
1180 | 1180 | |
1181 | - /** |
|
1182 | - * Retrieves the maximum allowed upload file size, in bytes. |
|
1183 | - * Takes into account the PHP ini settings <code>post_max_size</code> |
|
1184 | - * and <code>upload_max_filesize</code>. Since these cannot |
|
1185 | - * be modified at runtime, they are the hard limits for uploads. |
|
1186 | - * |
|
1187 | - * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
1188 | - * |
|
1189 | - * @return int Will return <code>-1</code> if no limit. |
|
1190 | - */ |
|
1181 | + /** |
|
1182 | + * Retrieves the maximum allowed upload file size, in bytes. |
|
1183 | + * Takes into account the PHP ini settings <code>post_max_size</code> |
|
1184 | + * and <code>upload_max_filesize</code>. Since these cannot |
|
1185 | + * be modified at runtime, they are the hard limits for uploads. |
|
1186 | + * |
|
1187 | + * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
1188 | + * |
|
1189 | + * @return int Will return <code>-1</code> if no limit. |
|
1190 | + */ |
|
1191 | 1191 | public static function getMaxUploadFilesize() : int |
1192 | 1192 | { |
1193 | 1193 | static $max_size = -1; |
@@ -1224,16 +1224,16 @@ discard block |
||
1224 | 1224 | return round($size); |
1225 | 1225 | } |
1226 | 1226 | |
1227 | - /** |
|
1228 | - * Makes a path relative using a folder depth: will reduce the |
|
1229 | - * length of the path so that only the amount of folders defined |
|
1230 | - * in the <code>$depth</code> attribute are shown below the actual |
|
1231 | - * folder or file in the path. |
|
1232 | - * |
|
1233 | - * @param string $path The absolute or relative path |
|
1234 | - * @param int $depth The folder depth to reduce the path to |
|
1235 | - * @return string |
|
1236 | - */ |
|
1227 | + /** |
|
1228 | + * Makes a path relative using a folder depth: will reduce the |
|
1229 | + * length of the path so that only the amount of folders defined |
|
1230 | + * in the <code>$depth</code> attribute are shown below the actual |
|
1231 | + * folder or file in the path. |
|
1232 | + * |
|
1233 | + * @param string $path The absolute or relative path |
|
1234 | + * @param int $depth The folder depth to reduce the path to |
|
1235 | + * @return string |
|
1236 | + */ |
|
1237 | 1237 | public static function relativizePathByDepth(string $path, int $depth=2) : string |
1238 | 1238 | { |
1239 | 1239 | $path = self::normalizePath($path); |
@@ -1271,23 +1271,23 @@ discard block |
||
1271 | 1271 | return trim(implode('/', $tokens), '/'); |
1272 | 1272 | } |
1273 | 1273 | |
1274 | - /** |
|
1275 | - * Makes the specified path relative to another path, |
|
1276 | - * by removing one from the other if found. Also |
|
1277 | - * normalizes the path to use forward slashes. |
|
1278 | - * |
|
1279 | - * Example: |
|
1280 | - * |
|
1281 | - * <pre> |
|
1282 | - * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
1283 | - * </pre> |
|
1284 | - * |
|
1285 | - * Result: <code>to/file.txt</code> |
|
1286 | - * |
|
1287 | - * @param string $path |
|
1288 | - * @param string $relativeTo |
|
1289 | - * @return string |
|
1290 | - */ |
|
1274 | + /** |
|
1275 | + * Makes the specified path relative to another path, |
|
1276 | + * by removing one from the other if found. Also |
|
1277 | + * normalizes the path to use forward slashes. |
|
1278 | + * |
|
1279 | + * Example: |
|
1280 | + * |
|
1281 | + * <pre> |
|
1282 | + * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
1283 | + * </pre> |
|
1284 | + * |
|
1285 | + * Result: <code>to/file.txt</code> |
|
1286 | + * |
|
1287 | + * @param string $path |
|
1288 | + * @param string $relativeTo |
|
1289 | + * @return string |
|
1290 | + */ |
|
1291 | 1291 | public static function relativizePath(string $path, string $relativeTo) : string |
1292 | 1292 | { |
1293 | 1293 | $path = self::normalizePath($path); |
@@ -1299,17 +1299,17 @@ discard block |
||
1299 | 1299 | return $relative; |
1300 | 1300 | } |
1301 | 1301 | |
1302 | - /** |
|
1303 | - * Checks that the target file exists, and throws an exception |
|
1304 | - * if it does not. |
|
1305 | - * |
|
1306 | - * @param string $path |
|
1307 | - * @param int|NULL $errorCode Optional custom error code |
|
1308 | - * @throws FileHelper_Exception |
|
1309 | - * @return string The real path to the file |
|
1310 | - * |
|
1311 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1312 | - */ |
|
1302 | + /** |
|
1303 | + * Checks that the target file exists, and throws an exception |
|
1304 | + * if it does not. |
|
1305 | + * |
|
1306 | + * @param string $path |
|
1307 | + * @param int|NULL $errorCode Optional custom error code |
|
1308 | + * @throws FileHelper_Exception |
|
1309 | + * @return string The real path to the file |
|
1310 | + * |
|
1311 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1312 | + */ |
|
1313 | 1313 | public static function requireFileExists(string $path, $errorCode=null) : string |
1314 | 1314 | { |
1315 | 1315 | $result = realpath($path); |
@@ -1328,18 +1328,18 @@ discard block |
||
1328 | 1328 | ); |
1329 | 1329 | } |
1330 | 1330 | |
1331 | - /** |
|
1332 | - * Reads a specific line number from the target file and returns its |
|
1333 | - * contents, if the file has such a line. Does so with little memory |
|
1334 | - * usage, as the file is not read entirely into memory. |
|
1335 | - * |
|
1336 | - * @param string $path |
|
1337 | - * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
1338 | - * @return string|NULL Will return null if the requested line does not exist. |
|
1339 | - * @throws FileHelper_Exception |
|
1340 | - * |
|
1341 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1342 | - */ |
|
1331 | + /** |
|
1332 | + * Reads a specific line number from the target file and returns its |
|
1333 | + * contents, if the file has such a line. Does so with little memory |
|
1334 | + * usage, as the file is not read entirely into memory. |
|
1335 | + * |
|
1336 | + * @param string $path |
|
1337 | + * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
1338 | + * @return string|NULL Will return null if the requested line does not exist. |
|
1339 | + * @throws FileHelper_Exception |
|
1340 | + * |
|
1341 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1342 | + */ |
|
1343 | 1343 | public static function getLineFromFile(string $path, int $lineNumber) : ?string |
1344 | 1344 | { |
1345 | 1345 | self::requireFileExists($path); |
@@ -1355,19 +1355,19 @@ discard block |
||
1355 | 1355 | $file->seek($targetLine); |
1356 | 1356 | |
1357 | 1357 | if($file->key() !== $targetLine) { |
1358 | - return null; |
|
1358 | + return null; |
|
1359 | 1359 | } |
1360 | 1360 | |
1361 | 1361 | return $file->current(); |
1362 | 1362 | } |
1363 | 1363 | |
1364 | - /** |
|
1365 | - * Retrieves the total amount of lines in the file, without |
|
1366 | - * reading the whole file into memory. |
|
1367 | - * |
|
1368 | - * @param string $path |
|
1369 | - * @return int |
|
1370 | - */ |
|
1364 | + /** |
|
1365 | + * Retrieves the total amount of lines in the file, without |
|
1366 | + * reading the whole file into memory. |
|
1367 | + * |
|
1368 | + * @param string $path |
|
1369 | + * @return int |
|
1370 | + */ |
|
1371 | 1371 | public static function countFileLines(string $path) : int |
1372 | 1372 | { |
1373 | 1373 | self::requireFileExists($path); |
@@ -1397,26 +1397,26 @@ discard block |
||
1397 | 1397 | return $number+1; |
1398 | 1398 | } |
1399 | 1399 | |
1400 | - /** |
|
1401 | - * Parses the target file to detect any PHP classes contained |
|
1402 | - * within, and retrieve information on them. Does not use the |
|
1403 | - * PHP reflection API. |
|
1404 | - * |
|
1405 | - * @param string $filePath |
|
1406 | - * @return FileHelper_PHPClassInfo |
|
1407 | - */ |
|
1400 | + /** |
|
1401 | + * Parses the target file to detect any PHP classes contained |
|
1402 | + * within, and retrieve information on them. Does not use the |
|
1403 | + * PHP reflection API. |
|
1404 | + * |
|
1405 | + * @param string $filePath |
|
1406 | + * @return FileHelper_PHPClassInfo |
|
1407 | + */ |
|
1408 | 1408 | public static function findPHPClasses(string $filePath) : FileHelper_PHPClassInfo |
1409 | 1409 | { |
1410 | 1410 | return new FileHelper_PHPClassInfo($filePath); |
1411 | 1411 | } |
1412 | 1412 | |
1413 | - /** |
|
1414 | - * Detects the end of line style used in the target file, if any. |
|
1415 | - * Can be used with large files, because it only reads part of it. |
|
1416 | - * |
|
1417 | - * @param string $filePath The path to the file. |
|
1418 | - * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found. |
|
1419 | - */ |
|
1413 | + /** |
|
1414 | + * Detects the end of line style used in the target file, if any. |
|
1415 | + * Can be used with large files, because it only reads part of it. |
|
1416 | + * |
|
1417 | + * @param string $filePath The path to the file. |
|
1418 | + * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found. |
|
1419 | + */ |
|
1420 | 1420 | public static function detectEOLCharacter(string $filePath) : ?ConvertHelper_EOL |
1421 | 1421 | { |
1422 | 1422 | // 20 lines is enough to get a good picture of the newline style in the file. |
@@ -1429,18 +1429,18 @@ discard block |
||
1429 | 1429 | return ConvertHelper::detectEOLCharacter($string); |
1430 | 1430 | } |
1431 | 1431 | |
1432 | - /** |
|
1433 | - * Reads the specified amount of lines from the target file. |
|
1434 | - * Unicode BOM compatible: any byte order marker is stripped |
|
1435 | - * from the resulting lines. |
|
1436 | - * |
|
1437 | - * @param string $filePath |
|
1438 | - * @param int $amount Set to 0 to read all lines. |
|
1439 | - * @return array |
|
1440 | - * |
|
1441 | - * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
|
1442 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1443 | - */ |
|
1432 | + /** |
|
1433 | + * Reads the specified amount of lines from the target file. |
|
1434 | + * Unicode BOM compatible: any byte order marker is stripped |
|
1435 | + * from the resulting lines. |
|
1436 | + * |
|
1437 | + * @param string $filePath |
|
1438 | + * @param int $amount Set to 0 to read all lines. |
|
1439 | + * @return array |
|
1440 | + * |
|
1441 | + * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
|
1442 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1443 | + */ |
|
1444 | 1444 | public static function readLines(string $filePath, int $amount=0) : array |
1445 | 1445 | { |
1446 | 1446 | self::requireFileExists($filePath); |
@@ -1491,16 +1491,16 @@ discard block |
||
1491 | 1491 | return $result; |
1492 | 1492 | } |
1493 | 1493 | |
1494 | - /** |
|
1495 | - * Reads all content from a file. |
|
1496 | - * |
|
1497 | - * @param string $filePath |
|
1498 | - * @throws FileHelper_Exception |
|
1499 | - * @return string |
|
1500 | - * |
|
1501 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1502 | - * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
1503 | - */ |
|
1494 | + /** |
|
1495 | + * Reads all content from a file. |
|
1496 | + * |
|
1497 | + * @param string $filePath |
|
1498 | + * @throws FileHelper_Exception |
|
1499 | + * @return string |
|
1500 | + * |
|
1501 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1502 | + * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
1503 | + */ |
|
1504 | 1504 | public static function readContents(string $filePath) : string |
1505 | 1505 | { |
1506 | 1506 | self::requireFileExists($filePath); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | $contents = file_get_contents($file); |
92 | 92 | |
93 | - if($contents === false) |
|
93 | + if ($contents === false) |
|
94 | 94 | { |
95 | 95 | throw new FileHelper_Exception( |
96 | 96 | 'Cannot load serialized content from file.', |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | $result = @unserialize($contents); |
106 | 106 | |
107 | - if($result !== false) { |
|
107 | + if ($result !== false) { |
|
108 | 108 | return $result; |
109 | 109 | } |
110 | 110 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | public static function deleteTree($rootFolder) |
122 | 122 | { |
123 | - if(!file_exists($rootFolder)) { |
|
123 | + if (!file_exists($rootFolder)) { |
|
124 | 124 | return true; |
125 | 125 | } |
126 | 126 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public static function createFolder($path) |
163 | 163 | { |
164 | - if(is_dir($path) || mkdir($path, 0777, true)) { |
|
164 | + if (is_dir($path) || mkdir($path, 0777, true)) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | 167 | |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | |
197 | 197 | if ($item->isDir()) |
198 | 198 | { |
199 | - FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName); |
|
199 | + FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target.'/'.$baseName); |
|
200 | 200 | } |
201 | - else if($item->isFile()) |
|
201 | + else if ($item->isFile()) |
|
202 | 202 | { |
203 | - self::copyFile($itemPath, $target . '/' . $baseName); |
|
203 | + self::copyFile($itemPath, $target.'/'.$baseName); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | { |
226 | 226 | self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND); |
227 | 227 | |
228 | - if(!is_readable($sourcePath)) |
|
228 | + if (!is_readable($sourcePath)) |
|
229 | 229 | { |
230 | 230 | throw new FileHelper_Exception( |
231 | 231 | sprintf('Source file [%s] to copy is not readable.', basename($sourcePath)), |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | |
240 | 240 | $targetFolder = dirname($targetPath); |
241 | 241 | |
242 | - if(!file_exists($targetFolder)) |
|
242 | + if (!file_exists($targetFolder)) |
|
243 | 243 | { |
244 | 244 | self::createFolder($targetFolder); |
245 | 245 | } |
246 | - else if(!is_writable($targetFolder)) |
|
246 | + else if (!is_writable($targetFolder)) |
|
247 | 247 | { |
248 | 248 | throw new FileHelper_Exception( |
249 | 249 | sprintf('Target folder [%s] is not writable.', basename($targetFolder)), |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | ); |
256 | 256 | } |
257 | 257 | |
258 | - if(copy($sourcePath, $targetPath)) { |
|
258 | + if (copy($sourcePath, $targetPath)) { |
|
259 | 259 | return; |
260 | 260 | } |
261 | 261 | |
@@ -282,11 +282,11 @@ discard block |
||
282 | 282 | */ |
283 | 283 | public static function deleteFile(string $filePath) : void |
284 | 284 | { |
285 | - if(!file_exists($filePath)) { |
|
285 | + if (!file_exists($filePath)) { |
|
286 | 286 | return; |
287 | 287 | } |
288 | 288 | |
289 | - if(unlink($filePath)) { |
|
289 | + if (unlink($filePath)) { |
|
290 | 290 | return; |
291 | 291 | } |
292 | 292 | |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | * @param string $heading |
309 | 309 | * @return \parseCSV |
310 | 310 | */ |
311 | - public static function createCSVParser($delimiter = ';', $enclosure = '"', $escape = '\\', $heading=false) |
|
311 | + public static function createCSVParser($delimiter = ';', $enclosure = '"', $escape = '\\', $heading = false) |
|
312 | 312 | { |
313 | - if($delimiter===null) { $delimiter = ';'; } |
|
314 | - if($enclosure===null) { $enclosure = '"'; } |
|
315 | - if($escape===null) { $escape = '\\'; } |
|
313 | + if ($delimiter === null) { $delimiter = ';'; } |
|
314 | + if ($enclosure === null) { $enclosure = '"'; } |
|
315 | + if ($escape === null) { $escape = '\\'; } |
|
316 | 316 | |
317 | 317 | $parser = new \parseCSV(null, null, null, array()); |
318 | 318 | |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | * @return array |
335 | 335 | * @see parseCSVFile() |
336 | 336 | */ |
337 | - public static function parseCSVString($csv, $delimiter = ';', $enclosure = '"', $escape = '\\', $heading=false) |
|
337 | + public static function parseCSVString($csv, $delimiter = ';', $enclosure = '"', $escape = '\\', $heading = false) |
|
338 | 338 | { |
339 | 339 | $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading); |
340 | 340 | return $parser->parse_string($csv); |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | * @return array |
352 | 352 | * @see parseCSVString() |
353 | 353 | */ |
354 | - public static function parseCSVFile($filePath, $delimiter = ';', $enclosure = '"', $escape = '\\', $heading=false) |
|
354 | + public static function parseCSVFile($filePath, $delimiter = ';', $enclosure = '"', $escape = '\\', $heading = false) |
|
355 | 355 | { |
356 | 356 | $content = file_get_contents($filePath); |
357 | 357 | if (!$content) { |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | public static function detectMimeType($fileName) |
372 | 372 | { |
373 | 373 | $ext = self::getExtension($fileName); |
374 | - if(empty($ext)) { |
|
374 | + if (empty($ext)) { |
|
375 | 375 | return null; |
376 | 376 | } |
377 | 377 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
393 | 393 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
394 | 394 | */ |
395 | - public static function sendFile($filePath, $fileName = null, $asAttachment=true) |
|
395 | + public static function sendFile($filePath, $fileName = null, $asAttachment = true) |
|
396 | 396 | { |
397 | 397 | self::requireFileExists($filePath); |
398 | 398 | |
@@ -414,10 +414,10 @@ discard block |
||
414 | 414 | |
415 | 415 | header("Cache-Control: public", true); |
416 | 416 | header("Content-Description: File Transfer", true); |
417 | - header("Content-Type: " . $mime, true); |
|
417 | + header("Content-Type: ".$mime, true); |
|
418 | 418 | |
419 | 419 | $disposition = 'inline'; |
420 | - if($asAttachment) { |
|
420 | + if ($asAttachment) { |
|
421 | 421 | $disposition = 'attachment'; |
422 | 422 | } |
423 | 423 | |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | */ |
492 | 492 | public static function isPHPFile($pathOrDirIterator) |
493 | 493 | { |
494 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
494 | + if (self::getExtension($pathOrDirIterator) == 'php') { |
|
495 | 495 | return true; |
496 | 496 | } |
497 | 497 | |
@@ -508,14 +508,14 @@ discard block |
||
508 | 508 | */ |
509 | 509 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
510 | 510 | { |
511 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
511 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
512 | 512 | $filename = $pathOrDirIterator->getFilename(); |
513 | 513 | } else { |
514 | 514 | $filename = basename($pathOrDirIterator); |
515 | 515 | } |
516 | 516 | |
517 | 517 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
518 | - if($lowercase) { |
|
518 | + if ($lowercase) { |
|
519 | 519 | $ext = mb_strtolower($ext); |
520 | 520 | } |
521 | 521 | |
@@ -537,13 +537,13 @@ discard block |
||
537 | 537 | public static function getFilename($pathOrDirIterator, $extension = true) |
538 | 538 | { |
539 | 539 | $path = $pathOrDirIterator; |
540 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
540 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
541 | 541 | $path = $pathOrDirIterator->getFilename(); |
542 | 542 | } |
543 | 543 | |
544 | 544 | $path = self::normalizePath($path); |
545 | 545 | |
546 | - if(!$extension) { |
|
546 | + if (!$extension) { |
|
547 | 547 | return pathinfo($path, PATHINFO_FILENAME); |
548 | 548 | } |
549 | 549 | |
@@ -561,12 +561,12 @@ discard block |
||
561 | 561 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
562 | 562 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
563 | 563 | */ |
564 | - public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
|
564 | + public static function parseJSONFile(string $file, $targetEncoding = null, $sourceEncoding = null) |
|
565 | 565 | { |
566 | 566 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
567 | 567 | |
568 | 568 | $content = file_get_contents($file); |
569 | - if(!$content) { |
|
569 | + if (!$content) { |
|
570 | 570 | throw new FileHelper_Exception( |
571 | 571 | 'Cannot get file contents', |
572 | 572 | sprintf( |
@@ -577,12 +577,12 @@ discard block |
||
577 | 577 | ); |
578 | 578 | } |
579 | 579 | |
580 | - if(isset($targetEncoding)) { |
|
580 | + if (isset($targetEncoding)) { |
|
581 | 581 | $content = mb_convert_encoding($content, $targetEncoding, $sourceEncoding); |
582 | 582 | } |
583 | 583 | |
584 | 584 | $json = json_decode($content, true); |
585 | - if($json === false || $json === NULL) { |
|
585 | + if ($json === false || $json === NULL) { |
|
586 | 586 | throw new FileHelper_Exception( |
587 | 587 | 'Cannot decode json data', |
588 | 588 | sprintf( |
@@ -622,13 +622,13 @@ discard block |
||
622 | 622 | |
623 | 623 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
624 | 624 | |
625 | - while(strstr($name, ' ')) { |
|
625 | + while (strstr($name, ' ')) { |
|
626 | 626 | $name = str_replace(' ', ' ', $name); |
627 | 627 | } |
628 | 628 | |
629 | 629 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
630 | 630 | |
631 | - while(strstr($name, '..')) { |
|
631 | + while (strstr($name, '..')) { |
|
632 | 632 | $name = str_replace('..', '.', $name); |
633 | 633 | } |
634 | 634 | |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | * @return string[] |
657 | 657 | * @see FileHelper::createFileFinder() |
658 | 658 | */ |
659 | - public static function findHTMLFiles($targetFolder, $options=array()) |
|
659 | + public static function findHTMLFiles($targetFolder, $options = array()) |
|
660 | 660 | { |
661 | 661 | return self::findFiles($targetFolder, array('html'), $options); |
662 | 662 | } |
@@ -669,44 +669,44 @@ discard block |
||
669 | 669 | * @return string[] |
670 | 670 | * @see FileHelper::createFileFinder() |
671 | 671 | */ |
672 | - public static function findPHPFiles($targetFolder, $options=array()) |
|
672 | + public static function findPHPFiles($targetFolder, $options = array()) |
|
673 | 673 | { |
674 | 674 | return self::findFiles($targetFolder, array('php'), $options); |
675 | 675 | } |
676 | 676 | |
677 | - public static function findFiles($targetFolder, $extensions=array(), $options=array(), $files=array()) |
|
677 | + public static function findFiles($targetFolder, $extensions = array(), $options = array(), $files = array()) |
|
678 | 678 | { |
679 | - if(!isset($options['strip-extension'])) { |
|
679 | + if (!isset($options['strip-extension'])) { |
|
680 | 680 | $options['strip-extension'] = false; |
681 | 681 | } |
682 | 682 | |
683 | - if(!isset($options['absolute-path'])) { |
|
683 | + if (!isset($options['absolute-path'])) { |
|
684 | 684 | $options['absolute-path'] = false; |
685 | 685 | } |
686 | 686 | |
687 | - if(!isset($options['relative-path'])) { |
|
687 | + if (!isset($options['relative-path'])) { |
|
688 | 688 | $options['relative-path'] = false; |
689 | 689 | } |
690 | 690 | |
691 | - if(!isset($options['recursive'])) { |
|
691 | + if (!isset($options['recursive'])) { |
|
692 | 692 | $options['recursive'] = false; |
693 | 693 | } |
694 | 694 | |
695 | - if($options['relative-path']) { |
|
695 | + if ($options['relative-path']) { |
|
696 | 696 | $options['absolute-path'] = true; |
697 | 697 | } |
698 | 698 | |
699 | - if(!isset($options['__root'])) { |
|
699 | + if (!isset($options['__root'])) { |
|
700 | 700 | $options['__root'] = self::normalizePath($targetFolder); |
701 | 701 | } |
702 | 702 | |
703 | 703 | $checkExtensions = false; |
704 | - if(!empty($extensions)) { |
|
704 | + if (!empty($extensions)) { |
|
705 | 705 | $checkExtensions = true; |
706 | 706 | $extensions = array_map('strtolower', $extensions); |
707 | 707 | } |
708 | 708 | |
709 | - if(!is_dir($targetFolder)) |
|
709 | + if (!is_dir($targetFolder)) |
|
710 | 710 | { |
711 | 711 | throw new FileHelper_Exception( |
712 | 712 | 'Target folder does not exist', |
@@ -719,32 +719,32 @@ discard block |
||
719 | 719 | } |
720 | 720 | |
721 | 721 | $d = new \DirectoryIterator($targetFolder); |
722 | - foreach($d as $item) { |
|
723 | - if($item->isDot()) { |
|
722 | + foreach ($d as $item) { |
|
723 | + if ($item->isDot()) { |
|
724 | 724 | continue; |
725 | 725 | } |
726 | 726 | |
727 | - if($item->isDir()) { |
|
728 | - if($options['recursive']) { |
|
727 | + if ($item->isDir()) { |
|
728 | + if ($options['recursive']) { |
|
729 | 729 | $files = self::findFiles($item->getPathname(), $extensions, $options, $files); |
730 | 730 | } |
731 | 731 | continue; |
732 | 732 | } |
733 | 733 | |
734 | - if($checkExtensions && !in_array(self::getExtension($item, true), $extensions)) { |
|
734 | + if ($checkExtensions && !in_array(self::getExtension($item, true), $extensions)) { |
|
735 | 735 | continue; |
736 | 736 | } |
737 | 737 | |
738 | 738 | $filename = $item->getFilename(); |
739 | - if($options['strip-extension']) { |
|
739 | + if ($options['strip-extension']) { |
|
740 | 740 | $filename = self::removeExtension($filename); |
741 | 741 | } |
742 | 742 | |
743 | - if($options['absolute-path']) { |
|
743 | + if ($options['absolute-path']) { |
|
744 | 744 | $filename = self::normalizePath($targetFolder.'/'.$filename); |
745 | 745 | } |
746 | 746 | |
747 | - if($options['relative-path']) { |
|
747 | + if ($options['relative-path']) { |
|
748 | 748 | $filename = ltrim(str_replace($options['__root'], '', $filename), '/'); |
749 | 749 | } |
750 | 750 | |
@@ -792,9 +792,9 @@ discard block |
||
792 | 792 | fclose($fp); |
793 | 793 | |
794 | 794 | $boms = self::getUTFBOMs(); |
795 | - foreach($boms as $bom => $value) { |
|
795 | + foreach ($boms as $bom => $value) { |
|
796 | 796 | $length = mb_strlen($value); |
797 | - if(mb_substr($text, 0, $length) == $value) { |
|
797 | + if (mb_substr($text, 0, $length) == $value) { |
|
798 | 798 | return $bom; |
799 | 799 | } |
800 | 800 | } |
@@ -813,13 +813,13 @@ discard block |
||
813 | 813 | */ |
814 | 814 | public static function getUTFBOMs() |
815 | 815 | { |
816 | - if(!isset(self::$utfBoms)) { |
|
816 | + if (!isset(self::$utfBoms)) { |
|
817 | 817 | self::$utfBoms = array( |
818 | - 'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF), |
|
819 | - 'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00), |
|
820 | - 'UTF16-BE' => chr(0xFE) . chr(0xFF), |
|
821 | - 'UTF16-LE' => chr(0xFF) . chr(0xFE), |
|
822 | - 'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF) |
|
818 | + 'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF), |
|
819 | + 'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00), |
|
820 | + 'UTF16-BE' => chr(0xFE).chr(0xFF), |
|
821 | + 'UTF16-LE' => chr(0xFF).chr(0xFE), |
|
822 | + 'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF) |
|
823 | 823 | ); |
824 | 824 | } |
825 | 825 | |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | $encodings = self::getKnownUnicodeEncodings(); |
841 | 841 | |
842 | 842 | $keep = array(); |
843 | - foreach($encodings as $string) |
|
843 | + foreach ($encodings as $string) |
|
844 | 844 | { |
845 | 845 | $withHyphen = str_replace('UTF', 'UTF-', $string); |
846 | 846 | |
@@ -871,22 +871,22 @@ discard block |
||
871 | 871 | */ |
872 | 872 | public static function normalizePath($path) |
873 | 873 | { |
874 | - if(is_string($path)) { |
|
874 | + if (is_string($path)) { |
|
875 | 875 | $path = str_replace(array('\\', '//'), array('/', '/'), $path); |
876 | 876 | } |
877 | 877 | |
878 | 878 | return $path; |
879 | 879 | } |
880 | 880 | |
881 | - public static function saveAsJSON($data, $file, $pretty=false) |
|
881 | + public static function saveAsJSON($data, $file, $pretty = false) |
|
882 | 882 | { |
883 | 883 | $options = null; |
884 | - if($pretty) { |
|
884 | + if ($pretty) { |
|
885 | 885 | $options = JSON_PRETTY_PRINT; |
886 | 886 | } |
887 | 887 | |
888 | 888 | $json = json_encode($data, $options); |
889 | - if($json===false) |
|
889 | + if ($json === false) |
|
890 | 890 | { |
891 | 891 | $errorCode = json_last_error(); |
892 | 892 | throw new FileHelper_Exception( |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | ); |
897 | 897 | } |
898 | 898 | |
899 | - if(!file_put_contents($file, $json)) { |
|
899 | + if (!file_put_contents($file, $json)) { |
|
900 | 900 | throw new FileHelper_Exception( |
901 | 901 | sprintf('Could not write the JSON file [%s] to disk.', basename($file)), |
902 | 902 | sprintf('Full path: [%s].', $file), |
@@ -917,12 +917,12 @@ discard block |
||
917 | 917 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
918 | 918 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
919 | 919 | */ |
920 | - public static function saveFile(string $filePath, string $content='') : void |
|
920 | + public static function saveFile(string $filePath, string $content = '') : void |
|
921 | 921 | { |
922 | 922 | // target file already exists |
923 | - if(file_exists($filePath)) |
|
923 | + if (file_exists($filePath)) |
|
924 | 924 | { |
925 | - if(!is_writable($filePath)) |
|
925 | + if (!is_writable($filePath)) |
|
926 | 926 | { |
927 | 927 | throw new FileHelper_Exception( |
928 | 928 | sprintf('Cannot save file: target file [%s] exists, but is not writable.', basename($filePath)), |
@@ -942,7 +942,7 @@ discard block |
||
942 | 942 | // create the folder as needed |
943 | 943 | self::createFolder($targetFolder); |
944 | 944 | |
945 | - if(!is_writable($targetFolder)) |
|
945 | + if (!is_writable($targetFolder)) |
|
946 | 946 | { |
947 | 947 | throw new FileHelper_Exception( |
948 | 948 | sprintf('Cannot save file: target folder [%s] is not writable.', basename($targetFolder)), |
@@ -955,7 +955,7 @@ discard block |
||
955 | 955 | } |
956 | 956 | } |
957 | 957 | |
958 | - if(file_put_contents($filePath, $content) !== false) { |
|
958 | + if (file_put_contents($filePath, $content) !== false) { |
|
959 | 959 | return; |
960 | 960 | } |
961 | 961 | |
@@ -991,7 +991,7 @@ discard block |
||
991 | 991 | { |
992 | 992 | static $checked = array(); |
993 | 993 | |
994 | - if(isset($checked[$command])) { |
|
994 | + if (isset($checked[$command])) { |
|
995 | 995 | return $checked[$command]; |
996 | 996 | } |
997 | 997 | |
@@ -1004,7 +1004,7 @@ discard block |
||
1004 | 1004 | |
1005 | 1005 | $os = strtolower(PHP_OS_FAMILY); |
1006 | 1006 | |
1007 | - if(!isset($osCommands[$os])) |
|
1007 | + if (!isset($osCommands[$os])) |
|
1008 | 1008 | { |
1009 | 1009 | throw new FileHelper_Exception( |
1010 | 1010 | 'Unsupported OS for CLI commands', |
@@ -1030,7 +1030,7 @@ discard block |
||
1030 | 1030 | $pipes |
1031 | 1031 | ); |
1032 | 1032 | |
1033 | - if($process === false) { |
|
1033 | + if ($process === false) { |
|
1034 | 1034 | $checked[$command] = false; |
1035 | 1035 | return false; |
1036 | 1036 | } |
@@ -1061,7 +1061,7 @@ discard block |
||
1061 | 1061 | */ |
1062 | 1062 | public static function checkPHPFileSyntax($path) |
1063 | 1063 | { |
1064 | - if(!self::canMakePHPCalls()) { |
|
1064 | + if (!self::canMakePHPCalls()) { |
|
1065 | 1065 | return true; |
1066 | 1066 | } |
1067 | 1067 | |
@@ -1072,7 +1072,7 @@ discard block |
||
1072 | 1072 | // when the validation is successful, the first entry |
1073 | 1073 | // in the array contains the success message. When it |
1074 | 1074 | // is invalid, the first entry is always empty. |
1075 | - if(!empty($output[0])) { |
|
1075 | + if (!empty($output[0])) { |
|
1076 | 1076 | return true; |
1077 | 1077 | } |
1078 | 1078 | |
@@ -1093,7 +1093,7 @@ discard block |
||
1093 | 1093 | public static function getModifiedDate($path) |
1094 | 1094 | { |
1095 | 1095 | $time = filemtime($path); |
1096 | - if($time !== false) { |
|
1096 | + if ($time !== false) { |
|
1097 | 1097 | $date = new \DateTime(); |
1098 | 1098 | $date->setTimestamp($time); |
1099 | 1099 | return $date; |
@@ -1120,7 +1120,7 @@ discard block |
||
1120 | 1120 | */ |
1121 | 1121 | public static function getSubfolders($targetFolder, $options = array()) |
1122 | 1122 | { |
1123 | - if(!is_dir($targetFolder)) |
|
1123 | + if (!is_dir($targetFolder)) |
|
1124 | 1124 | { |
1125 | 1125 | throw new FileHelper_Exception( |
1126 | 1126 | 'Target folder does not exist', |
@@ -1144,29 +1144,29 @@ discard block |
||
1144 | 1144 | |
1145 | 1145 | $d = new \DirectoryIterator($targetFolder); |
1146 | 1146 | |
1147 | - foreach($d as $item) |
|
1147 | + foreach ($d as $item) |
|
1148 | 1148 | { |
1149 | - if($item->isDir() && !$item->isDot()) |
|
1149 | + if ($item->isDir() && !$item->isDot()) |
|
1150 | 1150 | { |
1151 | 1151 | $name = $item->getFilename(); |
1152 | 1152 | |
1153 | - if(!$options['absolute-path']) { |
|
1153 | + if (!$options['absolute-path']) { |
|
1154 | 1154 | $result[] = $name; |
1155 | 1155 | } else { |
1156 | 1156 | $result[] = $targetFolder.'/'.$name; |
1157 | 1157 | } |
1158 | 1158 | |
1159 | - if(!$options['recursive']) |
|
1159 | + if (!$options['recursive']) |
|
1160 | 1160 | { |
1161 | 1161 | continue; |
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | $subs = self::getSubfolders($targetFolder.'/'.$name, $options); |
1165 | - foreach($subs as $sub) |
|
1165 | + foreach ($subs as $sub) |
|
1166 | 1166 | { |
1167 | 1167 | $relative = $name.'/'.$sub; |
1168 | 1168 | |
1169 | - if(!$options['absolute-path']) { |
|
1169 | + if (!$options['absolute-path']) { |
|
1170 | 1170 | $result[] = $relative; |
1171 | 1171 | } else { |
1172 | 1172 | $result[] = $targetFolder.'/'.$relative; |
@@ -1234,7 +1234,7 @@ discard block |
||
1234 | 1234 | * @param int $depth The folder depth to reduce the path to |
1235 | 1235 | * @return string |
1236 | 1236 | */ |
1237 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
1237 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
1238 | 1238 | { |
1239 | 1239 | $path = self::normalizePath($path); |
1240 | 1240 | |
@@ -1242,17 +1242,17 @@ discard block |
||
1242 | 1242 | $tokens = array_filter($tokens); // remove empty entries (trailing slash for example) |
1243 | 1243 | $tokens = array_values($tokens); // re-index keys |
1244 | 1244 | |
1245 | - if(empty($tokens)) { |
|
1245 | + if (empty($tokens)) { |
|
1246 | 1246 | return ''; |
1247 | 1247 | } |
1248 | 1248 | |
1249 | 1249 | // remove the drive if present |
1250 | - if(strstr($tokens[0], ':')) { |
|
1250 | + if (strstr($tokens[0], ':')) { |
|
1251 | 1251 | array_shift($tokens); |
1252 | 1252 | } |
1253 | 1253 | |
1254 | 1254 | // path was only the drive |
1255 | - if(count($tokens) == 0) { |
|
1255 | + if (count($tokens) == 0) { |
|
1256 | 1256 | return ''; |
1257 | 1257 | } |
1258 | 1258 | |
@@ -1261,8 +1261,8 @@ discard block |
||
1261 | 1261 | |
1262 | 1262 | // reduce the path to the specified depth |
1263 | 1263 | $length = count($tokens); |
1264 | - if($length > $depth) { |
|
1265 | - $tokens = array_slice($tokens, $length-$depth); |
|
1264 | + if ($length > $depth) { |
|
1265 | + $tokens = array_slice($tokens, $length - $depth); |
|
1266 | 1266 | } |
1267 | 1267 | |
1268 | 1268 | // append the last element again |
@@ -1310,14 +1310,14 @@ discard block |
||
1310 | 1310 | * |
1311 | 1311 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
1312 | 1312 | */ |
1313 | - public static function requireFileExists(string $path, $errorCode=null) : string |
|
1313 | + public static function requireFileExists(string $path, $errorCode = null) : string |
|
1314 | 1314 | { |
1315 | 1315 | $result = realpath($path); |
1316 | - if($result !== false) { |
|
1316 | + if ($result !== false) { |
|
1317 | 1317 | return $result; |
1318 | 1318 | } |
1319 | 1319 | |
1320 | - if($errorCode === null) { |
|
1320 | + if ($errorCode === null) { |
|
1321 | 1321 | $errorCode = self::ERROR_FILE_DOES_NOT_EXIST; |
1322 | 1322 | } |
1323 | 1323 | |
@@ -1346,15 +1346,15 @@ discard block |
||
1346 | 1346 | |
1347 | 1347 | $file = new \SplFileObject($path); |
1348 | 1348 | |
1349 | - if($file->eof()) { |
|
1349 | + if ($file->eof()) { |
|
1350 | 1350 | return ''; |
1351 | 1351 | } |
1352 | 1352 | |
1353 | - $targetLine = $lineNumber-1; |
|
1353 | + $targetLine = $lineNumber - 1; |
|
1354 | 1354 | |
1355 | 1355 | $file->seek($targetLine); |
1356 | 1356 | |
1357 | - if($file->key() !== $targetLine) { |
|
1357 | + if ($file->key() !== $targetLine) { |
|
1358 | 1358 | return null; |
1359 | 1359 | } |
1360 | 1360 | |
@@ -1380,7 +1380,7 @@ discard block |
||
1380 | 1380 | $number = $spl->key(); |
1381 | 1381 | |
1382 | 1382 | // if seeking to the end the cursor is still at 0, there are no lines. |
1383 | - if($number === 0) |
|
1383 | + if ($number === 0) |
|
1384 | 1384 | { |
1385 | 1385 | // since it's a very small file, to get reliable results, |
1386 | 1386 | // we read its contents and use that to determine what |
@@ -1388,13 +1388,13 @@ discard block |
||
1388 | 1388 | // that this is not pactical to solve with the SplFileObject. |
1389 | 1389 | $content = file_get_contents($path); |
1390 | 1390 | |
1391 | - if(empty($content)) { |
|
1391 | + if (empty($content)) { |
|
1392 | 1392 | return 0; |
1393 | 1393 | } |
1394 | 1394 | } |
1395 | 1395 | |
1396 | 1396 | // return the line number we were able to reach + 1 (key is zero-based) |
1397 | - return $number+1; |
|
1397 | + return $number + 1; |
|
1398 | 1398 | } |
1399 | 1399 | |
1400 | 1400 | /** |
@@ -1441,13 +1441,13 @@ discard block |
||
1441 | 1441 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
1442 | 1442 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
1443 | 1443 | */ |
1444 | - public static function readLines(string $filePath, int $amount=0) : array |
|
1444 | + public static function readLines(string $filePath, int $amount = 0) : array |
|
1445 | 1445 | { |
1446 | 1446 | self::requireFileExists($filePath); |
1447 | 1447 | |
1448 | 1448 | $fn = fopen($filePath, "r"); |
1449 | 1449 | |
1450 | - if($fn === false) |
|
1450 | + if ($fn === false) |
|
1451 | 1451 | { |
1452 | 1452 | throw new FileHelper_Exception( |
1453 | 1453 | 'Could not open file for reading.', |
@@ -1463,25 +1463,25 @@ discard block |
||
1463 | 1463 | $counter = 0; |
1464 | 1464 | $first = true; |
1465 | 1465 | |
1466 | - while(!feof($fn)) |
|
1466 | + while (!feof($fn)) |
|
1467 | 1467 | { |
1468 | 1468 | $counter++; |
1469 | 1469 | |
1470 | 1470 | $line = fgets($fn); |
1471 | 1471 | |
1472 | 1472 | // can happen with zero length files |
1473 | - if($line === false) { |
|
1473 | + if ($line === false) { |
|
1474 | 1474 | continue; |
1475 | 1475 | } |
1476 | 1476 | |
1477 | 1477 | // the first line may contain a unicode BOM marker. |
1478 | - if($first) { |
|
1478 | + if ($first) { |
|
1479 | 1479 | $line = ConvertHelper::stripUTFBom($line); |
1480 | 1480 | } |
1481 | 1481 | |
1482 | 1482 | $result[] = $line; |
1483 | 1483 | |
1484 | - if($amount > 0 && $counter == $amount) { |
|
1484 | + if ($amount > 0 && $counter == $amount) { |
|
1485 | 1485 | break; |
1486 | 1486 | } |
1487 | 1487 | } |
@@ -1507,7 +1507,7 @@ discard block |
||
1507 | 1507 | |
1508 | 1508 | $result = file_get_contents($filePath); |
1509 | 1509 | |
1510 | - if($result !== false) { |
|
1510 | + if ($result !== false) { |
|
1511 | 1511 | return $result; |
1512 | 1512 | } |
1513 | 1513 |
@@ -197,8 +197,7 @@ discard block |
||
197 | 197 | if ($item->isDir()) |
198 | 198 | { |
199 | 199 | FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName); |
200 | - } |
|
201 | - else if($item->isFile()) |
|
200 | + } else if($item->isFile()) |
|
202 | 201 | { |
203 | 202 | self::copyFile($itemPath, $target . '/' . $baseName); |
204 | 203 | } |
@@ -242,8 +241,7 @@ discard block |
||
242 | 241 | if(!file_exists($targetFolder)) |
243 | 242 | { |
244 | 243 | self::createFolder($targetFolder); |
245 | - } |
|
246 | - else if(!is_writable($targetFolder)) |
|
244 | + } else if(!is_writable($targetFolder)) |
|
247 | 245 | { |
248 | 246 | throw new FileHelper_Exception( |
249 | 247 | sprintf('Target folder [%s] is not writable.', basename($targetFolder)), |