Passed
Push — master ( e76473...8d6fb4 )
by Sebastian
09:39
created
src/URLInfo.php 1 patch
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -37,42 +37,42 @@  discard block
 block discarded – undo
37 37
     public const TYPE_PHONE = 'phone';
38 38
     public const TYPE_URL = 'url';
39 39
 
40
-   /**
41
-    * The original URL that was passed to the constructor.
42
-    * @var string
43
-    */
40
+    /**
41
+     * The original URL that was passed to the constructor.
42
+     * @var string
43
+     */
44 44
     protected string $rawURL;
45 45
 
46
-   /**
47
-    * @var array<string,mixed>
48
-    */
46
+    /**
47
+     * @var array<string,mixed>
48
+     */
49 49
     protected array $info;
50 50
     
51
-   /**
52
-    * @var string[]
53
-    */
51
+    /**
52
+     * @var string[]
53
+     */
54 54
     protected array $excludedParams = array();
55 55
     
56
-   /**
57
-    * @var bool
58
-    * @see URLInfo::setParamExclusion()
59
-    */
56
+    /**
57
+     * @var bool
58
+     * @see URLInfo::setParamExclusion()
59
+     */
60 60
     protected bool $paramExclusion = false;
61 61
     
62
-   /**
63
-    * @var array<string,string>|NULL
64
-    * @see URLInfo::getTypeLabel()
65
-    */
62
+    /**
63
+     * @var array<string,string>|NULL
64
+     * @see URLInfo::getTypeLabel()
65
+     */
66 66
     protected static ?array $typeLabels = null;
67 67
     
68
-   /**
69
-    * @var bool
70
-    */
68
+    /**
69
+     * @var bool
70
+     */
71 71
     protected bool $highlightExcluded = false;
72 72
     
73
-   /**
74
-    * @var string[]
75
-    */
73
+    /**
74
+     * @var string[]
75
+     */
76 76
     protected array $infoKeys = array(
77 77
         'scheme',
78 78
         'host',
@@ -84,24 +84,24 @@  discard block
 block discarded – undo
84 84
         'fragment'
85 85
     );
86 86
     
87
-   /**
88
-    * @var string
89
-    */
87
+    /**
88
+     * @var string
89
+     */
90 90
     protected string $url;
91 91
     
92
-   /**
93
-    * @var URLInfo_Parser
94
-    */
92
+    /**
93
+     * @var URLInfo_Parser
94
+     */
95 95
     protected URLInfo_Parser $parser;
96 96
     
97
-   /**
98
-    * @var URLInfo_Normalizer|NULL
99
-    */
97
+    /**
98
+     * @var URLInfo_Normalizer|NULL
99
+     */
100 100
     protected ?URLInfo_Normalizer $normalizer = null;
101 101
     
102
-   /**
103
-    * @var bool
104
-    */
102
+    /**
103
+     * @var bool
104
+     */
105 105
     protected bool $encodeUTFChars = false;
106 106
     
107 107
     public function __construct(string $url)
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
         $this->info = $this->parser->getInfo();
119 119
     }
120 120
 
121
-   /**
122
-    * Whether to URL encode any non-encoded UTF8 characters in the URL.
123
-    * Default is to leave them as-is for better readability, since 
124
-    * browsers handle this well.
125
-    * 
126
-    * @param bool $enabled
127
-    * @return URLInfo
128
-    */
121
+    /**
122
+     * Whether to URL encode any non-encoded UTF8 characters in the URL.
123
+     * Default is to leave them as-is for better readability, since 
124
+     * browsers handle this well.
125
+     * 
126
+     * @param bool $enabled
127
+     * @return URLInfo
128
+     */
129 129
     public function setUTFEncoding(bool $enabled=true) : URLInfo
130 130
     {
131 131
         if($this->encodeUTFChars !== $enabled)
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
         return $this->encodeUTFChars;
143 143
     }
144 144
     
145
-   /**
146
-    * Filters an URL: removes control characters and the
147
-    * like to have a clean URL to work with.
148
-    * 
149
-    * @param string $url
150
-    * @return string
151
-    */
145
+    /**
146
+     * Filters an URL: removes control characters and the
147
+     * like to have a clean URL to work with.
148
+     * 
149
+     * @param string $url
150
+     * @return string
151
+     */
152 152
     public static function filterURL(string $url)
153 153
     {
154 154
         return URLInfo_Filter::filter($url);
@@ -178,12 +178,12 @@  discard block
 block discarded – undo
178 178
         return $this->info['type'] === self::TYPE_PHONE;
179 179
     }
180 180
     
181
-   /**
182
-    * Whether the URL is a regular URL, not one of the 
183
-    * other types like a phone number or email address.
184
-    * 
185
-    * @return bool
186
-    */
181
+    /**
182
+     * Whether the URL is a regular URL, not one of the 
183
+     * other types like a phone number or email address.
184
+     * 
185
+     * @return bool
186
+     */
187 187
     public function isURL() : bool
188 188
     {
189 189
         $host = $this->getHost();
@@ -195,20 +195,20 @@  discard block
 block discarded – undo
195 195
         return $this->parser->isValid();
196 196
     }
197 197
     
198
-   /**
199
-    * Retrieves the host name, or an empty string if none is present.
200
-    * 
201
-    * @return string
202
-    */
198
+    /**
199
+     * Retrieves the host name, or an empty string if none is present.
200
+     * 
201
+     * @return string
202
+     */
203 203
     public function getHost() : string
204 204
     {
205 205
         return $this->getInfoKey('host');
206 206
     }
207 207
     
208
-   /**
209
-    * Retrieves the path, or an empty string if none is present.
210
-    * @return string
211
-    */
208
+    /**
209
+     * Retrieves the path, or an empty string if none is present.
210
+     * @return string
211
+     */
212 212
     public function getPath() : string
213 213
     {
214 214
         return $this->getInfoKey('path');
@@ -224,10 +224,10 @@  discard block
 block discarded – undo
224 224
         return $this->getInfoKey('scheme');
225 225
     }
226 226
     
227
-   /**
228
-    * Retrieves the port specified in the URL, or -1 if none is preseent.
229
-    * @return int
230
-    */
227
+    /**
228
+     * Retrieves the port specified in the URL, or -1 if none is preseent.
229
+     * @return int
230
+     */
231 231
     public function getPort() : int
232 232
     {
233 233
         $port = $this->getInfoKey('port');
@@ -239,13 +239,13 @@  discard block
 block discarded – undo
239 239
         return -1;
240 240
     }
241 241
     
242
-   /**
243
-    * Retrieves the raw query string, or an empty string if none is present.
244
-    * 
245
-    * @return string
246
-    * 
247
-    * @see URLInfo::getParams()
248
-    */
242
+    /**
243
+     * Retrieves the raw query string, or an empty string if none is present.
244
+     * 
245
+     * @return string
246
+     * 
247
+     * @see URLInfo::getParams()
248
+     */
249 249
     public function getQuery() : string
250 250
     {
251 251
         return $this->getInfoKey('query');
@@ -261,20 +261,20 @@  discard block
 block discarded – undo
261 261
         return $this->getInfoKey('pass');
262 262
     }
263 263
     
264
-   /**
265
-    * Whether the URL contains a port number.
266
-    * @return bool
267
-    */
264
+    /**
265
+     * Whether the URL contains a port number.
266
+     * @return bool
267
+     */
268 268
     public function hasPort() : bool
269 269
     {
270 270
         return $this->getPort() !== -1;
271 271
     }
272 272
     
273
-   /**
274
-    * Alias for the hasParams() method.
275
-    * @return bool
276
-    * @see URLInfo::hasParams()
277
-    */
273
+    /**
274
+     * Alias for the hasParams() method.
275
+     * @return bool
276
+     * @see URLInfo::hasParams()
277
+     */
278 278
     public function hasQuery() : bool
279 279
     {
280 280
         return $this->hasParams();
@@ -319,23 +319,23 @@  discard block
 block discarded – undo
319 319
         return '';
320 320
     }
321 321
 
322
-   /**
323
-    * Retrieves a normalized URL: this ensures that all parameters
324
-    * in the URL are always in the same order.
325
-    * 
326
-    * @return string
327
-    */
322
+    /**
323
+     * Retrieves a normalized URL: this ensures that all parameters
324
+     * in the URL are always in the same order.
325
+     * 
326
+     * @return string
327
+     */
328 328
     public function getNormalized() : string
329 329
     {
330 330
         return $this->normalize(true);
331 331
     }
332 332
     
333
-   /**
334
-    * Like getNormalized(), but if a username and password are present
335
-    * in the URL, returns the URL without them.
336
-    * 
337
-    * @return string
338
-    */
333
+    /**
334
+     * Like getNormalized(), but if a username and password are present
335
+     * in the URL, returns the URL without them.
336
+     * 
337
+     * @return string
338
+     */
339 339
     public function getNormalizedWithoutAuth() : string
340 340
     {
341 341
         return $this->normalize(false);
@@ -356,25 +356,25 @@  discard block
 block discarded – undo
356 356
         return $this->normalizer->normalize();
357 357
     }
358 358
     
359
-   /**
360
-    * Creates a hash of the URL, which can be used for comparisons.
361
-    * Since any parameters in the URL's query are sorted alphabetically,
362
-    * the same links with a different parameter order will have the 
363
-    * same hash.
364
-    * 
365
-    * @return string
366
-    */
359
+    /**
360
+     * Creates a hash of the URL, which can be used for comparisons.
361
+     * Since any parameters in the URL's query are sorted alphabetically,
362
+     * the same links with a different parameter order will have the 
363
+     * same hash.
364
+     * 
365
+     * @return string
366
+     */
367 367
     public function getHash()
368 368
     {
369 369
         return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized());
370 370
     }
371 371
 
372
-   /**
373
-    * Highlights the URL using HTML tags with specific highlighting
374
-    * class names.
375
-    * 
376
-    * @return string Will return an empty string if the URL is not valid.
377
-    */
372
+    /**
373
+     * Highlights the URL using HTML tags with specific highlighting
374
+     * class names.
375
+     * 
376
+     * @return string Will return an empty string if the URL is not valid.
377
+     */
378 378
     public function getHighlighted() : string
379 379
     {
380 380
         if(!$this->isValid()) {
@@ -408,15 +408,15 @@  discard block
 block discarded – undo
408 408
         return count($params);
409 409
     }
410 410
     
411
-   /**
412
-    * Retrieves all parameters specified in the url,
413
-    * if any, as an associative array. 
414
-    * 
415
-    * NOTE: Ignores parameters that have been added
416
-    * to the excluded parameters list.
417
-    *
418
-    * @return array<string,string>
419
-    */
411
+    /**
412
+     * Retrieves all parameters specified in the url,
413
+     * if any, as an associative array. 
414
+     * 
415
+     * NOTE: Ignores parameters that have been added
416
+     * to the excluded parameters list.
417
+     *
418
+     * @return array<string,string>
419
+     */
420 420
     public function getParams() : array
421 421
     {
422 422
         if(!$this->paramExclusion || empty($this->excludedParams)) {
@@ -434,22 +434,22 @@  discard block
 block discarded – undo
434 434
         return $keep;
435 435
     }
436 436
     
437
-   /**
438
-    * Retrieves the names of all parameters present in the URL, if any.
439
-    * @return string[]
440
-    */
437
+    /**
438
+     * Retrieves the names of all parameters present in the URL, if any.
439
+     * @return string[]
440
+     */
441 441
     public function getParamNames() : array
442 442
     {
443 443
         $params = $this->getParams();
444 444
         return array_keys($params);
445 445
     }
446 446
     
447
-   /**
448
-    * Retrieves a specific parameter value from the URL.
449
-    * 
450
-    * @param string $name
451
-    * @return string The parameter value, or an empty string if it does not exist.
452
-    */
447
+    /**
448
+     * Retrieves a specific parameter value from the URL.
449
+     * 
450
+     * @param string $name
451
+     * @return string The parameter value, or an empty string if it does not exist.
452
+     */
453 453
     public function getParam(string $name) : string
454 454
     {
455 455
         if(isset($this->info['params'][$name])) {
@@ -459,16 +459,16 @@  discard block
 block discarded – undo
459 459
         return '';
460 460
     }
461 461
     
462
-   /**
463
-    * Excludes an URL parameter entirely if present:
464
-    * the parser will act as if the parameter was not
465
-    * even present in the source URL, effectively
466
-    * stripping it.
467
-    *
468
-    * @param string $name
469
-    * @param string $reason A human readable explanation why this is excluded - used when highlighting links.
470
-    * @return URLInfo
471
-    */
462
+    /**
463
+     * Excludes an URL parameter entirely if present:
464
+     * the parser will act as if the parameter was not
465
+     * even present in the source URL, effectively
466
+     * stripping it.
467
+     *
468
+     * @param string $name
469
+     * @param string $reason A human readable explanation why this is excluded - used when highlighting links.
470
+     * @return URLInfo
471
+     */
472 472
     public function excludeParam(string $name, string $reason='') : URLInfo
473 473
     {
474 474
         if(!isset($this->excludedParams[$name]))
@@ -521,14 +521,14 @@  discard block
 block discarded – undo
521 521
         return self::$typeLabels[$this->getType()];
522 522
     }
523 523
 
524
-   /**
525
-    * Whether excluded parameters should be highlighted in
526
-    * a different color in the URL when using the
527
-    * {@link URLInfo::getHighlighted()} method.
528
-    *
529
-    * @param bool $highlight
530
-    * @return URLInfo
531
-    */
524
+    /**
525
+     * Whether excluded parameters should be highlighted in
526
+     * a different color in the URL when using the
527
+     * {@link URLInfo::getHighlighted()} method.
528
+     *
529
+     * @param bool $highlight
530
+     * @return URLInfo
531
+     */
532 532
     public function setHighlightExcluded(bool $highlight=true) : URLInfo
533 533
     {
534 534
         $this->highlightExcluded = $highlight;
@@ -584,24 +584,24 @@  discard block
 block discarded – undo
584 584
         return $this;
585 585
     }
586 586
     
587
-   /**
588
-    * Whether the parameter exclusion mode is enabled:
589
-    * In this case, if any parameters have been added to the
590
-    * exclusion list, all relevant methods will exclude these.
591
-    *
592
-    * @return bool
593
-    */
587
+    /**
588
+     * Whether the parameter exclusion mode is enabled:
589
+     * In this case, if any parameters have been added to the
590
+     * exclusion list, all relevant methods will exclude these.
591
+     *
592
+     * @return bool
593
+     */
594 594
     public function isParamExclusionEnabled() : bool
595 595
     {
596 596
         return $this->paramExclusion;
597 597
     }
598 598
     
599
-   /**
600
-    * Checks whether the link contains any parameters that
601
-    * are on the list of excluded parameters.
602
-    *
603
-    * @return bool
604
-    */
599
+    /**
600
+     * Checks whether the link contains any parameters that
601
+     * are on the list of excluded parameters.
602
+     *
603
+     * @return bool
604
+     */
605 605
     public function containsExcludedParams() : bool
606 606
     {
607 607
         if(empty($this->excludedParams)) {
@@ -672,16 +672,16 @@  discard block
 block discarded – undo
672 672
         return $this->highlightExcluded;
673 673
     }
674 674
     
675
-   /**
676
-    * Checks if the URL exists, i.e. can be connected to. Will return
677
-    * true if the returned HTTP status code is `200` or `302`.
678
-    * 
679
-    * NOTE: If the target URL requires HTTP authentication, the username
680
-    * and password should be integrated into the URL.
681
-    * 
682
-    * @return bool
683
-    * @throws BaseException
684
-    */
675
+    /**
676
+     * Checks if the URL exists, i.e. can be connected to. Will return
677
+     * true if the returned HTTP status code is `200` or `302`.
678
+     * 
679
+     * NOTE: If the target URL requires HTTP authentication, the username
680
+     * and password should be integrated into the URL.
681
+     * 
682
+     * @return bool
683
+     * @throws BaseException
684
+     */
685 685
     public function tryConnect(bool $verifySSL=true) : bool
686 686
     {
687 687
         return $this->createConnectionTester()
@@ -689,26 +689,26 @@  discard block
 block discarded – undo
689 689
         ->canConnect();
690 690
     }
691 691
     
692
-   /**
693
-    * Creates the connection tester instance that is used
694
-    * to check if a URL can be connected to, and which is
695
-    * used in the {@see URLInfo::tryConnect()} method. It
696
-    * allows more settings to be used.
697
-    * 
698
-    * @return URLInfo_ConnectionTester
699
-    */
692
+    /**
693
+     * Creates the connection tester instance that is used
694
+     * to check if a URL can be connected to, and which is
695
+     * used in the {@see URLInfo::tryConnect()} method. It
696
+     * allows more settings to be used.
697
+     * 
698
+     * @return URLInfo_ConnectionTester
699
+     */
700 700
     public function createConnectionTester() : URLInfo_ConnectionTester
701 701
     {
702 702
         return new URLInfo_ConnectionTester($this);
703 703
     }
704 704
     
705
-   /**
706
-    * Adds/overwrites an URL parameter.
707
-    *  
708
-    * @param string $name
709
-    * @param string $val
710
-    * @return URLInfo
711
-    */
705
+    /**
706
+     * Adds/overwrites an URL parameter.
707
+     *  
708
+     * @param string $name
709
+     * @param string $val
710
+     * @return URLInfo
711
+     */
712 712
     public function setParam(string $name, string $val) : URLInfo
713 713
     {
714 714
         $this->info['params'][$name] = $val;
@@ -716,13 +716,13 @@  discard block
 block discarded – undo
716 716
         return $this;
717 717
     }
718 718
     
719
-   /**
720
-    * Removes an URL parameter. Has no effect if the 
721
-    * parameter is not present to begin with.
722
-    * 
723
-    * @param string $param
724
-    * @return URLInfo
725
-    */
719
+    /**
720
+     * Removes an URL parameter. Has no effect if the 
721
+     * parameter is not present to begin with.
722
+     * 
723
+     * @param string $param
724
+     * @return URLInfo
725
+     */
726 726
     public function removeParam(string $param) : URLInfo
727 727
     {
728 728
         if(isset($this->info['params'][$param]))
Please login to merge, or discard this patch.
src/FileHelper.php 1 patch
Indentation   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
     public const ERROR_PATH_NOT_WRITABLE = 340039;
72 72
     public const ERROR_PATH_INVALID = 340040;
73 73
 
74
-   /**
75
-    * Opens a serialized file and returns the unserialized data.
76
-    *
77
-    * @param string $file
78
-    * @throws FileHelper_Exception
79
-    * @return array<int|string,mixed>
80
-    * @see SerializedFile::parse()
81
-    * 
82
-    * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
83
-    * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ
84
-    * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED
85
-    */
74
+    /**
75
+     * Opens a serialized file and returns the unserialized data.
76
+     *
77
+     * @param string $file
78
+     * @throws FileHelper_Exception
79
+     * @return array<int|string,mixed>
80
+     * @see SerializedFile::parse()
81
+     * 
82
+     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
83
+     * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ
84
+     * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED
85
+     */
86 86
     public static function parseSerializedFile(string $file) : array
87 87
     {
88 88
         return SerializedFile::factory(self::getFileInfo($file))
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
         return FolderTree::delete($rootFolder);
102 102
     }
103 103
     
104
-   /**
105
-    * Create a folder, if it does not exist yet.
106
-    *  
107
-    * @param string $path
108
-    * @throws FileHelper_Exception
109
-    * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER
110
-    */
104
+    /**
105
+     * Create a folder, if it does not exist yet.
106
+     *  
107
+     * @param string $path
108
+     * @throws FileHelper_Exception
109
+     * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER
110
+     */
111 111
     public static function createFolder(string $path) : void
112 112
     {
113 113
         self::getFolderInfo($path)->create();
@@ -130,36 +130,36 @@  discard block
 block discarded – undo
130 130
         FolderTree::copy($source, $target);
131 131
     }
132 132
     
133
-   /**
134
-    * Copies a file to the target location. Includes checks
135
-    * for most error sources, like the source file not being
136
-    * readable. Automatically creates the target folder if it
137
-    * does not exist yet.
138
-    * 
139
-    * @param string $sourcePath
140
-    * @param string $targetPath
141
-    * @throws FileHelper_Exception
142
-    * 
143
-    * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER
144
-    * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND
145
-    * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE
146
-    * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE
147
-    * @see FileHelper::ERROR_CANNOT_COPY_FILE
148
-    */
133
+    /**
134
+     * Copies a file to the target location. Includes checks
135
+     * for most error sources, like the source file not being
136
+     * readable. Automatically creates the target folder if it
137
+     * does not exist yet.
138
+     * 
139
+     * @param string $sourcePath
140
+     * @param string $targetPath
141
+     * @throws FileHelper_Exception
142
+     * 
143
+     * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER
144
+     * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND
145
+     * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE
146
+     * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE
147
+     * @see FileHelper::ERROR_CANNOT_COPY_FILE
148
+     */
149 149
     public static function copyFile(string $sourcePath, string $targetPath) : void
150 150
     {
151 151
         self::getFileInfo($sourcePath)->copyTo($targetPath);
152 152
     }
153 153
     
154
-   /**
155
-    * Deletes the target file. Ignored if it cannot be found,
156
-    * and throws an exception if it fails.
157
-    * 
158
-    * @param string $filePath
159
-    * @throws FileHelper_Exception
160
-    * 
161
-    * @see FileHelper::ERROR_CANNOT_DELETE_FILE
162
-    */
154
+    /**
155
+     * Deletes the target file. Ignored if it cannot be found,
156
+     * and throws an exception if it fails.
157
+     * 
158
+     * @param string $filePath
159
+     * @throws FileHelper_Exception
160
+     * 
161
+     * @see FileHelper::ERROR_CANNOT_DELETE_FILE
162
+     */
163 163
     public static function deleteFile(string $filePath) : void
164 164
     {
165 165
         self::getFileInfo($filePath)->delete();
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
     }
189 189
 
190 190
     /**
191
-    * Creates a new CSV parser instance and returns it.
192
-    * 
193
-    * @param string $delimiter
194
-    * @param string $enclosure
195
-    * @param string $escape
196
-    * @param bool $heading
197
-    * @return Csv
191
+     * Creates a new CSV parser instance and returns it.
192
+     * 
193
+     * @param string $delimiter
194
+     * @param string $enclosure
195
+     * @param string $escape
196
+     * @param bool $heading
197
+     * @return Csv
198 198
      * @see CSVHelper::createParser()
199
-    */
199
+     */
200 200
     public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : Csv
201 201
     {
202 202
         if($delimiter==='') { $delimiter = ';'; }
@@ -209,21 +209,21 @@  discard block
 block discarded – undo
209 209
         return $parser;
210 210
     }
211 211
 
212
-   /**
213
-    * Parses all lines in the specified string and returns an
214
-    * indexed array with all csv values in each line.
215
-    *
216
-    * @param string $csv
217
-    * @param string $delimiter
218
-    * @param string $enclosure
219
-    * @param string $escape
220
-    * @param bool $heading
221
-    * @return array<int,array<string,string>>
222
-    * @throws FileHelper_Exception
223
-    * 
224
-    * @see parseCSVFile()
225
-    * @see FileHelper::ERROR_PARSING_CSV
226
-    */
212
+    /**
213
+     * Parses all lines in the specified string and returns an
214
+     * indexed array with all csv values in each line.
215
+     *
216
+     * @param string $csv
217
+     * @param string $delimiter
218
+     * @param string $enclosure
219
+     * @param string $escape
220
+     * @param bool $heading
221
+     * @return array<int,array<string,string>>
222
+     * @throws FileHelper_Exception
223
+     * 
224
+     * @see parseCSVFile()
225
+     * @see FileHelper::ERROR_PARSING_CSV
226
+     */
227 227
     public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array
228 228
     {
229 229
         $parser = self::createCSVParser($delimiter, $enclosure, '\\', $heading);
@@ -342,29 +342,29 @@  discard block
 block discarded – undo
342 342
             ->download();
343 343
     }
344 344
     
345
-   /**
346
-    * Verifies whether the target file is a PHP file. The path
347
-    * to the file can be a path to a file as a string, or a 
348
-    * DirectoryIterator object instance.
349
-    * 
350
-    * @param string|DirectoryIterator $pathOrDirIterator
351
-    * @return boolean
352
-    */
345
+    /**
346
+     * Verifies whether the target file is a PHP file. The path
347
+     * to the file can be a path to a file as a string, or a 
348
+     * DirectoryIterator object instance.
349
+     * 
350
+     * @param string|DirectoryIterator $pathOrDirIterator
351
+     * @return boolean
352
+     */
353 353
     public static function isPHPFile($pathOrDirIterator) : bool
354 354
     {
355
-    	return self::getExtension($pathOrDirIterator) === 'php';
355
+        return self::getExtension($pathOrDirIterator) === 'php';
356 356
     }
357 357
     
358
-   /**
359
-    * Retrieves the extension of the specified file. Can be a path
360
-    * to a file as a string, or a DirectoryIterator object instance.
361
-    *
362
-    * NOTE: A folder will return an empty string.
363
-    * 
364
-    * @param string|DirectoryIterator $pathOrDirIterator
365
-    * @param bool $lowercase
366
-    * @return string
367
-    */
358
+    /**
359
+     * Retrieves the extension of the specified file. Can be a path
360
+     * to a file as a string, or a DirectoryIterator object instance.
361
+     *
362
+     * NOTE: A folder will return an empty string.
363
+     * 
364
+     * @param string|DirectoryIterator $pathOrDirIterator
365
+     * @param bool $lowercase
366
+     * @return string
367
+     */
368 368
     public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string
369 369
     {
370 370
         $info = self::getPathInfo($pathOrDirIterator);
@@ -377,18 +377,18 @@  discard block
 block discarded – undo
377 377
         return '';
378 378
     }
379 379
     
380
-   /**
381
-    * Retrieves the file name from a path, with or without extension.
382
-    * The path to the file can be a string, or a DirectoryIterator object
383
-    * instance.
384
-    * 
385
-    * In case of folders, behaves like the "pathinfo" function: returns
386
-    * the name of the folder.
387
-    * 
388
-    * @param string|DirectoryIterator $pathOrDirIterator
389
-    * @param bool $extension
390
-    * @return string
391
-    */
380
+    /**
381
+     * Retrieves the file name from a path, with or without extension.
382
+     * The path to the file can be a string, or a DirectoryIterator object
383
+     * instance.
384
+     * 
385
+     * In case of folders, behaves like the "pathinfo" function: returns
386
+     * the name of the folder.
387
+     * 
388
+     * @param string|DirectoryIterator $pathOrDirIterator
389
+     * @param bool $extension
390
+     * @return string
391
+     */
392 392
     public static function getFilename($pathOrDirIterator, bool $extension = true) : string
393 393
     {
394 394
         $info = self::getPathInfo($pathOrDirIterator);
@@ -422,16 +422,16 @@  discard block
 block discarded – undo
422 422
             ->parse();
423 423
     }
424 424
     
425
-   /**
426
-    * Corrects common formatting mistakes when users enter
427
-    * file names, like too many spaces, dots and the like.
428
-    * 
429
-    * NOTE: if the file name contains a path, the path is
430
-    * stripped, leaving only the file name.
431
-    * 
432
-    * @param string $name
433
-    * @return string
434
-    */
425
+    /**
426
+     * Corrects common formatting mistakes when users enter
427
+     * file names, like too many spaces, dots and the like.
428
+     * 
429
+     * NOTE: if the file name contains a path, the path is
430
+     * stripped, leaving only the file name.
431
+     * 
432
+     * @param string $name
433
+     * @return string
434
+     */
435 435
     public static function fixFileName(string $name) : string
436 436
     {
437 437
         return NameFixer::fixName($name);
@@ -489,20 +489,20 @@  discard block
 block discarded – undo
489 489
         return self::findFiles($targetFolder, array('php'), $options);
490 490
     }
491 491
     
492
-   /**
493
-    * Finds files according to the specified options.
494
-    * 
495
-    * NOTE: This method only exists for backwards compatibility.
496
-    * Use the `createFileFinder()` method instead, which offers
497
-    * an object oriented interface that is much easier to use.
498
-    *  
499
-    * @param string $targetFolder
500
-    * @param string[] $extensions
501
-    * @param array<string,mixed> $options
502
-    * @throws FileHelper_Exception
503
-    * @return string[]
504
-    * @see FileHelper::createFileFinder()
505
-    */
492
+    /**
493
+     * Finds files according to the specified options.
494
+     * 
495
+     * NOTE: This method only exists for backwards compatibility.
496
+     * Use the `createFileFinder()` method instead, which offers
497
+     * an object oriented interface that is much easier to use.
498
+     *  
499
+     * @param string $targetFolder
500
+     * @param string[] $extensions
501
+     * @param array<string,mixed> $options
502
+     * @throws FileHelper_Exception
503
+     * @return string[]
504
+     * @see FileHelper::createFileFinder()
505
+     */
506 506
     public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array()) : array
507 507
     {
508 508
         $finder = self::createFileFinder($targetFolder);
@@ -532,14 +532,14 @@  discard block
 block discarded – undo
532 532
         return $finder->getAll();
533 533
     }
534 534
 
535
-   /**
536
-    * Removes the extension from the specified path or file name,
537
-    * if any, and returns the name without the extension.
538
-    * 
539
-    * @param string $filename
540
-    * @param bool $keepPath Whether to keep the path component, if any. Default PHP pathinfo behavior is not to.
541
-    * @return string
542
-    */
535
+    /**
536
+     * Removes the extension from the specified path or file name,
537
+     * if any, and returns the name without the extension.
538
+     * 
539
+     * @param string $filename
540
+     * @param bool $keepPath Whether to keep the path component, if any. Default PHP pathinfo behavior is not to.
541
+     * @return string
542
+     */
543 543
     public static function removeExtension(string $filename, bool $keepPath=false) : string
544 544
     {
545 545
         return self::getFileInfo($filename)->removeExtension($keepPath);
@@ -570,39 +570,39 @@  discard block
 block discarded – undo
570 570
             ->detectUTFBom(self::getFileInfo($filename));
571 571
     }
572 572
 
573
-   /**
574
-    * Retrieves a list of all UTF byte order mark character
575
-    * sequences, as an associative array with UTF encoding => bom sequence
576
-    * pairs.
577
-    * 
578
-    * @return array<string,string>
579
-    * @deprecated
580
-    */
573
+    /**
574
+     * Retrieves a list of all UTF byte order mark character
575
+     * sequences, as an associative array with UTF encoding => bom sequence
576
+     * pairs.
577
+     * 
578
+     * @return array<string,string>
579
+     * @deprecated
580
+     */
581 581
     public static function getUTFBOMs() : array
582 582
     {
583 583
         return self::createUnicodeHandling()->getUTFBOMs();
584 584
     }
585 585
     
586
-   /**
587
-    * Checks whether the specified encoding is a valid
588
-    * unicode encoding, for example "UTF16-LE" or "UTF8".
589
-    * Also accounts for alternate way to write the, like
590
-    * "UTF-8", and omitting little/big endian suffixes.
591
-    * 
592
-    * @param string $encoding
593
-    * @return boolean
594
-    * @deprecated Use {@see FileHelper::createUnicodeHandling()} instead.
595
-    */
586
+    /**
587
+     * Checks whether the specified encoding is a valid
588
+     * unicode encoding, for example "UTF16-LE" or "UTF8".
589
+     * Also accounts for alternate way to write the, like
590
+     * "UTF-8", and omitting little/big endian suffixes.
591
+     * 
592
+     * @param string $encoding
593
+     * @return boolean
594
+     * @deprecated Use {@see FileHelper::createUnicodeHandling()} instead.
595
+     */
596 596
     public static function isValidUnicodeEncoding(string $encoding) : bool
597 597
     {
598 598
         return self::createUnicodeHandling()->isValidEncoding($encoding);
599 599
     }
600 600
     
601
-   /**
602
-    * Retrieves a list of all known unicode file encodings.
603
-    * @return string[]
604
-    * @deprecated Since v1.10.0. Use the unicode handling class instead.
605
-    */
601
+    /**
602
+     * Retrieves a list of all known unicode file encodings.
603
+     * @return string[]
604
+     * @deprecated Since v1.10.0. Use the unicode handling class instead.
605
+     */
606 606
     public static function getKnownUnicodeEncodings() : array
607 607
     {
608 608
         return self::createUnicodeHandling()->getKnownEncodings();
@@ -623,49 +623,49 @@  discard block
 block discarded – undo
623 623
         return self::$unicodeHandling;
624 624
     }
625 625
     
626
-   /**
627
-    * Normalizes the slash style in a file or folder path,
628
-    * by replacing any anti-slashes with forward slashes.
629
-    * 
630
-    * @param string $path
631
-    * @return string
632
-    */
626
+    /**
627
+     * Normalizes the slash style in a file or folder path,
628
+     * by replacing any anti-slashes with forward slashes.
629
+     * 
630
+     * @param string $path
631
+     * @return string
632
+     */
633 633
     public static function normalizePath(string $path) : string
634 634
     {
635 635
         return str_replace(array('\\', '//'), array('/', '/'), $path);
636 636
     }
637 637
     
638
-   /**
639
-    * Saves the specified data to a file, JSON encoded.
640
-    * 
641
-    * @param mixed $data
642
-    * @param string $file
643
-    * @param bool $pretty
644
-    * @throws FileHelper_Exception
645
-    * 
646
-    * @see FileHelper::ERROR_JSON_ENCODE_ERROR
647
-    * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE
648
-    * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
649
-    * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
650
-    */
638
+    /**
639
+     * Saves the specified data to a file, JSON encoded.
640
+     * 
641
+     * @param mixed $data
642
+     * @param string $file
643
+     * @param bool $pretty
644
+     * @throws FileHelper_Exception
645
+     * 
646
+     * @see FileHelper::ERROR_JSON_ENCODE_ERROR
647
+     * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE
648
+     * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
649
+     * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
650
+     */
651 651
     public static function saveAsJSON($data, string $file, bool $pretty=false) : void
652 652
     {
653 653
         JSONFile::factory(self::getFileInfo($file))
654 654
             ->putData($data, $pretty);
655 655
     }
656 656
    
657
-   /**
658
-    * Saves the specified content to the target file, creating
659
-    * the file and the folder as necessary.
660
-    * 
661
-    * @param string $filePath
662
-    * @param string $content
663
-    * @throws FileHelper_Exception
664
-    * 
665
-    * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE
666
-    * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
667
-    * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
668
-    */
657
+    /**
658
+     * Saves the specified content to the target file, creating
659
+     * the file and the folder as necessary.
660
+     * 
661
+     * @param string $filePath
662
+     * @param string $content
663
+     * @throws FileHelper_Exception
664
+     * 
665
+     * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE
666
+     * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
667
+     * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
668
+     */
669 669
     public static function saveFile(string $filePath, string $content='') : void
670 670
     {
671 671
         self::getFileInfo($filePath)->putContents($content);
@@ -730,14 +730,14 @@  discard block
 block discarded – undo
730 730
         return $output;
731 731
     }
732 732
     
733
-   /**
734
-    * Retrieves the last modified date for the specified file or folder.
735
-    * 
736
-    * Note: If the target does not exist, returns null. 
737
-    * 
738
-    * @param string $path
739
-    * @return DateTime|NULL
740
-    */
733
+    /**
734
+     * Retrieves the last modified date for the specified file or folder.
735
+     * 
736
+     * Note: If the target does not exist, returns null. 
737
+     * 
738
+     * @param string $path
739
+     * @return DateTime|NULL
740
+     */
741 741
     public static function getModifiedDate(string $path) : ?DateTime
742 742
     {
743 743
         $time = filemtime($path);
@@ -777,16 +777,16 @@  discard block
 block discarded – undo
777 777
             ->getPaths();
778 778
     }
779 779
 
780
-   /**
781
-    * Retrieves the maximum allowed upload file size, in bytes.
782
-    * Takes into account the PHP ini settings <code>post_max_size</code>
783
-    * and <code>upload_max_filesize</code>. Since these cannot
784
-    * be modified at runtime, they are the hard limits for uploads.
785
-    * 
786
-    * NOTE: Based on binary values, where 1KB = 1024 Bytes.
787
-    * 
788
-    * @return int Will return <code>-1</code> if no limit.
789
-    */
780
+    /**
781
+     * Retrieves the maximum allowed upload file size, in bytes.
782
+     * Takes into account the PHP ini settings <code>post_max_size</code>
783
+     * and <code>upload_max_filesize</code>. Since these cannot
784
+     * be modified at runtime, they are the hard limits for uploads.
785
+     * 
786
+     * NOTE: Based on binary values, where 1KB = 1024 Bytes.
787
+     * 
788
+     * @return int Will return <code>-1</code> if no limit.
789
+     */
790 790
     public static function getMaxUploadFilesize() : int
791 791
     {
792 792
         static $max_size = -1;
@@ -824,16 +824,16 @@  discard block
 block discarded – undo
824 824
         return round($size);
825 825
     }
826 826
    
827
-   /**
828
-    * Makes a path relative using a folder depth: will reduce the
829
-    * length of the path so that only the amount of folders defined
830
-    * in the <code>$depth</code> attribute are shown below the actual
831
-    * folder or file in the path.
832
-    *  
833
-    * @param string  $path The absolute or relative path
834
-    * @param int $depth The folder depth to reduce the path to
835
-    * @return string
836
-    */
827
+    /**
828
+     * Makes a path relative using a folder depth: will reduce the
829
+     * length of the path so that only the amount of folders defined
830
+     * in the <code>$depth</code> attribute are shown below the actual
831
+     * folder or file in the path.
832
+     *  
833
+     * @param string  $path The absolute or relative path
834
+     * @param int $depth The folder depth to reduce the path to
835
+     * @return string
836
+     */
837 837
     public static function relativizePathByDepth(string $path, int $depth=2) : string
838 838
     {
839 839
         $path = self::normalizePath($path);
@@ -871,23 +871,23 @@  discard block
 block discarded – undo
871 871
         return trim(implode('/', $tokens), '/');
872 872
     }
873 873
     
874
-   /**
875
-    * Makes the specified path relative to another path,
876
-    * by removing one from the other if found. Also 
877
-    * normalizes the path to use forward slashes. 
878
-    * 
879
-    * Example:
880
-    * 
881
-    * <pre>
882
-    * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder');
883
-    * </pre>
884
-    * 
885
-    * Result: <code>to/file.txt</code>
886
-    * 
887
-    * @param string $path
888
-    * @param string $relativeTo
889
-    * @return string
890
-    */
874
+    /**
875
+     * Makes the specified path relative to another path,
876
+     * by removing one from the other if found. Also 
877
+     * normalizes the path to use forward slashes. 
878
+     * 
879
+     * Example:
880
+     * 
881
+     * <pre>
882
+     * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder');
883
+     * </pre>
884
+     * 
885
+     * Result: <code>to/file.txt</code>
886
+     * 
887
+     * @param string $path
888
+     * @param string $relativeTo
889
+     * @return string
890
+     */
891 891
     public static function relativizePath(string $path, string $relativeTo) : string
892 892
     {
893 893
         $path = self::normalizePath($path);
@@ -898,18 +898,18 @@  discard block
 block discarded – undo
898 898
         return trim($relative, '/');
899 899
     }
900 900
     
901
-   /**
902
-    * Checks that the target file exists, and throws an exception
903
-    * if it does not. 
904
-    * 
905
-    * @param string|DirectoryIterator $path
906
-    * @param int|NULL $errorCode Optional custom error code
907
-    * @throws FileHelper_Exception
908
-    * @return string The real path to the file
909
-    * 
910
-    * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
911
-    * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND
912
-    */
901
+    /**
902
+     * Checks that the target file exists, and throws an exception
903
+     * if it does not. 
904
+     * 
905
+     * @param string|DirectoryIterator $path
906
+     * @param int|NULL $errorCode Optional custom error code
907
+     * @throws FileHelper_Exception
908
+     * @return string The real path to the file
909
+     * 
910
+     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
911
+     * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND
912
+     */
913 913
     public static function requireFileExists($path, ?int $errorCode=null) : string
914 914
     {
915 915
         return self::getPathInfo($path)
@@ -932,18 +932,18 @@  discard block
 block discarded – undo
932 932
             ->getPath();
933 933
     }
934 934
     
935
-   /**
936
-    * Reads a specific line number from the target file and returns its
937
-    * contents, if the file has such a line. Does so with little memory
938
-    * usage, as the file is not read entirely into memory.
939
-    * 
940
-    * @param string $path
941
-    * @param int $lineNumber Note: 1-based; the first line is number 1.
942
-    * @return string|NULL Will return null if the requested line does not exist.
943
-    * @throws FileHelper_Exception
944
-    * 
945
-    * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
946
-    */
935
+    /**
936
+     * Reads a specific line number from the target file and returns its
937
+     * contents, if the file has such a line. Does so with little memory
938
+     * usage, as the file is not read entirely into memory.
939
+     * 
940
+     * @param string $path
941
+     * @param int $lineNumber Note: 1-based; the first line is number 1.
942
+     * @return string|NULL Will return null if the requested line does not exist.
943
+     * @throws FileHelper_Exception
944
+     * 
945
+     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
946
+     */
947 947
     public static function getLineFromFile(string $path, int $lineNumber) : ?string
948 948
     {
949 949
         return self::getFileInfo($path)
@@ -951,13 +951,13 @@  discard block
 block discarded – undo
951 951
             ->getLine($lineNumber);
952 952
     }
953 953
     
954
-   /**
955
-    * Retrieves the total amount of lines in the file, without 
956
-    * reading the whole file into memory.
957
-    * 
958
-    * @param string $path
959
-    * @return int
960
-    */
954
+    /**
955
+     * Retrieves the total amount of lines in the file, without 
956
+     * reading the whole file into memory.
957
+     * 
958
+     * @param string $path
959
+     * @return int
960
+     */
961 961
     public static function countFileLines(string $path) : int
962 962
     {
963 963
         return self::getFileInfo($path)
@@ -965,26 +965,26 @@  discard block
 block discarded – undo
965 965
             ->countLines();
966 966
     }
967 967
     
968
-   /**
969
-    * Parses the target file to detect any PHP classes contained
970
-    * within, and retrieve information on them. Does not use the 
971
-    * PHP reflection API.
972
-    * 
973
-    * @param string $filePath
974
-    * @return FileHelper_PHPClassInfo
975
-    */
968
+    /**
969
+     * Parses the target file to detect any PHP classes contained
970
+     * within, and retrieve information on them. Does not use the 
971
+     * PHP reflection API.
972
+     * 
973
+     * @param string $filePath
974
+     * @return FileHelper_PHPClassInfo
975
+     */
976 976
     public static function findPHPClasses(string $filePath) : FileHelper_PHPClassInfo
977 977
     {
978 978
         return new FileHelper_PHPClassInfo($filePath);
979 979
     }
980 980
     
981
-   /**
982
-    * Detects the end of line style used in the target file, if any.
983
-    * Can be used with large files, because it only reads part of it.
984
-    * 
985
-    * @param string $filePath The path to the file.
986
-    * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found.
987
-    */
981
+    /**
982
+     * Detects the end of line style used in the target file, if any.
983
+     * Can be used with large files, because it only reads part of it.
984
+     * 
985
+     * @param string $filePath The path to the file.
986
+     * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found.
987
+     */
988 988
     public static function detectEOLCharacter(string $filePath) : ?ConvertHelper_EOL
989 989
     {
990 990
         // 20 lines is enough to get a good picture of the newline style in the file.
@@ -1017,33 +1017,33 @@  discard block
 block discarded – undo
1017 1017
             ->getLines($amount);
1018 1018
     }
1019 1019
     
1020
-   /**
1021
-    * Reads all content from a file.
1022
-    * 
1023
-    * @param string $filePath
1024
-    * @throws FileHelper_Exception
1025
-    * @return string
1026
-    * 
1027
-    * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1028
-    * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS
1029
-    */
1020
+    /**
1021
+     * Reads all content from a file.
1022
+     * 
1023
+     * @param string $filePath
1024
+     * @throws FileHelper_Exception
1025
+     * @return string
1026
+     * 
1027
+     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1028
+     * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS
1029
+     */
1030 1030
     public static function readContents(string $filePath) : string
1031 1031
     {
1032 1032
         return self::getFileInfo($filePath)->getContents();
1033 1033
     }
1034 1034
 
1035
-   /**
1036
-    * Ensures that the target path exists on disk, and is a folder.
1037
-    * 
1038
-    * @param string $path
1039
-    * @return string The real path, with normalized slashes.
1040
-    * @throws FileHelper_Exception
1041
-    * 
1042
-    * @see FileHelper::normalizePath()
1043
-    * 
1044
-    * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST
1045
-    * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER
1046
-    */
1035
+    /**
1036
+     * Ensures that the target path exists on disk, and is a folder.
1037
+     * 
1038
+     * @param string $path
1039
+     * @return string The real path, with normalized slashes.
1040
+     * @throws FileHelper_Exception
1041
+     * 
1042
+     * @see FileHelper::normalizePath()
1043
+     * 
1044
+     * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST
1045
+     * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER
1046
+     */
1047 1047
     public static function requireFolderExists(string $path) : string
1048 1048
     {
1049 1049
         return self::getFolderInfo($path)
Please login to merge, or discard this patch.
src/Traits/Classable.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
  */
26 26
 trait Traits_Classable
27 27
 {
28
-   /**
29
-    * @var string[]
30
-    */
28
+    /**
29
+     * @var string[]
30
+     */
31 31
     protected array $classes = array();
32 32
 
33 33
     public function hasClasses() : bool
@@ -82,30 +82,30 @@  discard block
 block discarded – undo
82 82
         return $this;
83 83
     }
84 84
     
85
-   /**
86
-    * Retrieves a list of all classes, if any.
87
-    * 
88
-    * @return string[]
89
-    */
85
+    /**
86
+     * Retrieves a list of all classes, if any.
87
+     * 
88
+     * @return string[]
89
+     */
90 90
     public function getClasses() : array
91 91
     {
92 92
         return $this->classes;
93 93
     }
94 94
     
95
-   /**
96
-    * Renders the class names list as space-separated string for use in an HTML tag.
97
-    * 
98
-    * @return string
99
-    */
95
+    /**
96
+     * Renders the class names list as space-separated string for use in an HTML tag.
97
+     * 
98
+     * @return string
99
+     */
100 100
     public function classesToString() : string
101 101
     {
102 102
         return implode(' ', $this->classes);
103 103
     }
104 104
     
105
-   /**
106
-    * Renders the "class" attribute string for inserting into an HTML tag.
107
-    * @return string
108
-    */
105
+    /**
106
+     * Renders the "class" attribute string for inserting into an HTML tag.
107
+     * @return string
108
+     */
109 109
     public function classesToAttribute() : string
110 110
     {
111 111
         if(!empty($this->classes))
Please login to merge, or discard this patch.
src/Traits/Optionable.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
  */
27 27
 trait Traits_Optionable
28 28
 {
29
-   /**
30
-    * @var array<string,mixed>|NULL
31
-    */
29
+    /**
30
+     * @var array<string,mixed>|NULL
31
+     */
32 32
     protected ?array $options = null;
33 33
 
34 34
     /**
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
         return $this;
50 50
     }
51 51
     
52
-   /**
53
-    * Sets a collection of options at once, from an
54
-    * associative array.
55
-    * 
56
-    * @param array<string,mixed> $options
57
-    * @return $this
58
-    */
52
+    /**
53
+     * Sets a collection of options at once, from an
54
+     * associative array.
55
+     * 
56
+     * @param array<string,mixed> $options
57
+     * @return $this
58
+     */
59 59
     public function setOptions(array $options) : self
60 60
     {
61 61
         foreach($options as $name => $value) {
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
         return $this;
66 66
     }
67 67
     
68
-   /**
69
-    * Retrieves an option's value.
70
-    * 
71
-    * NOTE: Use the specialized type getters to ensure an option
72
-    * contains the expected type (for ex. getArrayOption()). 
73
-    * 
74
-    * @param string $name
75
-    * @param mixed $default The default value to return if the option does not exist.
76
-    * @return mixed
77
-    */
68
+    /**
69
+     * Retrieves an option's value.
70
+     * 
71
+     * NOTE: Use the specialized type getters to ensure an option
72
+     * contains the expected type (for ex. getArrayOption()). 
73
+     * 
74
+     * @param string $name
75
+     * @param mixed $default The default value to return if the option does not exist.
76
+     * @return mixed
77
+     */
78 78
     public function getOption(string $name, $default=null)
79 79
     {
80 80
         if(!isset($this->options))
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
         return $this->options[$name] ?? $default;
86 86
     }
87 87
     
88
-   /**
89
-    * Enforces that the option value is a string. Numbers are converted
90
-    * to string, strings are passed through, and all other types will 
91
-    * return the default value. The default value is also returned if
92
-    * the string is empty.
93
-    * 
94
-    * @param string $name
95
-    * @param string $default Used if the option does not exist, is invalid, or empty.
96
-    * @return string
97
-    */
88
+    /**
89
+     * Enforces that the option value is a string. Numbers are converted
90
+     * to string, strings are passed through, and all other types will 
91
+     * return the default value. The default value is also returned if
92
+     * the string is empty.
93
+     * 
94
+     * @param string $name
95
+     * @param string $default Used if the option does not exist, is invalid, or empty.
96
+     * @return string
97
+     */
98 98
     public function getStringOption(string $name, string $default='') : string
99 99
     {
100 100
         $value = $this->getOption($name, false);
@@ -126,15 +126,15 @@  discard block
 block discarded – undo
126 126
         return $default;
127 127
     }
128 128
     
129
-   /**
130
-    * Treats the option value as an integer value: will return
131
-    * valid integer values (also from integer strings), or the
132
-    * default value otherwise.
133
-    * 
134
-    * @param string $name
135
-    * @param int $default
136
-    * @return int
137
-    */
129
+    /**
130
+     * Treats the option value as an integer value: will return
131
+     * valid integer values (also from integer strings), or the
132
+     * default value otherwise.
133
+     * 
134
+     * @param string $name
135
+     * @param int $default
136
+     * @return int
137
+     */
138 138
     public function getIntOption(string $name, int $default=0) : int
139 139
     {
140 140
         $value = $this->getOption($name);
@@ -145,14 +145,14 @@  discard block
 block discarded – undo
145 145
         return $default;
146 146
     }
147 147
     
148
-   /**
149
-    * Treats an option as an array, and returns its value
150
-    * only if it contains an array - otherwise, an empty
151
-    * array is returned.
152
-    * 
153
-    * @param string $name
154
-    * @return array<int|string,mixed>
155
-    */
148
+    /**
149
+     * Treats an option as an array, and returns its value
150
+     * only if it contains an array - otherwise, an empty
151
+     * array is returned.
152
+     * 
153
+     * @param string $name
154
+     * @return array<int|string,mixed>
155
+     */
156 156
     public function getArrayOption(string $name) : array
157 157
     {
158 158
         $val = $this->getOption($name);
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
         return array();
164 164
     }
165 165
     
166
-   /**
167
-    * Checks whether the specified option exists - even
168
-    * if it has a NULL value.
169
-    * 
170
-    * @param string $name
171
-    * @return bool
172
-    */
166
+    /**
167
+     * Checks whether the specified option exists - even
168
+     * if it has a NULL value.
169
+     * 
170
+     * @param string $name
171
+     * @return bool
172
+     */
173 173
     public function hasOption(string $name) : bool
174 174
     {
175 175
         if(!isset($this->options)) {
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
         return array_key_exists($name, $this->options);
180 180
     }
181 181
     
182
-   /**
183
-    * Returns all options in one associative array.
184
-    *
185
-    * @return array<string,mixed>
186
-    */
182
+    /**
183
+     * Returns all options in one associative array.
184
+     *
185
+     * @return array<string,mixed>
186
+     */
187 187
     public function getOptions() : array
188 188
     {
189 189
         if(!isset($this->options)) {
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
         return $this->options;
194 194
     }
195 195
     
196
-   /**
197
-    * Checks whether the option's value is the one specified.
198
-    * 
199
-    * @param string $name
200
-    * @param mixed $value
201
-    * @return bool
202
-    */
196
+    /**
197
+     * Checks whether the option's value is the one specified.
198
+     * 
199
+     * @param string $name
200
+     * @param mixed $value
201
+     * @return bool
202
+     */
203 203
     public function isOption(string $name, $value) : bool
204 204
     {
205 205
         return $this->getOption($name) === $value;
Please login to merge, or discard this patch.
src/ImageHelper.php 1 patch
Indentation   +420 added lines, -420 removed lines patch added patch discarded remove patch
@@ -50,53 +50,53 @@  discard block
 block discarded – undo
50 50
     public const COLORFORMAT_HEX = 2;
51 51
 
52 52
     /**
53
-    * @var string
54
-    */
53
+     * @var string
54
+     */
55 55
     protected $file;
56 56
 
57
-   /**
58
-    * @var ImageHelper_Size
59
-    */
57
+    /**
58
+     * @var ImageHelper_Size
59
+     */
60 60
     protected $info;
61 61
 
62
-   /**
63
-    * @var string
64
-    */
62
+    /**
63
+     * @var string
64
+     */
65 65
     protected $type;
66 66
 
67
-   /**
68
-    * @var resource|NULL
69
-    */
67
+    /**
68
+     * @var resource|NULL
69
+     */
70 70
     protected $newImage;
71 71
 
72
-   /**
73
-    * @var resource
74
-    */
72
+    /**
73
+     * @var resource
74
+     */
75 75
     protected $sourceImage;
76 76
 
77
-   /**
78
-    * @var int
79
-    */
77
+    /**
78
+     * @var int
79
+     */
80 80
     protected $width;
81 81
 
82
-   /**
83
-    * @var int
84
-    */
82
+    /**
83
+     * @var int
84
+     */
85 85
     protected $height;
86 86
 
87
-   /**
88
-    * @var int
89
-    */
87
+    /**
88
+     * @var int
89
+     */
90 90
     protected $newWidth = 0;
91 91
 
92
-   /**
93
-    * @var int
94
-    */
92
+    /**
93
+     * @var int
94
+     */
95 95
     protected $newHeight = 0;
96 96
 
97
-   /**
98
-    * @var int
99
-    */
97
+    /**
98
+     * @var int
99
+     */
100 100
     protected $quality = 85;
101 101
 
102 102
     /**
@@ -201,17 +201,17 @@  discard block
 block discarded – undo
201 201
         }
202 202
     }
203 203
 
204
-   /**
205
-    * Factory method: creates a new helper with a blank image.
206
-    * 
207
-    * @param integer $width
208
-    * @param integer $height
209
-    * @param string $type The target file type when saving
210
-    * @return ImageHelper
211
-    * @throws ImageHelper_Exception
212
-    *
213
-    * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT
214
-    */
204
+    /**
205
+     * Factory method: creates a new helper with a blank image.
206
+     * 
207
+     * @param integer $width
208
+     * @param integer $height
209
+     * @param string $type The target file type when saving
210
+     * @return ImageHelper
211
+     * @throws ImageHelper_Exception
212
+     *
213
+     * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT
214
+     */
215 215
     public static function createNew($width, $height, $type='png')
216 216
     {
217 217
         $img = imagecreatetruecolor($width, $height);
@@ -226,18 +226,18 @@  discard block
 block discarded – undo
226 226
         );
227 227
     }
228 228
     
229
-   /**
230
-    * Factory method: creates an image helper from an
231
-    * existing image resource.
232
-    *
233
-    * Note: while the resource is type independent, the
234
-    * type parameter is required for some methods, as well
235
-    * as to be able to save the image.
236
-    *
237
-    * @param resource $resource
238
-    * @param string $type The target image type, e.g. "jpeg", "png", etc.
239
-    * @return ImageHelper
240
-    */
229
+    /**
230
+     * Factory method: creates an image helper from an
231
+     * existing image resource.
232
+     *
233
+     * Note: while the resource is type independent, the
234
+     * type parameter is required for some methods, as well
235
+     * as to be able to save the image.
236
+     *
237
+     * @param resource $resource
238
+     * @param string $type The target image type, e.g. "jpeg", "png", etc.
239
+     * @return ImageHelper
240
+     */
241 241
     public static function createFromResource($resource, ?string $type=null)
242 242
     {
243 243
         self::requireResource($resource);
@@ -245,29 +245,29 @@  discard block
 block discarded – undo
245 245
         return new ImageHelper(null, $resource, $type);
246 246
     }
247 247
     
248
-   /**
249
-    * Factory method: creates an image helper from an
250
-    * image file on disk.
251
-    *
252
-    * @param string $file
253
-    * @return ImageHelper
254
-    */
248
+    /**
249
+     * Factory method: creates an image helper from an
250
+     * image file on disk.
251
+     *
252
+     * @param string $file
253
+     * @return ImageHelper
254
+     */
255 255
     public static function createFromFile(string $file) : ImageHelper
256 256
     {
257 257
         return new ImageHelper($file);
258 258
     }
259 259
     
260
-   /**
261
-    * Sets a global image helper configuration value. Available
262
-    * configuration settings are:
263
-    * 
264
-    * <ul>
265
-    * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether totry and adjust the memory limit automatically so there will be enough to load/process the target image.</li>
266
-    * </ul>
267
-    * 
268
-    * @param string $name
269
-    * @param mixed $value
270
-    */
260
+    /**
261
+     * Sets a global image helper configuration value. Available
262
+     * configuration settings are:
263
+     * 
264
+     * <ul>
265
+     * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether totry and adjust the memory limit automatically so there will be enough to load/process the target image.</li>
266
+     * </ul>
267
+     * 
268
+     * @param string $name
269
+     * @param mixed $value
270
+     */
271 271
     public static function setConfig($name, $value)
272 272
     {
273 273
         if(isset(self::$config[$name])) {
@@ -275,22 +275,22 @@  discard block
 block discarded – undo
275 275
         }
276 276
     }
277 277
     
278
-   /**
279
-    * Shorthand for setting the automatic memory adjustment
280
-    * global configuration setting.
281
-    * 
282
-    * @param bool $enabled
283
-    */
278
+    /**
279
+     * Shorthand for setting the automatic memory adjustment
280
+     * global configuration setting.
281
+     * 
282
+     * @param bool $enabled
283
+     */
284 284
     public static function setAutoMemoryAdjustment($enabled=true)
285 285
     {
286 286
         self::setConfig('auto-memory-adjustment', $enabled);
287 287
     }
288 288
     
289
-   /**
290
-    * Duplicates an image resource.
291
-    * @param resource $img
292
-    * @return resource
293
-    */
289
+    /**
290
+     * Duplicates an image resource.
291
+     * @param resource $img
292
+     * @return resource
293
+     */
294 294
     protected function duplicateImage($img)
295 295
     {
296 296
         self::requireResource($img);
@@ -302,12 +302,12 @@  discard block
 block discarded – undo
302 302
         return $duplicate;
303 303
     }
304 304
     
305
-   /**
306
-    * Duplicates the current state of the image into a new
307
-    * image helper instance.
308
-    * 
309
-    * @return ImageHelper
310
-    */
305
+    /**
306
+     * Duplicates the current state of the image into a new
307
+     * image helper instance.
308
+     * 
309
+     * @return ImageHelper
310
+     */
311 311
     public function duplicate()
312 312
     {
313 313
         return ImageHelper::createFromResource($this->duplicateImage($this->newImage));
@@ -495,13 +495,13 @@  discard block
 block discarded – undo
495 495
         ));
496 496
     }
497 497
     
498
-   /**
499
-    * Resamples the image to a new width, maintaining
500
-    * aspect ratio.
501
-    * 
502
-    * @param int $width
503
-    * @return ImageHelper
504
-    */
498
+    /**
499
+     * Resamples the image to a new width, maintaining
500
+     * aspect ratio.
501
+     * 
502
+     * @param int $width
503
+     * @return ImageHelper
504
+     */
505 505
     public function resampleByWidth(int $width) : ImageHelper
506 506
     {
507 507
         $size = $this->getSizeByWidth($width);
@@ -511,12 +511,12 @@  discard block
 block discarded – undo
511 511
         return $this;
512 512
     }
513 513
 
514
-   /**
515
-    * Resamples the image by height, and creates a new image file on disk.
516
-    * 
517
-    * @param int $height
518
-    * @return ImageHelper
519
-    */
514
+    /**
515
+     * Resamples the image by height, and creates a new image file on disk.
516
+     * 
517
+     * @param int $height
518
+     * @return ImageHelper
519
+     */
520 520
     public function resampleByHeight($height) : ImageHelper
521 521
     {
522 522
         $size = $this->getSizeByHeight($height);
@@ -524,13 +524,13 @@  discard block
 block discarded – undo
524 524
         return $this->resampleImage($size->getWidth(), $size->getHeight());
525 525
     }
526 526
 
527
-   /**
528
-    * Resamples the image without keeping the aspect ratio.
529
-    * 
530
-    * @param int $width
531
-    * @param int $height
532
-    * @return ImageHelper
533
-    */
527
+    /**
528
+     * Resamples the image without keeping the aspect ratio.
529
+     * 
530
+     * @param int $width
531
+     * @param int $height
532
+     * @return ImageHelper
533
+     */
534 534
     public function resample(?int $width = null, ?int $height = null) : ImageHelper
535 535
     {
536 536
         if($this->isVector()) {
@@ -595,12 +595,12 @@  discard block
 block discarded – undo
595 595
     
596 596
     protected $alpha = false;
597 597
 
598
-   /**
599
-    * Configures the specified image resource to make it alpha compatible.
600
-    * 
601
-    * @param resource $canvas
602
-    * @param bool $fill Whether to fill the whole canvas with the transparency
603
-    */
598
+    /**
599
+     * Configures the specified image resource to make it alpha compatible.
600
+     * 
601
+     * @param resource $canvas
602
+     * @param bool $fill Whether to fill the whole canvas with the transparency
603
+     */
604 604
     public static function addAlphaSupport($canvas, $fill=true)
605 605
     {
606 606
         self::requireResource($canvas);
@@ -715,12 +715,12 @@  discard block
 block discarded – undo
715 715
         $this->quality = $quality * 1;
716 716
     }
717 717
 
718
-   /**
719
-    * Attempts to adjust the memory to the required size
720
-    * to work with the current image.
721
-    * 
722
-    * @return boolean
723
-    */
718
+    /**
719
+     * Attempts to adjust the memory to the required size
720
+     * to work with the current image.
721
+     * 
722
+     * @return boolean
723
+     */
724 724
     protected function adjustMemory() : bool
725 725
     {
726 726
         if(!self::$config['auto-memory-adjustment']) {
@@ -760,27 +760,27 @@  discard block
 block discarded – undo
760 760
         return false;
761 761
     }
762 762
 
763
-   /**
764
-    * Stretches the image to the specified dimensions.
765
-    * 
766
-    * @param int $width
767
-    * @param int $height
768
-    * @return ImageHelper
769
-    */
763
+    /**
764
+     * Stretches the image to the specified dimensions.
765
+     * 
766
+     * @param int $width
767
+     * @param int $height
768
+     * @return ImageHelper
769
+     */
770 770
     public function stretch(int $width, int $height) : ImageHelper
771 771
     {
772 772
         return $this->resampleImage($width, $height);
773 773
     }
774 774
 
775
-   /**
776
-    * Creates a new image from the current image,
777
-    * resampling it to the new size.
778
-    * 
779
-    * @param int $newWidth
780
-    * @param int $newHeight   
781
-    * @throws ImageHelper_Exception
782
-    * @return ImageHelper
783
-    */
775
+    /**
776
+     * Creates a new image from the current image,
777
+     * resampling it to the new size.
778
+     * 
779
+     * @param int $newWidth
780
+     * @param int $newHeight   
781
+     * @throws ImageHelper_Exception
782
+     * @return ImageHelper
783
+     */
784 784
     protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper
785 785
     {
786 786
         if($this->isVector()) {
@@ -849,17 +849,17 @@  discard block
 block discarded – undo
849 849
         return array_unique($types);
850 850
     }
851 851
     
852
-   /**
853
-    * Displays an existing image resource.
854
-    *
855
-    * @param resource $resource
856
-    * @param string $imageType The image format to send, i.e. "jpeg", "png"
857
-    * @param int $quality The quality to use for the image. This is 0-9 (0=no compression, 9=max) for PNG, and 0-100 (0=lowest, 100=highest quality) for JPG
858
-    *
859
-    * @throws ImageHelper_Exception
860
-    * @see ImageHelper::ERROR_NOT_A_RESOURCE
861
-    * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE
862
-    */
852
+    /**
853
+     * Displays an existing image resource.
854
+     *
855
+     * @param resource $resource
856
+     * @param string $imageType The image format to send, i.e. "jpeg", "png"
857
+     * @param int $quality The quality to use for the image. This is 0-9 (0=no compression, 9=max) for PNG, and 0-100 (0=lowest, 100=highest quality) for JPG
858
+     *
859
+     * @throws ImageHelper_Exception
860
+     * @see ImageHelper::ERROR_NOT_A_RESOURCE
861
+     * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE
862
+     */
863 863
     public static function displayImageStream($resource, string $imageType, int $quality=-1) : void
864 864
     {
865 865
         self::requireResource($resource);
@@ -942,11 +942,11 @@  discard block
 block discarded – undo
942 942
         readfile($imageFile);
943 943
     }
944 944
     
945
-   /**
946
-    * Displays the current image.
947
-    *
948
-    * NOTE: You must call `exit()` manually after this.
949
-    */
945
+    /**
946
+     * Displays the current image.
947
+     *
948
+     * NOTE: You must call `exit()` manually after this.
949
+     */
950 950
     public function display() : void
951 951
     {
952 952
         $this->displayImageStream(
@@ -970,16 +970,16 @@  discard block
 block discarded – undo
970 970
         return $this->trimImage($this->newImage, $color);
971 971
     }
972 972
     
973
-   /**
974
-    * Retrieves a color definition by its index.
975
-    * 
976
-    * @param resource $img A valid image resource.
977
-    * @param int $colorIndex The color index, as returned by `imagecolorat` for example.
978
-    * @return array<string,int> An array with red, green, blue and alpha keys.
979
-    *
980
-    * @throws ImageHelper_Exception
981
-    * @see ImageHelper::ERROR_NOT_A_RESOURCE
982
-    */
973
+    /**
974
+     * Retrieves a color definition by its index.
975
+     * 
976
+     * @param resource $img A valid image resource.
977
+     * @param int $colorIndex The color index, as returned by `imagecolorat` for example.
978
+     * @return array<string,int> An array with red, green, blue and alpha keys.
979
+     *
980
+     * @throws ImageHelper_Exception
981
+     * @see ImageHelper::ERROR_NOT_A_RESOURCE
982
+     */
983 983
     public function getIndexedColors($img, int $colorIndex) : array
984 984
     {
985 985
         self::requireResource($img);
@@ -999,18 +999,18 @@  discard block
 block discarded – undo
999 999
         );
1000 1000
     }
1001 1001
         
1002
-   /**
1003
-    * Trims the specified image resource by removing the specified color.
1004
-    * Also works with transparency.
1005
-    * 
1006
-    * @param resource $img
1007
-    * @param array|NULL $color A color definition, as an associative array with red, green, blue and alpha keys. If not specified, the color at pixel position 0,0 will be used.
1008
-    * @return ImageHelper
1009
-    *
1010
-    * @throws ImageHelper_Exception
1011
-    * @see ImageHelper::ERROR_NOT_A_RESOURCE
1012
-    * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS
1013
-    */
1002
+    /**
1003
+     * Trims the specified image resource by removing the specified color.
1004
+     * Also works with transparency.
1005
+     * 
1006
+     * @param resource $img
1007
+     * @param array|NULL $color A color definition, as an associative array with red, green, blue and alpha keys. If not specified, the color at pixel position 0,0 will be used.
1008
+     * @return ImageHelper
1009
+     *
1010
+     * @throws ImageHelper_Exception
1011
+     * @see ImageHelper::ERROR_NOT_A_RESOURCE
1012
+     * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS
1013
+     */
1014 1014
     protected function trimImage($img, ?array $color=null) : ImageHelper
1015 1015
     {
1016 1016
         if($this->isVector()) {
@@ -1118,14 +1118,14 @@  discard block
 block discarded – undo
1118 1118
         return $this;
1119 1119
     }
1120 1120
     
1121
-   /**
1122
-    * Requires the subject to be a resource.
1123
-    * 
1124
-    * @param resource|mixed $subject
1125
-    *
1126
-    * @throws ImageHelper_Exception
1127
-    * @see ImageHelper::ERROR_NOT_A_RESOURCE
1128
-    */
1121
+    /**
1122
+     * Requires the subject to be a resource.
1123
+     * 
1124
+     * @param resource|mixed $subject
1125
+     *
1126
+     * @throws ImageHelper_Exception
1127
+     * @see ImageHelper::ERROR_NOT_A_RESOURCE
1128
+     */
1129 1129
     protected static function requireResource($subject) : void
1130 1130
     {
1131 1131
         if(is_resource($subject)) {
@@ -1142,14 +1142,14 @@  discard block
 block discarded – undo
1142 1142
         );
1143 1143
     }
1144 1144
     
1145
-   /**
1146
-    * Creates a new image resource, with transparent background.
1147
-    * 
1148
-    * @param int $width
1149
-    * @param int $height
1150
-    * @throws ImageHelper_Exception
1151
-    * @return resource
1152
-    */
1145
+    /**
1146
+     * Creates a new image resource, with transparent background.
1147
+     * 
1148
+     * @param int $width
1149
+     * @param int $height
1150
+     * @throws ImageHelper_Exception
1151
+     * @return resource
1152
+     */
1153 1153
     protected function createNewImage(int $width, int $height)
1154 1154
     {
1155 1155
         $img = imagecreatetruecolor($width, $height);
@@ -1168,54 +1168,54 @@  discard block
 block discarded – undo
1168 1168
         return $img;
1169 1169
     }
1170 1170
     
1171
-   /**
1172
-    * Whether the two specified colors are the same.
1173
-    * 
1174
-    * @param array<string,int> $a
1175
-    * @param array<string,int> $b
1176
-    * @return boolean
1177
-    */
1178
-	protected function colorsMatch(array $a, array $b) : bool
1179
-	{
1180
-		$parts = array('red', 'green', 'blue');
1181
-		foreach($parts as $part) {
1182
-			if($a[$part] != $b[$part]) {
1183
-				return false;
1184
-			}
1185
-		} 
1171
+    /**
1172
+     * Whether the two specified colors are the same.
1173
+     * 
1174
+     * @param array<string,int> $a
1175
+     * @param array<string,int> $b
1176
+     * @return boolean
1177
+     */
1178
+    protected function colorsMatch(array $a, array $b) : bool
1179
+    {
1180
+        $parts = array('red', 'green', 'blue');
1181
+        foreach($parts as $part) {
1182
+            if($a[$part] != $b[$part]) {
1183
+                return false;
1184
+            }
1185
+        } 
1186 1186
 		
1187
-		return true;
1188
-	}
1187
+        return true;
1188
+    }
1189 1189
 	
1190
-	public function fillWhite($x=0, $y=0)
1191
-	{
1192
-	    $this->addRGBColor('white', 255, 255, 255);
1190
+    public function fillWhite($x=0, $y=0)
1191
+    {
1192
+        $this->addRGBColor('white', 255, 255, 255);
1193 1193
         return $this->fill('white', $x, $y);
1194
-	}
1194
+    }
1195 1195
 	
1196
-	public function fillTransparent() : ImageHelper
1197
-	{
1196
+    public function fillTransparent() : ImageHelper
1197
+    {
1198 1198
         $this->enableAlpha();
1199 1199
 	    
1200
-	    self::fillImageTransparent($this->newImage);
1200
+        self::fillImageTransparent($this->newImage);
1201 1201
 	    
1202
-	    return $this;
1203
-	}
1202
+        return $this;
1203
+    }
1204 1204
 	
1205
-	public static function fillImageTransparent($resource)
1206
-	{
1207
-	    self::requireResource($resource);
1205
+    public static function fillImageTransparent($resource)
1206
+    {
1207
+        self::requireResource($resource);
1208 1208
 	    
1209
-	    $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127);
1210
-	    imagecolortransparent ($resource, $transparent);
1211
-	    imagefill($resource, 0, 0, $transparent);
1212
-	}
1209
+        $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127);
1210
+        imagecolortransparent ($resource, $transparent);
1211
+        imagefill($resource, 0, 0, $transparent);
1212
+    }
1213 1213
 	
1214
-	public function fill($colorName, $x=0, $y=0)
1215
-	{
1216
-	    imagefill($this->newImage, $x, $y, $this->colors[$colorName]);
1217
-	    return $this;
1218
-	}
1214
+    public function fill($colorName, $x=0, $y=0)
1215
+    {
1216
+        imagefill($this->newImage, $x, $y, $this->colors[$colorName]);
1217
+        return $this;
1218
+    }
1219 1219
 	
1220 1220
     protected $colors = array();
1221 1221
 
@@ -1236,9 +1236,9 @@  discard block
 block discarded – undo
1236 1236
         return $this;
1237 1237
     }
1238 1238
     
1239
-   /**
1240
-    * @return resource
1241
-    */
1239
+    /**
1240
+     * @return resource
1241
+     */
1242 1242
     public function getImage()
1243 1243
     {
1244 1244
         return $this->newImage;
@@ -1256,26 +1256,26 @@  discard block
 block discarded – undo
1256 1256
         return $this;
1257 1257
     }
1258 1258
     
1259
-   /**
1260
-    * Retrieves the size of the image.
1261
-    * 
1262
-    * @return ImageHelper_Size
1263
-    * @throws ImageHelper_Exception
1264
-    * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE
1265
-    */
1266
-	public function getSize() : ImageHelper_Size
1259
+    /**
1260
+     * Retrieves the size of the image.
1261
+     * 
1262
+     * @return ImageHelper_Size
1263
+     * @throws ImageHelper_Exception
1264
+     * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE
1265
+     */
1266
+    public function getSize() : ImageHelper_Size
1267 1267
     {
1268
-	    return self::getImageSize($this->newImage);
1268
+        return self::getImageSize($this->newImage);
1269 1269
     }
1270 1270
     
1271 1271
     protected $TTFFile;
1272 1272
     
1273
-   /**
1274
-    * Sets the TTF font file to use for text operations.
1275
-    * 
1276
-    * @param string $filePath
1277
-    * @return ImageHelper
1278
-    */
1273
+    /**
1274
+     * Sets the TTF font file to use for text operations.
1275
+     * 
1276
+     * @param string $filePath
1277
+     * @return ImageHelper
1278
+     */
1279 1279
     public function setFontTTF($filePath)
1280 1280
     {
1281 1281
         $this->TTFFile = $filePath;
@@ -1347,63 +1347,63 @@  discard block
 block discarded – undo
1347 1347
             return;
1348 1348
         }
1349 1349
         
1350
-	    throw new ImageHelper_Exception(
1350
+        throw new ImageHelper_Exception(
1351 1351
             'No true type font specified',
1352 1352
             'This functionality requires a TTF font file to be specified with the [setFontTTF] method.',
1353 1353
             self::ERROR_NO_TRUE_TYPE_FONT_SET    
1354 1354
         );
1355 1355
     }
1356 1356
     
1357
-   /**
1358
-	 * Retrieves the size of an image file on disk, or
1359
-	 * an existing image resource.
1360
-	 *
1361
-	 * <pre>
1362
-	 * array(
1363
-	 *     0: (width),
1364
-	 *     1: (height),
1365
-	 *     "channels": the amount of channels
1366
-	 *     "bits": bits per channel
1357
+    /**
1358
+     * Retrieves the size of an image file on disk, or
1359
+     * an existing image resource.
1360
+     *
1361
+     * <pre>
1362
+     * array(
1363
+     *     0: (width),
1364
+     *     1: (height),
1365
+     *     "channels": the amount of channels
1366
+     *     "bits": bits per channel
1367 1367
      * )     
1368
-	 * </pre>
1369
-	 *
1370
-	 * @param string|resource $pathOrResource
1371
-	 * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize
1372
-	 * @see ImageHelper_Size
1373
-	 * @throws ImageHelper_Exception
1374
-	 * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE
1375
-	 * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE
1376
-	 * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING
1377
-	 * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID
1378
-	 */
1379
-	public static function getImageSize($pathOrResource) : ImageHelper_Size
1380
-	{
1381
-	    if(is_resource($pathOrResource)) 
1382
-	    {
1383
-	        return new ImageHelper_Size(array(
1384
-	            'width' => imagesx($pathOrResource),
1385
-	            'height' => imagesy($pathOrResource),
1386
-	            'channels' => 1,
1387
-	            'bits' => 8
1388
-	        ));
1389
-	    }
1368
+     * </pre>
1369
+     *
1370
+     * @param string|resource $pathOrResource
1371
+     * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize
1372
+     * @see ImageHelper_Size
1373
+     * @throws ImageHelper_Exception
1374
+     * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE
1375
+     * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE
1376
+     * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING
1377
+     * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID
1378
+     */
1379
+    public static function getImageSize($pathOrResource) : ImageHelper_Size
1380
+    {
1381
+        if(is_resource($pathOrResource)) 
1382
+        {
1383
+            return new ImageHelper_Size(array(
1384
+                'width' => imagesx($pathOrResource),
1385
+                'height' => imagesy($pathOrResource),
1386
+                'channels' => 1,
1387
+                'bits' => 8
1388
+            ));
1389
+        }
1390 1390
 	    
1391
-	    $type = self::getFileImageType($pathOrResource);
1391
+        $type = self::getFileImageType($pathOrResource);
1392 1392
 	    
1393
-	    $info = false;
1394
-	    $method = 'getImageSize_'.$type;
1395
-	    if(method_exists(__CLASS__, $method)) 
1396
-	    {
1397
-	        $info = call_user_func(array(__CLASS__, $method), $pathOrResource);
1398
-	    } 
1399
-	    else 
1400
-	    {
1401
-	        $info = getimagesize($pathOrResource);
1402
-	    }
1393
+        $info = false;
1394
+        $method = 'getImageSize_'.$type;
1395
+        if(method_exists(__CLASS__, $method)) 
1396
+        {
1397
+            $info = call_user_func(array(__CLASS__, $method), $pathOrResource);
1398
+        } 
1399
+        else 
1400
+        {
1401
+            $info = getimagesize($pathOrResource);
1402
+        }
1403 1403
 	    
1404
-	    if($info !== false) {
1405
-	        return new ImageHelper_Size($info);
1406
-	    }
1404
+        if($info !== false) {
1405
+            return new ImageHelper_Size($info);
1406
+        }
1407 1407
 	    
1408 1408
         throw new ImageHelper_Exception(
1409 1409
             'Error opening image file',
@@ -1413,98 +1413,98 @@  discard block
 block discarded – undo
1413 1413
             ),
1414 1414
             self::ERROR_CANNOT_GET_IMAGE_SIZE
1415 1415
         );
1416
-	}
1416
+    }
1417 1417
 	
1418
-   /**
1419
-    * @param string $imagePath
1420
-    * @throws ImageHelper_Exception
1421
-    * @return array
1422
-    * 
1423
-    * @todo This should return a ImageHelper_Size instance.
1424
-    */
1425
-	protected static function getImageSize_svg(string $imagePath) : array
1426
-	{
1427
-	    $xml = XMLHelper::createSimplexml();
1428
-	    $xml->loadFile($imagePath);
1418
+    /**
1419
+     * @param string $imagePath
1420
+     * @throws ImageHelper_Exception
1421
+     * @return array
1422
+     * 
1423
+     * @todo This should return a ImageHelper_Size instance.
1424
+     */
1425
+    protected static function getImageSize_svg(string $imagePath) : array
1426
+    {
1427
+        $xml = XMLHelper::createSimplexml();
1428
+        $xml->loadFile($imagePath);
1429 1429
 	    
1430
-	    if($xml->hasErrors()) {
1431
-	        throw new ImageHelper_Exception(
1432
-	            'Error opening SVG image',
1433
-	            sprintf(
1434
-	                'The XML content of the image [%s] could not be parsed.',
1435
-	                $imagePath
1430
+        if($xml->hasErrors()) {
1431
+            throw new ImageHelper_Exception(
1432
+                'Error opening SVG image',
1433
+                sprintf(
1434
+                    'The XML content of the image [%s] could not be parsed.',
1435
+                    $imagePath
1436 1436
                 ),
1437
-	            self::ERROR_CANNOT_READ_SVG_IMAGE
1437
+                self::ERROR_CANNOT_READ_SVG_IMAGE
1438 1438
             );
1439
-	    }
1439
+        }
1440 1440
 	    
1441
-	    $data = $xml->toArray();
1442
-	    $xml->dispose();
1443
-	    unset($xml);
1441
+        $data = $xml->toArray();
1442
+        $xml->dispose();
1443
+        unset($xml);
1444 1444
 	    
1445
-	    if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) {
1446
-	        throw new ImageHelper_Exception(
1447
-	            'SVG Image is corrupted',
1448
-	            sprintf(
1449
-	                'The [viewBox] attribute is missing in the XML of the image at path [%s].',
1450
-	                $imagePath
1445
+        if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) {
1446
+            throw new ImageHelper_Exception(
1447
+                'SVG Image is corrupted',
1448
+                sprintf(
1449
+                    'The [viewBox] attribute is missing in the XML of the image at path [%s].',
1450
+                    $imagePath
1451 1451
                 ),
1452
-	            self::ERROR_SVG_SOURCE_VIEWBOX_MISSING
1452
+                self::ERROR_SVG_SOURCE_VIEWBOX_MISSING
1453 1453
             );
1454
-	    }
1454
+        }
1455 1455
 	    
1456
-	    $svgWidth = parseNumber($data['@attributes']['width'])->getNumber();
1457
-	    $svgHeight = parseNumber($data['@attributes']['height'])->getNumber();
1456
+        $svgWidth = parseNumber($data['@attributes']['width'])->getNumber();
1457
+        $svgHeight = parseNumber($data['@attributes']['height'])->getNumber();
1458 1458
 	    
1459
-	    $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']);
1460
-	    $size = explode(',', $viewBox);
1459
+        $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']);
1460
+        $size = explode(',', $viewBox);
1461 1461
 	    
1462
-	    if(count($size) != 4) 
1463
-	    {
1464
-	        throw new ImageHelper_Exception(
1465
-	            'SVG image has an invalid viewBox attribute',
1466
-	            sprintf(
1467
-	               'The [viewBox] attribute does not have an expected value: [%s] in path [%s].',
1468
-	                $viewBox,
1469
-	                $imagePath
1462
+        if(count($size) != 4) 
1463
+        {
1464
+            throw new ImageHelper_Exception(
1465
+                'SVG image has an invalid viewBox attribute',
1466
+                sprintf(
1467
+                    'The [viewBox] attribute does not have an expected value: [%s] in path [%s].',
1468
+                    $viewBox,
1469
+                    $imagePath
1470 1470
                 ),
1471
-	            self::ERROR_SVG_VIEWBOX_INVALID
1471
+                self::ERROR_SVG_VIEWBOX_INVALID
1472 1472
             );
1473
-	    }
1473
+        }
1474 1474
 	    
1475
-	    $boxWidth = (float)$size[2];
1476
-	    $boxHeight = (float)$size[3];
1475
+        $boxWidth = (float)$size[2];
1476
+        $boxHeight = (float)$size[3];
1477 1477
 	    
1478
-	    // calculate the x and y units of the document: 
1479
-	    // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox
1480
-	    //
1481
-	    // The viewbox combined with the width and heigt of the svg
1482
-	    // allow calculating how many pixels are in one unit of the 
1483
-	    // width and height of the document.
1478
+        // calculate the x and y units of the document: 
1479
+        // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox
1480
+        //
1481
+        // The viewbox combined with the width and heigt of the svg
1482
+        // allow calculating how many pixels are in one unit of the 
1483
+        // width and height of the document.
1484 1484
         //
1485
-	    $xUnits = $svgWidth / $boxWidth;
1486
-	    $yUnits = $svgHeight / $boxHeight;
1485
+        $xUnits = $svgWidth / $boxWidth;
1486
+        $yUnits = $svgHeight / $boxHeight;
1487 1487
 	    
1488
-	    $pxWidth = $xUnits * $svgWidth;
1489
-	    $pxHeight = $yUnits * $svgHeight;
1488
+        $pxWidth = $xUnits * $svgWidth;
1489
+        $pxHeight = $yUnits * $svgHeight;
1490 1490
 	    
1491
-	    return array(
1492
-	        $pxWidth,
1493
-	        $pxHeight,
1494
-	        'bits' => 8
1495
-	    );
1496
-	}
1491
+        return array(
1492
+            $pxWidth,
1493
+            $pxHeight,
1494
+            'bits' => 8
1495
+        );
1496
+    }
1497 1497
 	
1498
-	/**
1499
-    * Crops the image to the specified width and height, optionally
1500
-    * specifying the origin position to crop from.
1501
-    * 
1502
-    * @param integer $width
1503
-    * @param integer $height
1504
-    * @param integer $x
1505
-    * @param integer $y
1506
-    * @return ImageHelper
1507
-    */
1498
+    /**
1499
+     * Crops the image to the specified width and height, optionally
1500
+     * specifying the origin position to crop from.
1501
+     * 
1502
+     * @param integer $width
1503
+     * @param integer $height
1504
+     * @param integer $x
1505
+     * @param integer $y
1506
+     * @return ImageHelper
1507
+     */
1508 1508
     public function crop(int $width, int $height, int $x=0, int $y=0) : ImageHelper
1509 1509
     {
1510 1510
         $new = $this->createNewImage($width, $height);
@@ -1526,22 +1526,22 @@  discard block
 block discarded – undo
1526 1526
         return $this->newHeight;
1527 1527
     }
1528 1528
 
1529
-   /**
1530
-    * Calculates the average color value used in 
1531
-    * the image. Returns an associative array
1532
-    * with the red, green, blue and alpha components,
1533
-    * or a HEX color string depending on the selected
1534
-    * format.
1535
-    * 
1536
-    * NOTE: Use the calcAverageColorXXX methods for
1537
-    * strict return types. 
1538
-    * 
1539
-    * @param int $format The format in which to return the color value.
1540
-    * @return array|string
1541
-    * 
1542
-    * @see ImageHelper::calcAverageColorRGB()
1543
-    * @see ImageHelper::calcAverageColorHEX()
1544
-    */
1529
+    /**
1530
+     * Calculates the average color value used in 
1531
+     * the image. Returns an associative array
1532
+     * with the red, green, blue and alpha components,
1533
+     * or a HEX color string depending on the selected
1534
+     * format.
1535
+     * 
1536
+     * NOTE: Use the calcAverageColorXXX methods for
1537
+     * strict return types. 
1538
+     * 
1539
+     * @param int $format The format in which to return the color value.
1540
+     * @return array|string
1541
+     * 
1542
+     * @see ImageHelper::calcAverageColorRGB()
1543
+     * @see ImageHelper::calcAverageColorHEX()
1544
+     */
1545 1545
     public function calcAverageColor(int $format=self::COLORFORMAT_RGB)
1546 1546
     {
1547 1547
         $image = $this->duplicate();
@@ -1550,35 +1550,35 @@  discard block
 block discarded – undo
1550 1550
         return $image->getColorAt(0, 0, $format);
1551 1551
     }
1552 1552
     
1553
-   /**
1554
-    * Calculates the image's average color value, and
1555
-    * returns an associative array with red, green,
1556
-    * blue and alpha keys.
1557
-    * 
1558
-    * @throws ImageHelper_Exception
1559
-    * @return array
1560
-    */
1553
+    /**
1554
+     * Calculates the image's average color value, and
1555
+     * returns an associative array with red, green,
1556
+     * blue and alpha keys.
1557
+     * 
1558
+     * @throws ImageHelper_Exception
1559
+     * @return array
1560
+     */
1561 1561
     public function calcAverageColorRGB() : array
1562 1562
     {
1563
-       $result = $this->calcAverageColor(self::COLORFORMAT_RGB);
1564
-       if(is_array($result)) {
1565
-           return $result;
1566
-       }
1563
+        $result = $this->calcAverageColor(self::COLORFORMAT_RGB);
1564
+        if(is_array($result)) {
1565
+            return $result;
1566
+        }
1567 1567
        
1568
-       throw new ImageHelper_Exception(
1569
-           'Unexpected color value',
1570
-           sprintf('Expected an array, got [%s].', gettype($result)),
1571
-           self::ERROR_UNEXPECTED_COLOR_VALUE
1572
-       );
1568
+        throw new ImageHelper_Exception(
1569
+            'Unexpected color value',
1570
+            sprintf('Expected an array, got [%s].', gettype($result)),
1571
+            self::ERROR_UNEXPECTED_COLOR_VALUE
1572
+        );
1573 1573
     }
1574 1574
     
1575
-   /**
1576
-    * Calculates the image's average color value, and
1577
-    * returns a hex color string (without the #).
1578
-    * 
1579
-    * @throws ImageHelper_Exception
1580
-    * @return string
1581
-    */
1575
+    /**
1576
+     * Calculates the image's average color value, and
1577
+     * returns a hex color string (without the #).
1578
+     * 
1579
+     * @throws ImageHelper_Exception
1580
+     * @return string
1581
+     */
1582 1582
     public function calcAverageColorHex() : string
1583 1583
     {
1584 1584
         $result = $this->calcAverageColor(self::COLORFORMAT_HEX);
@@ -1645,12 +1645,12 @@  discard block
 block discarded – undo
1645 1645
         return $rgb;
1646 1646
     }
1647 1647
     
1648
-   /**
1649
-    * Converts an RGB value to its luminance equivalent.
1650
-    * 
1651
-    * @param array<string,int> $rgb
1652
-    * @return integer Integer, from 0 to 255 (0=black, 255=white)
1653
-    */
1648
+    /**
1649
+     * Converts an RGB value to its luminance equivalent.
1650
+     * 
1651
+     * @param array<string,int> $rgb
1652
+     * @return integer Integer, from 0 to 255 (0=black, 255=white)
1653
+     */
1654 1654
     public static function rgb2luma(array $rgb) : int
1655 1655
     {
1656 1656
         return (int)floor((($rgb['red']*2)+$rgb['blue']+($rgb['green']*3))/6);
@@ -1670,15 +1670,15 @@  discard block
 block discarded – undo
1670 1670
         return $luma * 100 / 255;
1671 1671
     }
1672 1672
     
1673
-   /**
1674
-    * Retrieves an md5 hash of the source image file.
1675
-    * 
1676
-    * NOTE: Only works when the helper has been created
1677
-    * from a file. Otherwise, an exception is thrown.
1678
-    * 
1679
-    * @return string
1680
-    * @throws ImageHelper_Exception|OutputBuffering_Exception
1681
-    */
1673
+    /**
1674
+     * Retrieves an md5 hash of the source image file.
1675
+     * 
1676
+     * NOTE: Only works when the helper has been created
1677
+     * from a file. Otherwise, an exception is thrown.
1678
+     * 
1679
+     * @return string
1680
+     * @throws ImageHelper_Exception|OutputBuffering_Exception
1681
+     */
1682 1682
     public function getHash() : string
1683 1683
     {
1684 1684
         if($this->newImage === null)
Please login to merge, or discard this patch.
src/NumberInfo.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -40,19 +40,19 @@  discard block
 block discarded – undo
40 40
  */
41 41
 class NumberInfo
42 42
 {
43
-   /**
44
-    * @var string|int|float|null
45
-    */
43
+    /**
44
+     * @var string|int|float|null
45
+     */
46 46
     protected $rawValue;
47 47
     
48
-   /**
49
-    * @var array<string,mixed>
50
-    */
48
+    /**
49
+     * @var array<string,mixed>
50
+     */
51 51
     protected array $info;
52 52
     
53
-   /**
54
-    * @var bool
55
-    */
53
+    /**
54
+     * @var bool
55
+     */
56 56
     protected bool $empty = false;
57 57
 
58 58
     /**
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 
63 63
     /**
64 64
      * Units and whether they allow decimal values.
65
-    * @var array<string,bool>
66
-    */
65
+     * @var array<string,bool>
66
+     */
67 67
     protected array $knownUnits = array(
68 68
         '%' => true,
69 69
         'rem' => true,
@@ -141,21 +141,21 @@  discard block
 block discarded – undo
141 141
         return $this;
142 142
     }
143 143
     
144
-   /**
145
-    * Retrieves the raw, internal information array resulting
146
-    * from the parsing of the number.
147
-    *  
148
-    * @return array<string,mixed>
149
-    */
144
+    /**
145
+     * Retrieves the raw, internal information array resulting
146
+     * from the parsing of the number.
147
+     *  
148
+     * @return array<string,mixed>
149
+     */
150 150
     public function getRawInfo() : array
151 151
     {
152 152
         return $this->info;
153 153
     }
154 154
     
155
-   /**
156
-    * Whether the number was empty (null or empty string).
157
-    * @return boolean
158
-    */
155
+    /**
156
+     * Whether the number was empty (null or empty string).
157
+     * @return boolean
158
+     */
159 159
     public function isEmpty() : bool
160 160
     {
161 161
         return $this->empty;
@@ -729,12 +729,12 @@  discard block
 block discarded – undo
729 729
         return $cache[$key];
730 730
     }
731 731
     
732
-   /**
733
-    * Parses a string number notation with units included, e.g. 14px, 50%...
734
-    * 
735
-    * @param string $test
736
-    * @return array<string,mixed>
737
-    */
732
+    /**
733
+     * Parses a string number notation with units included, e.g. 14px, 50%...
734
+     * 
735
+     * @param string $test
736
+     * @return array<string,mixed>
737
+     */
738 738
     private function parseStringValue(string $test) : array
739 739
     {
740 740
         $number = null;
@@ -785,13 +785,13 @@  discard block
 block discarded – undo
785 785
         return $this->filterInfo($result);
786 786
     }
787 787
     
788
-   /**
789
-    * Attempts to determine what kind of units are specified
790
-    * in the string. Returns NULL if none could be matched.
791
-    * 
792
-    * @param string $value
793
-    * @return array<string,mixed>|NULL
794
-    */
788
+    /**
789
+     * Attempts to determine what kind of units are specified
790
+     * in the string. Returns NULL if none could be matched.
791
+     * 
792
+     * @param string $value
793
+     * @return array<string,mixed>|NULL
794
+     */
795 795
     private function findUnits(string $value) : ?array
796 796
     {
797 797
         $vlength = strlen($value);
@@ -819,12 +819,12 @@  discard block
 block discarded – undo
819 819
         return null;
820 820
     }
821 821
     
822
-   /**
823
-    * Creates the cache key for the specified value.
824
-    * 
825
-    * @param mixed $value
826
-    * @return string
827
-    */
822
+    /**
823
+     * Creates the cache key for the specified value.
824
+     * 
825
+     * @param mixed $value
826
+     * @return string
827
+     */
828 828
     private function createValueKey($value) : string
829 829
     {
830 830
         if(!is_string($value) && !is_numeric($value))
@@ -835,59 +835,59 @@  discard block
 block discarded – undo
835 835
         return (string)$value;
836 836
     }
837 837
 
838
-   /**
839
-    * Called if explicitly enabled: allows filtering the 
840
-    * number after the detection process has completed.
841
-    * 
842
-    * @param string|NULL $number The adjusted number
843
-    * @param string $originalString The original value before it was parsed
844
-    * @return string|null
845
-    */
838
+    /**
839
+     * Called if explicitly enabled: allows filtering the 
840
+     * number after the detection process has completed.
841
+     * 
842
+     * @param string|NULL $number The adjusted number
843
+     * @param string $originalString The original value before it was parsed
844
+     * @return string|null
845
+     */
846 846
     protected function postProcess(?string $number, /** @scrutinizer ignore-unused */ string $originalString)
847 847
     {
848 848
         return $number;
849 849
     }
850 850
     
851
-   /**
852
-    * Filters the value before it is parsed, but only if it is a string.
853
-    * 
854
-    * NOTE: This may be overwritten in a subclass, to allow custom filtering
855
-    * the values. An example of a use case would be a preprocessor for
856
-    * variables in a templating system.
857
-    * 
858
-    * @param string $trimmedString The trimmed value.
859
-    * @param array<string,mixed> $cache The internal values cache array.
860
-    * @param string $originalValue The original value that the NumberInfo was created for.
861
-    * @return string
862
-    * 
863
-    * @see NumberInfo::enablePostProcess()
864
-    */
851
+    /**
852
+     * Filters the value before it is parsed, but only if it is a string.
853
+     * 
854
+     * NOTE: This may be overwritten in a subclass, to allow custom filtering
855
+     * the values. An example of a use case would be a preprocessor for
856
+     * variables in a templating system.
857
+     * 
858
+     * @param string $trimmedString The trimmed value.
859
+     * @param array<string,mixed> $cache The internal values cache array.
860
+     * @param string $originalValue The original value that the NumberInfo was created for.
861
+     * @return string
862
+     * 
863
+     * @see NumberInfo::enablePostProcess()
864
+     */
865 865
     protected function preProcess(string $trimmedString, /** @scrutinizer ignore-unused */ array &$cache, /** @scrutinizer ignore-unused */ string $originalValue) : string
866 866
     {
867 867
         return str_replace(',', '.', $trimmedString);
868 868
     }
869 869
     
870
-   /**
871
-    * Enables the post-processing so the postProcess method gets called.
872
-    * This should be called in the {@link NumberInfo::preProcess()}
873
-    * method as needed.
874
-    * 
875
-    * @return $this
876
-    * @see NumberInfo::postProcess()
877
-    */
870
+    /**
871
+     * Enables the post-processing so the postProcess method gets called.
872
+     * This should be called in the {@link NumberInfo::preProcess()}
873
+     * method as needed.
874
+     * 
875
+     * @return $this
876
+     * @see NumberInfo::postProcess()
877
+     */
878 878
     protected function enablePostProcess() : NumberInfo
879 879
     {
880 880
         $this->postProcess = true;
881 881
         return $this;
882 882
     }
883 883
     
884
-   /**
885
-    * Filters the number info array to adjust the units
886
-    * and number according to the required rules.
887
-    * 
888
-    * @param array<string,mixed> $info
889
-    * @return array<string,mixed>
890
-    */
884
+    /**
885
+     * Filters the number info array to adjust the units
886
+     * and number according to the required rules.
887
+     * 
888
+     * @param array<string,mixed> $info
889
+     * @return array<string,mixed>
890
+     */
891 891
     protected function filterInfo(array $info) : array
892 892
     {
893 893
         $useUnits = 'px';
Please login to merge, or discard this patch.
src/Request/URLComparer.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -23,44 +23,44 @@
 block discarded – undo
23 23
  */
24 24
 class Request_URLComparer
25 25
 {
26
-   /**
27
-    * @var Request
28
-    */
26
+    /**
27
+     * @var Request
28
+     */
29 29
     protected Request $request;
30 30
     
31
-   /**
32
-    * @var string
33
-    */
31
+    /**
32
+     * @var string
33
+     */
34 34
     protected string $sourceURL;
35 35
     
36
-   /**
37
-    * @var string
38
-    */
36
+    /**
37
+     * @var string
38
+     */
39 39
     protected string $targetURL;
40 40
     
41
-   /**
42
-    * @var string[]
43
-    */
41
+    /**
42
+     * @var string[]
43
+     */
44 44
     protected array $limitParams = array();
45 45
     
46
-   /**
47
-    * @var bool
48
-    */
46
+    /**
47
+     * @var bool
48
+     */
49 49
     protected bool $isMatch = false;
50 50
     
51
-   /**
52
-    * @var bool
53
-    */
51
+    /**
52
+     * @var bool
53
+     */
54 54
     protected bool $ignoreFragment = true;
55 55
 
56
-   /**
57
-    * @var URLInfo
58
-    */
56
+    /**
57
+     * @var URLInfo
58
+     */
59 59
     protected URLInfo $sourceInfo;
60 60
     
61
-   /**
62
-    * @var URLInfo
63
-    */
61
+    /**
62
+     * @var URLInfo
63
+     */
64 64
     protected URLInfo $targetInfo;
65 65
     
66 66
     public function __construct(Request $request, string $sourceURL, string $targetURL)
Please login to merge, or discard this patch.
src/SVNHelper.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -23,101 +23,101 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class SVNHelper
25 25
 {
26
-   /**
27
-    * @var integer
28
-    */
26
+    /**
27
+     * @var integer
28
+     */
29 29
     public const ERROR_LOCAL_PATH_DOES_NOT_EXIST = 22401;
30 30
     
31
-   /**
32
-    * @var integer
33
-    */
31
+    /**
32
+     * @var integer
33
+     */
34 34
     public const ERROR_INVALID_REP_URL = 22402;
35 35
     
36
-   /**
37
-    * @var integer
38
-    */
36
+    /**
37
+     * @var integer
38
+     */
39 39
     public const ERROR_PATH_IS_OUTSIDE_REPOSITORY = 22403;
40 40
     
41
-   /**
42
-    * @var integer
43
-    */
41
+    /**
42
+     * @var integer
43
+     */
44 44
     public const ERROR_TARGET_FOLDER_IS_A_FILE = 22404;
45 45
     
46
-   /**
47
-    * @var integer
48
-    */
46
+    /**
47
+     * @var integer
48
+     */
49 49
     public const ERROR_CANNOT_ADD_INEXISTENT_FILE = 22405;
50 50
     
51
-   /**
52
-    * @var integer
53
-    */
51
+    /**
52
+     * @var integer
53
+     */
54 54
     public const ERROR_TARGET_PATH_NOT_FOUND = 22406;
55 55
     
56
-   /**
57
-    * @var integer
58
-    */
56
+    /**
57
+     * @var integer
58
+     */
59 59
     public const ERROR_INVALID_TARGET_TYPE = 22407;
60 60
     
61
-   /**
62
-    * @var integer
63
-    */
61
+    /**
62
+     * @var integer
63
+     */
64 64
     public const ERROR_INVALID_LOG_CALLBACK = 22408; 
65 65
     
66
-   /**
67
-    * @var SVNHelper_Target_Folder
68
-    */
66
+    /**
67
+     * @var SVNHelper_Target_Folder
68
+     */
69 69
     protected $target;
70 70
     
71
-   /**
72
-    * @var string
73
-    */
71
+    /**
72
+     * @var string
73
+     */
74 74
     protected $path;
75 75
     
76
-   /**
77
-    * @var string
78
-    */
76
+    /**
77
+     * @var string
78
+     */
79 79
     protected $url;
80 80
     
81
-   /**
82
-    * @var string
83
-    */
81
+    /**
82
+     * @var string
83
+     */
84 84
     protected $user;
85 85
     
86
-   /**
87
-    * @var string
88
-    */
86
+    /**
87
+     * @var string
88
+     */
89 89
     protected $pass;
90 90
     
91
-   /**
92
-    * @var array
93
-    */
91
+    /**
92
+     * @var array
93
+     */
94 94
     protected $options = array(
95 95
         'binaries-path' => ''
96 96
     );
97 97
     
98
-   /**
99
-    * @var boolean
100
-    */
98
+    /**
99
+     * @var boolean
100
+     */
101 101
     protected $isWindows = false;
102 102
     
103
-   /**
104
-    * @var array
105
-    */
103
+    /**
104
+     * @var array
105
+     */
106 106
     protected $normalize = array(
107 107
         'from' => '\\',
108 108
         'to' => '/'
109 109
     );
110 110
     
111
-   /**
112
-    * @var string
113
-    */
111
+    /**
112
+     * @var string
113
+     */
114 114
     protected $sourcePath;
115 115
     
116
-   /**
117
-    * @param string $repPath The path to the repository
118
-    * @param string $repURL The SVN URL to the repository
119
-    * @throws SVNHelper_Exception
120
-    */
116
+    /**
117
+     * @param string $repPath The path to the repository
118
+     * @param string $repURL The SVN URL to the repository
119
+     * @throws SVNHelper_Exception
120
+     */
121 121
     public function __construct(string $repPath, string $repURL)
122 122
     {
123 123
         $this->isWindows = substr(PHP_OS, 0, 3) == 'WIN';
@@ -178,16 +178,16 @@  discard block
 block discarded – undo
178 178
         return $this->pass;
179 179
     }
180 180
     
181
-   /**
182
-    * Normalizes slashes in the path according to the
183
-    * operating system, i.e. forward slashes for NIX-systems
184
-    * and backward slashes for Windows.
185
-    *
186
-    * @param string $path An absolute path to normalize
187
-    * @param bool $relativize Whether to return a path relative to the repository
188
-    * @throws SVNHelper_Exception
189
-    * @return string
190
-    */
181
+    /**
182
+     * Normalizes slashes in the path according to the
183
+     * operating system, i.e. forward slashes for NIX-systems
184
+     * and backward slashes for Windows.
185
+     *
186
+     * @param string $path An absolute path to normalize
187
+     * @param bool $relativize Whether to return a path relative to the repository
188
+     * @throws SVNHelper_Exception
189
+     * @return string
190
+     */
191 191
     public function normalizePath($path, $relativize=false)
192 192
     {
193 193
         if(empty($path)) {
@@ -222,32 +222,32 @@  discard block
 block discarded – undo
222 222
         );
223 223
     }
224 224
     
225
-   /**
226
-    * Retrieves the path slash style according to the
227
-    * current operating system.
228
-    * 
229
-    * @return string
230
-    */
225
+    /**
226
+     * Retrieves the path slash style according to the
227
+     * current operating system.
228
+     * 
229
+     * @return string
230
+     */
231 231
     public function getSlash()
232 232
     {
233 233
         return $this->normalize['to'];
234 234
     }
235 235
     
236
-   /**
237
-    * Keeps instances of files.
238
-    * @var SVNHelper_Target[]
239
-    */
236
+    /**
237
+     * Keeps instances of files.
238
+     * @var SVNHelper_Target[]
239
+     */
240 240
     protected $targets = array();
241 241
     
242
-   /**
243
-    * Retrieves a file instance from the SVN repository:
244
-    * this allows all possible operations on the file as
245
-    * well as accessing more information on it.
246
-    * 
247
-    * @param string $path A path to the file, relative to the repository path or absolute.
248
-    * @return SVNHelper_Target_File
249
-    * @throws SVNHelper_Exception
250
-    */
242
+    /**
243
+     * Retrieves a file instance from the SVN repository:
244
+     * this allows all possible operations on the file as
245
+     * well as accessing more information on it.
246
+     * 
247
+     * @param string $path A path to the file, relative to the repository path or absolute.
248
+     * @return SVNHelper_Target_File
249
+     * @throws SVNHelper_Exception
250
+     */
251 251
     public function getFile(string $path) : SVNHelper_Target_File
252 252
     {
253 253
         $path = $this->filterPath($path);
@@ -256,15 +256,15 @@  discard block
 block discarded – undo
256 256
             ->requireIsFile();
257 257
     }
258 258
 
259
-   /**
260
-    * Retrieves a folder instance from the SVN repository:
261
-    * This allows all possible operations on the folder as
262
-    * well as accessing more information on it.
263
-    * 
264
-    * @param string $path
265
-    * @return SVNHelper_Target_Folder
266
-    * @throws SVNHelper_Exception
267
-    */
259
+    /**
260
+     * Retrieves a folder instance from the SVN repository:
261
+     * This allows all possible operations on the folder as
262
+     * well as accessing more information on it.
263
+     * 
264
+     * @param string $path
265
+     * @return SVNHelper_Target_Folder
266
+     * @throws SVNHelper_Exception
267
+     */
268 268
     public function getFolder(string $path) : SVNHelper_Target_Folder
269 269
     {
270 270
         $path = $this->filterPath($path);
@@ -273,13 +273,13 @@  discard block
 block discarded – undo
273 273
             ->requireIsFolder();
274 274
     }
275 275
     
276
-   /**
277
-    * Passes the path through realpath and ensures it exists.
278
-    *
279
-    * @param string $path
280
-    * @throws SVNHelper_Exception
281
-    * @return string
282
-    */
276
+    /**
277
+     * Passes the path through realpath and ensures it exists.
278
+     *
279
+     * @param string $path
280
+     * @throws SVNHelper_Exception
281
+     * @return string
282
+     */
283 283
     protected function filterPath($path)
284 284
     {
285 285
         if(empty($path)) {
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
         );
305 305
     }
306 306
     
307
-   /**
308
-    * Retrieves a target file or folder within the repository.
309
-    *
310
-    * @param string $type The target type, "File" or "Folder".
311
-    * @param string $relativePath A path relative to the root folder.
312
-    * @return SVNHelper_Target
313
-    */
307
+    /**
308
+     * Retrieves a target file or folder within the repository.
309
+     *
310
+     * @param string $type The target type, "File" or "Folder".
311
+     * @param string $relativePath A path relative to the root folder.
312
+     * @return SVNHelper_Target
313
+     */
314 314
     protected function getTarget(string $type, string $relativePath) : SVNHelper_Target
315 315
     {
316 316
         $key = $type.':'.$relativePath;
@@ -358,33 +358,33 @@  discard block
 block discarded – undo
358 358
         return $this->url;
359 359
     }
360 360
     
361
-   /**
362
-    * Updates the whole SVN repository from the root folder.
363
-    * @return SVNHelper_CommandResult
364
-    */
361
+    /**
362
+     * Updates the whole SVN repository from the root folder.
363
+     * @return SVNHelper_CommandResult
364
+     */
365 365
     public function runUpdate()
366 366
     {
367 367
         return $this->createUpdate($this->target)->execute();
368 368
     }
369 369
     
370
-   /**
371
-    * Creates an update command for the target file or folder.
372
-    * This can be configured further before it is executed.
373
-    * 
374
-    * @param SVNHelper_Target $target
375
-    * @return SVNHelper_Command_Update
376
-    */
370
+    /**
371
+     * Creates an update command for the target file or folder.
372
+     * This can be configured further before it is executed.
373
+     * 
374
+     * @param SVNHelper_Target $target
375
+     * @return SVNHelper_Command_Update
376
+     */
377 377
     public function createUpdate(SVNHelper_Target $target)
378 378
     {
379 379
         return $this->createCommand('Update', $target);
380 380
     }
381 381
     
382
-   /**
383
-    * Creates an add command for the targt file or folder.
384
-    * 
385
-    * @param SVNHelper_Target $target
386
-    * @return SVNHelper_Command_Add
387
-    */
382
+    /**
383
+     * Creates an add command for the targt file or folder.
384
+     * 
385
+     * @param SVNHelper_Target $target
386
+     * @return SVNHelper_Command_Add
387
+     */
388 388
     public function createAdd(SVNHelper_Target $target)
389 389
     {
390 390
         return $this->createCommand('Add', $target);
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
         return $this->createCommand('Info', $target);
402 402
     }
403 403
     
404
-   /**
405
-    * Creates a status command for the target file or folder.
406
-    * 
407
-    * @param SVNHelper_Target $target
408
-    * @return SVNHelper_Command_Status
409
-    */
404
+    /**
405
+     * Creates a status command for the target file or folder.
406
+     * 
407
+     * @param SVNHelper_Target $target
408
+     * @return SVNHelper_Command_Status
409
+     */
410 410
     public function createStatus(SVNHelper_Target $target)
411 411
     {
412 412
         return $this->createCommand('Status', $target);
@@ -431,28 +431,28 @@  discard block
 block discarded – undo
431 431
         return $cmd;
432 432
     }
433 433
     
434
-   /**
435
-    * Creates a path relative to the repository for the target
436
-    * file or folder, from an absolute path.
437
-    *
438
-    * @param string $path An absolute path.
439
-    * @return string
440
-    */
434
+    /**
435
+     * Creates a path relative to the repository for the target
436
+     * file or folder, from an absolute path.
437
+     *
438
+     * @param string $path An absolute path.
439
+     * @return string
440
+     */
441 441
     public function relativizePath($path)
442 442
     {
443 443
         return $this->normalizePath($path, true);
444 444
     }
445 445
     
446
-   /**
447
-    * Adds a folder: creates it as necessary (recursive),
448
-    * and adds it to be committed if it is not versioned yet.
449
-    * Use this instead of {@link getFolder()} when you are
450
-    * not sure that it exists yet, and will need it.
451
-    * 
452
-    * @param string $path Absolute or relative path to the folder
453
-    * @throws SVNHelper_Exception
454
-    * @return SVNHelper_Target_Folder
455
-    */
446
+    /**
447
+     * Adds a folder: creates it as necessary (recursive),
448
+     * and adds it to be committed if it is not versioned yet.
449
+     * Use this instead of {@link getFolder()} when you are
450
+     * not sure that it exists yet, and will need it.
451
+     * 
452
+     * @param string $path Absolute or relative path to the folder
453
+     * @throws SVNHelper_Exception
454
+     * @return SVNHelper_Target_Folder
455
+     */
456 456
     public function addFolder($path)
457 457
     {
458 458
         if(is_dir($path)) {
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
     
503 503
     protected static $logCallback;
504 504
 
505
-   /**
506
-    * Sets the callback function/method to use for
507
-    * SVH helper log messages. This gets the message
508
-    * and the SVNHelper instance as parameters.
509
-    * 
510
-    * @param callable $callback
511
-    * @throws SVNHelper_Exception
512
-    */
505
+    /**
506
+     * Sets the callback function/method to use for
507
+     * SVH helper log messages. This gets the message
508
+     * and the SVNHelper instance as parameters.
509
+     * 
510
+     * @param callable $callback
511
+     * @throws SVNHelper_Exception
512
+     */
513 513
     public static function setLogCallback($callback)
514 514
     {
515 515
         if(!is_callable($callback)) {
@@ -530,22 +530,22 @@  discard block
 block discarded – undo
530 530
         }
531 531
     }
532 532
 
533
-   /**
534
-    * Retrieves information about the file, and adds it
535
-    * to be committed later if it not versioned yet. 
536
-    * 
537
-    * @param string $path
538
-    * @return SVNHelper_Target_File
539
-    */
533
+    /**
534
+     * Retrieves information about the file, and adds it
535
+     * to be committed later if it not versioned yet. 
536
+     * 
537
+     * @param string $path
538
+     * @return SVNHelper_Target_File
539
+     */
540 540
     public function addFile($path)
541 541
     {
542 542
         return $this->getFile($path)->runAdd();        
543 543
     }
544 544
     
545
-   /**
546
-    * Commits all changes in the repository.
547
-    * @param string $message The commit message to log.
548
-    */
545
+    /**
546
+     * Commits all changes in the repository.
547
+     * @param string $message The commit message to log.
548
+     */
549 549
     public function runCommit($message)
550 550
     {
551 551
         $this->createCommit($this->getFolder($this->path), $message)->execute();
Please login to merge, or discard this patch.