@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @see FileHelper_FileFinder |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -declare(strict_types = 1); |
|
| 10 | +declare(strict_types=1); |
|
| 11 | 11 | |
| 12 | 12 | namespace AppUtils; |
| 13 | 13 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public function getAll() : array |
| 127 | 127 | { |
| 128 | - if(!isset($this->found)) { |
|
| 128 | + if (!isset($this->found)) { |
|
| 129 | 129 | $this->find($this->path, true); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -150,25 +150,25 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | protected $found; |
| 152 | 152 | |
| 153 | - protected function find($path, $isRoot=false) |
|
| 153 | + protected function find($path, $isRoot = false) |
|
| 154 | 154 | { |
| 155 | - if($isRoot) { |
|
| 155 | + if ($isRoot) { |
|
| 156 | 156 | $this->found = array(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $d = new \DirectoryIterator($path); |
| 160 | - foreach($d as $item) |
|
| 160 | + foreach ($d as $item) |
|
| 161 | 161 | { |
| 162 | - if($item->isDir()) |
|
| 162 | + if ($item->isDir()) |
|
| 163 | 163 | { |
| 164 | - if($this->getOption('recursive') === true && !$item->isDot()) { |
|
| 164 | + if ($this->getOption('recursive') === true && !$item->isDot()) { |
|
| 165 | 165 | $this->find($item->getPathname()); |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | else |
| 169 | 169 | { |
| 170 | 170 | $file = $this->filterFile($item->getPathname()); |
| 171 | - if($file) { |
|
| 171 | + if ($file) { |
|
| 172 | 172 | $this->found[] = $file; |
| 173 | 173 | } |
| 174 | 174 | } |
@@ -184,20 +184,20 @@ discard block |
||
| 184 | 184 | $include = $this->getOption('include-extensions'); |
| 185 | 185 | $exclude = $this->getOption('exclude-extensions'); |
| 186 | 186 | |
| 187 | - if(!empty($include)) |
|
| 187 | + if (!empty($include)) |
|
| 188 | 188 | { |
| 189 | - if(!in_array($info['extension'], $include)) { |
|
| 189 | + if (!in_array($info['extension'], $include)) { |
|
| 190 | 190 | return false; |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | - else if(!empty($exclude)) |
|
| 193 | + else if (!empty($exclude)) |
|
| 194 | 194 | { |
| 195 | - if(in_array($info['extension'], $exclude)) { |
|
| 195 | + if (in_array($info['extension'], $exclude)) { |
|
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - switch($this->getOption('pathmode')) |
|
| 200 | + switch ($this->getOption('pathmode')) |
|
| 201 | 201 | { |
| 202 | 202 | case self::PATH_MODE_STRIP: |
| 203 | 203 | $path = basename($path); |
@@ -213,13 +213,13 @@ discard block |
||
| 213 | 213 | break; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - if($this->getOption('strip-extensions') === true) |
|
| 216 | + if ($this->getOption('strip-extensions') === true) |
|
| 217 | 217 | { |
| 218 | 218 | $path = str_replace('.'.$info['extension'], '', $path); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | $replace = $this->getOption('slash-replacement'); |
| 222 | - if(!empty($replace)) { |
|
| 222 | + if (!empty($replace)) { |
|
| 223 | 223 | $path = str_replace('/', $replace, $path); |
| 224 | 224 | } |
| 225 | 225 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param int $code |
| 32 | 32 | * @param \Exception $previous |
| 33 | 33 | */ |
| 34 | - public function __construct(string $message, $details=null, $code=null, $previous=null) |
|
| 34 | + public function __construct(string $message, $details = null, $code = null, $previous = null) |
|
| 35 | 35 | { |
| 36 | 36 | parent::__construct($message, $code, $previous); |
| 37 | 37 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function getDetails() : string |
| 46 | 46 | { |
| 47 | - if($this->details !== null) { |
|
| 47 | + if ($this->details !== null) { |
|
| 48 | 48 | return $this->details; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function display() |
| 59 | 59 | { |
| 60 | - if(!headers_sent()) { |
|
| 60 | + if (!headers_sent()) { |
|
| 61 | 61 | header('Content-type:text/plain; charset=utf-8'); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | throw new BaseException(''); |
| 87 | 87 | } |
| 88 | - catch(BaseException $e) |
|
| 88 | + catch (BaseException $e) |
|
| 89 | 89 | { |
| 90 | 90 | echo self::createInfo($e)->toString(); |
| 91 | 91 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | throw new BaseException(''); |
| 102 | 102 | } |
| 103 | - catch(BaseException $e) |
|
| 103 | + catch (BaseException $e) |
|
| 104 | 104 | { |
| 105 | 105 | echo '<pre style="background:#fff;font-family:monospace;font-size:14px;color:#444;padding:16px;border:solid 1px #999;border-radius:4px;">'; |
| 106 | 106 | echo self::createInfo($e)->toString(); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function setValue($value) : NumberInfo |
| 86 | 86 | { |
| 87 | - if($value instanceof NumberInfo) { |
|
| 87 | + if ($value instanceof NumberInfo) { |
|
| 88 | 88 | $value = $value->getValue(); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | public function isPositive() : bool |
| 119 | 119 | { |
| 120 | - if(!$this->isEmpty()) { |
|
| 120 | + if (!$this->isEmpty()) { |
|
| 121 | 121 | $number = $this->getNumber(); |
| 122 | 122 | return $number > 0; |
| 123 | 123 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function hasValue() : bool |
| 150 | 150 | { |
| 151 | - if(!$this->isEmpty() && !$this->isZero()) { |
|
| 151 | + if (!$this->isEmpty() && !$this->isZero()) { |
|
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public function getUnits() |
| 223 | 223 | { |
| 224 | - if(!$this->hasUnits()) { |
|
| 224 | + if (!$this->hasUnits()) { |
|
| 225 | 225 | return 'px'; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -255,15 +255,15 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | public function toAttribute() |
| 257 | 257 | { |
| 258 | - if($this->isEmpty()) { |
|
| 258 | + if ($this->isEmpty()) { |
|
| 259 | 259 | return null; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if($this->isZero()) { |
|
| 262 | + if ($this->isZero()) { |
|
| 263 | 263 | return '0'; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if($this->isPercent()) { |
|
| 266 | + if ($this->isPercent()) { |
|
| 267 | 267 | return $this->getNumber().$this->getUnits(); |
| 268 | 268 | } |
| 269 | 269 | |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function toCSS() |
| 278 | 278 | { |
| 279 | - if($this->isEmpty()) { |
|
| 279 | + if ($this->isEmpty()) { |
|
| 280 | 280 | return null; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if($this->isZero()) { |
|
| 283 | + if ($this->isZero()) { |
|
| 284 | 284 | return '0'; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | public function __toString() |
| 291 | 291 | { |
| 292 | - if($this->isEmpty()) { |
|
| 292 | + if ($this->isEmpty()) { |
|
| 293 | 293 | return ''; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | public function isBiggerThan($number) |
| 308 | 308 | { |
| 309 | 309 | $number = parseNumber($number); |
| 310 | - if($number->getUnits() != $this->getUnits()) { |
|
| 310 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 311 | 311 | return false; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | public function isSmallerThan($number) |
| 326 | 326 | { |
| 327 | 327 | $number = parseNumber($number); |
| 328 | - if($number->getUnits() != $this->getUnits()) { |
|
| 328 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 329 | 329 | return false; |
| 330 | 330 | } |
| 331 | 331 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | public function isBiggerEqual($number) |
| 336 | 336 | { |
| 337 | 337 | $number = parseNumber($number); |
| 338 | - if($number->getUnits() != $this->getUnits()) { |
|
| 338 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 339 | 339 | return false; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | */ |
| 353 | 353 | public function add($value) |
| 354 | 354 | { |
| 355 | - if($this->isEmpty()) { |
|
| 355 | + if ($this->isEmpty()) { |
|
| 356 | 356 | $this->setValue($value); |
| 357 | 357 | return $this; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | $number = parseNumber($value); |
| 361 | 361 | |
| 362 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 362 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 363 | 363 | { |
| 364 | 364 | $new = $this->getNumber() + $number->getNumber(); |
| 365 | 365 | $this->setValue($new.$this->getUnits()); |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public function subtract($value) |
| 380 | 380 | { |
| 381 | - if($this->isEmpty()) { |
|
| 381 | + if ($this->isEmpty()) { |
|
| 382 | 382 | $this->setValue($value); |
| 383 | 383 | return $this; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $number = parseNumber($value); |
| 387 | 387 | |
| 388 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 388 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 389 | 389 | { |
| 390 | 390 | $new = $this->getNumber() - $number->getNumber(); |
| 391 | 391 | $this->setValue($new.$this->getUnits()); |
@@ -412,25 +412,25 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | protected function percentOperation($operation, $percent) |
| 414 | 414 | { |
| 415 | - if($this->isZeroOrEmpty()) { |
|
| 415 | + if ($this->isZeroOrEmpty()) { |
|
| 416 | 416 | return $this; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | $percent = parseNumber($percent); |
| 420 | - if($percent->hasUnits() && !$percent->isPercent()) { |
|
| 420 | + if ($percent->hasUnits() && !$percent->isPercent()) { |
|
| 421 | 421 | return $this; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | $number = $this->getNumber(); |
| 425 | 425 | $value = $number * $percent->getNumber() / 100; |
| 426 | 426 | |
| 427 | - if($operation == '-') { |
|
| 427 | + if ($operation == '-') { |
|
| 428 | 428 | $number = $number - $value; |
| 429 | 429 | } else { |
| 430 | 430 | $number = $number + $value; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if($this->isUnitInteger()) { |
|
| 433 | + if ($this->isUnitInteger()) { |
|
| 434 | 434 | $number = intval($number); |
| 435 | 435 | } |
| 436 | 436 | |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | { |
| 480 | 480 | static $cache = array(); |
| 481 | 481 | |
| 482 | - if(!is_string($value) && !is_numeric($value)) |
|
| 482 | + if (!is_string($value) && !is_numeric($value)) |
|
| 483 | 483 | { |
| 484 | 484 | $value = ''; |
| 485 | 485 | $key = '_EMPTY_'; |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | $key = (string)$value; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - if(array_key_exists($key, $cache)) { |
|
| 492 | + if (array_key_exists($key, $cache)) { |
|
| 493 | 493 | return $cache[$key]; |
| 494 | 494 | } |
| 495 | 495 | |
@@ -499,31 +499,31 @@ discard block |
||
| 499 | 499 | 'number' => null |
| 500 | 500 | ); |
| 501 | 501 | |
| 502 | - if($value === '') { |
|
| 502 | + if ($value === '') { |
|
| 503 | 503 | $cache[$key]['empty'] = true; |
| 504 | 504 | return $cache[$key]; |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - if($value === 0 || $value === '0') { |
|
| 507 | + if ($value === 0 || $value === '0') { |
|
| 508 | 508 | $cache[$key]['number'] = 0; |
| 509 | 509 | $cache[$key] = $this->filterInfo($cache[$key]); |
| 510 | 510 | return $cache[$key]; |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | $test = trim((string)$value); |
| 514 | - if($test === '') { |
|
| 514 | + if ($test === '') { |
|
| 515 | 515 | $cache[$key]['empty'] = true; |
| 516 | 516 | return $cache[$key]; |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | // replace comma notation (which is only possible if it's a string) |
| 520 | - if(is_string($value)) |
|
| 520 | + if (is_string($value)) |
|
| 521 | 521 | { |
| 522 | 522 | $test = $this->preProcess($test, $cache, $value); |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | // convert to a number if it's numeric |
| 526 | - if(is_numeric($test)) { |
|
| 526 | + if (is_numeric($test)) { |
|
| 527 | 527 | $cache[$key]['number'] = $test * 1; |
| 528 | 528 | $cache[$key] = $this->filterInfo($cache[$key]); |
| 529 | 529 | return $cache[$key]; |
@@ -536,16 +536,16 @@ discard block |
||
| 536 | 536 | |
| 537 | 537 | $vlength = strlen($test); |
| 538 | 538 | $names = array_keys($this->knownUnits); |
| 539 | - foreach($names as $unit) |
|
| 539 | + foreach ($names as $unit) |
|
| 540 | 540 | { |
| 541 | 541 | $ulength = strlen($unit); |
| 542 | - $start = $vlength-$ulength; |
|
| 543 | - if($start < 0) { |
|
| 542 | + $start = $vlength - $ulength; |
|
| 543 | + if ($start < 0) { |
|
| 544 | 544 | continue; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | $search = substr($test, $start, $ulength); |
| 548 | - if($search==$unit) { |
|
| 548 | + if ($search == $unit) { |
|
| 549 | 549 | $units = $unit; |
| 550 | 550 | $number = substr($test, 0, $start); |
| 551 | 551 | break; |
@@ -553,12 +553,12 @@ discard block |
||
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | // the filters have to restore the value |
| 556 | - if($this->postProcess) |
|
| 556 | + if ($this->postProcess) |
|
| 557 | 557 | { |
| 558 | 558 | $number = $this->postProcess($number, $test); |
| 559 | 559 | } |
| 560 | 560 | // empty number |
| 561 | - else if($number === '' || $number === null || is_bool($number)) |
|
| 561 | + else if ($number === '' || $number === null || is_bool($number)) |
|
| 562 | 562 | { |
| 563 | 563 | $number = null; |
| 564 | 564 | $cache[$key]['empty'] = true; |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | $number = trim($number); |
| 570 | 570 | |
| 571 | 571 | // may be an arbitrary string in some cases |
| 572 | - if(!is_numeric($number)) |
|
| 572 | + if (!is_numeric($number)) |
|
| 573 | 573 | { |
| 574 | 574 | $number = null; |
| 575 | 575 | $cache[$key]['empty'] = true; |
@@ -648,12 +648,12 @@ discard block |
||
| 648 | 648 | protected function filterInfo(array $info) : array |
| 649 | 649 | { |
| 650 | 650 | $useUnits = 'px'; |
| 651 | - if($info['units'] !== null) { |
|
| 651 | + if ($info['units'] !== null) { |
|
| 652 | 652 | $useUnits = $info['units']; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | // the units are non-decimal: convert decimal values |
| 656 | - if($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 656 | + if ($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 657 | 657 | { |
| 658 | 658 | $info['number'] = intval($info['number']); |
| 659 | 659 | } |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | $section = $this->addSection(self::SECTION_DEFAULT); |
| 37 | 37 | |
| 38 | - if(empty($iniString)) { |
|
| 38 | + if (empty($iniString)) { |
|
| 39 | 39 | return; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $eol = ConvertHelper::detectEOLCharacter($iniString); |
| 43 | - if($eol !== null) { |
|
| 43 | + if ($eol !== null) { |
|
| 44 | 44 | $this->eol = $eol->getCharacter(); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $total = count($lines); |
| 50 | 50 | |
| 51 | - for($i=0; $i < $total; $i++) |
|
| 51 | + for ($i = 0; $i < $total; $i++) |
|
| 52 | 52 | { |
| 53 | 53 | $line = new IniHelper_Line($lines[$i], $i); |
| 54 | 54 | |
| 55 | - if($line->isSection()) { |
|
| 55 | + if ($line->isSection()) { |
|
| 56 | 56 | $section = $this->addSection($line->getSectionName()); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $iniPath = FileHelper::requireFileExists($iniPath); |
| 83 | 83 | |
| 84 | 84 | $content = file_get_contents($iniPath); |
| 85 | - if($content !== false) { |
|
| 85 | + if ($content !== false) { |
|
| 86 | 86 | return self::createFromString($content); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function addSection(string $name) : IniHelper_Section |
| 129 | 129 | { |
| 130 | - if(!isset($this->sections[$name])) { |
|
| 130 | + if (!isset($this->sections[$name])) { |
|
| 131 | 131 | $this->sections[$name] = new IniHelper_Section($this, $name); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function getSection(string $name) : ?IniHelper_Section |
| 144 | 144 | { |
| 145 | - if(isset($this->sections[$name])) { |
|
| 145 | + if (isset($this->sections[$name])) { |
|
| 146 | 146 | return $this->sections[$name]; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | $result = array(); |
| 160 | 160 | |
| 161 | - foreach($this->sections as $section) |
|
| 161 | + foreach ($this->sections as $section) |
|
| 162 | 162 | { |
| 163 | - if($section->isDefault()) |
|
| 163 | + if ($section->isDefault()) |
|
| 164 | 164 | { |
| 165 | 165 | $result = array_merge($result, $section->toArray()); |
| 166 | 166 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | $parts = array(); |
| 202 | 202 | |
| 203 | - foreach($this->sections as $section) |
|
| 203 | + foreach ($this->sections as $section) |
|
| 204 | 204 | { |
| 205 | 205 | $parts[] = $section->toString(); |
| 206 | 206 | } |
@@ -243,8 +243,8 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | public function sectionExists(string $name) : bool |
| 245 | 245 | { |
| 246 | - foreach($this->sections as $section) { |
|
| 247 | - if($section->getName() === $name) { |
|
| 246 | + foreach ($this->sections as $section) { |
|
| 247 | + if ($section->getName() === $name) { |
|
| 248 | 248 | return true; |
| 249 | 249 | } |
| 250 | 250 | } |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | { |
| 274 | 274 | $path = $this->parsePath($path); |
| 275 | 275 | |
| 276 | - if(!$this->sectionExists($path['section'])) { |
|
| 276 | + if (!$this->sectionExists($path['section'])) { |
|
| 277 | 277 | return array(); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | { |
| 285 | 285 | $path = explode($this->pathSeparator, $path); |
| 286 | 286 | |
| 287 | - if(count($path) === 1) |
|
| 287 | + if (count($path) === 1) |
|
| 288 | 288 | { |
| 289 | 289 | return array( |
| 290 | 290 | 'section' => self::SECTION_DEFAULT, |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function setOption(string $name, $value) : Interface_Optionable |
| 43 | 43 | { |
| 44 | - if(!isset($this->options)) { |
|
| 44 | + if (!isset($this->options)) { |
|
| 45 | 45 | $this->options = $this->getDefaultOptions(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function setOptions(array $options) : Interface_Optionable |
| 60 | 60 | { |
| 61 | - foreach($options as $name => $value) { |
|
| 61 | + foreach ($options as $name => $value) { |
|
| 62 | 62 | $this->setOption($name, $value); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | * @param mixed $default The default value to return if the option does not exist. |
| 76 | 76 | * @return mixed |
| 77 | 77 | */ |
| 78 | - public function getOption(string $name, $default=null) |
|
| 78 | + public function getOption(string $name, $default = null) |
|
| 79 | 79 | { |
| 80 | - if(!isset($this->options)) { |
|
| 80 | + if (!isset($this->options)) { |
|
| 81 | 81 | $this->options = $this->getDefaultOptions(); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if(isset($this->options[$name])) { |
|
| 84 | + if (isset($this->options[$name])) { |
|
| 85 | 85 | return $this->options[$name]; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | $value = $this->getOption($name, false); |
| 102 | 102 | |
| 103 | - if(is_scalar($value)) { |
|
| 103 | + if (is_scalar($value)) { |
|
| 104 | 104 | return (string)$value; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | public function getBoolOption(string $name) : bool |
| 120 | 120 | { |
| 121 | - if($this->getOption($name) === true) { |
|
| 121 | + if ($this->getOption($name) === true) { |
|
| 122 | 122 | return true; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | public function getArrayOption(string $name) : array |
| 137 | 137 | { |
| 138 | 138 | $val = $this->getOption($name); |
| 139 | - if(is_array($val)) { |
|
| 139 | + if (is_array($val)) { |
|
| 140 | 140 | return $val; |
| 141 | 141 | } |
| 142 | 142 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function hasOption(string $name) : bool |
| 154 | 154 | { |
| 155 | - if(!isset($this->options)) { |
|
| 155 | + if (!isset($this->options)) { |
|
| 156 | 156 | $this->options = $this->getDefaultOptions(); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function getOptions() : array |
| 167 | 167 | { |
| 168 | - if(!isset($this->options)) { |
|
| 168 | + if (!isset($this->options)) { |
|
| 169 | 169 | $this->options = $this->getDefaultOptions(); |
| 170 | 170 | } |
| 171 | 171 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | interface Interface_Optionable |
| 201 | 201 | { |
| 202 | 202 | function setOption(string $name, $value) : Interface_Optionable; |
| 203 | - function getOption(string $name, $default=null); |
|
| 203 | + function getOption(string $name, $default = null); |
|
| 204 | 204 | function setOptions(array $options) : Interface_Optionable; |
| 205 | 205 | function getOptions() : array; |
| 206 | 206 | function isOption(string $name, $value) : bool; |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $contents = file_get_contents($file); |
| 112 | 112 | |
| 113 | - if($contents === false) |
|
| 113 | + if ($contents === false) |
|
| 114 | 114 | { |
| 115 | 115 | throw new FileHelper_Exception( |
| 116 | 116 | 'Cannot load serialized content from file.', |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | $result = @unserialize($contents); |
| 126 | 126 | |
| 127 | - if($result !== false) { |
|
| 127 | + if ($result !== false) { |
|
| 128 | 128 | return $result; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | public static function deleteTree($rootFolder) |
| 142 | 142 | { |
| 143 | - if(!file_exists($rootFolder)) { |
|
| 143 | + if (!file_exists($rootFolder)) { |
|
| 144 | 144 | return true; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | public static function createFolder($path) |
| 183 | 183 | { |
| 184 | - if(is_dir($path) || mkdir($path, 0777, true)) { |
|
| 184 | + if (is_dir($path) || mkdir($path, 0777, true)) { |
|
| 185 | 185 | return; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -216,11 +216,11 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | if ($item->isDir()) |
| 218 | 218 | { |
| 219 | - FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName); |
|
| 219 | + FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target.'/'.$baseName); |
|
| 220 | 220 | } |
| 221 | - else if($item->isFile()) |
|
| 221 | + else if ($item->isFile()) |
|
| 222 | 222 | { |
| 223 | - self::copyFile($itemPath, $target . '/' . $baseName); |
|
| 223 | + self::copyFile($itemPath, $target.'/'.$baseName); |
|
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | { |
| 246 | 246 | self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND); |
| 247 | 247 | |
| 248 | - if(!is_readable($sourcePath)) |
|
| 248 | + if (!is_readable($sourcePath)) |
|
| 249 | 249 | { |
| 250 | 250 | throw new FileHelper_Exception( |
| 251 | 251 | sprintf('Source file [%s] to copy is not readable.', basename($sourcePath)), |
@@ -259,11 +259,11 @@ discard block |
||
| 259 | 259 | |
| 260 | 260 | $targetFolder = dirname($targetPath); |
| 261 | 261 | |
| 262 | - if(!file_exists($targetFolder)) |
|
| 262 | + if (!file_exists($targetFolder)) |
|
| 263 | 263 | { |
| 264 | 264 | self::createFolder($targetFolder); |
| 265 | 265 | } |
| 266 | - else if(!is_writable($targetFolder)) |
|
| 266 | + else if (!is_writable($targetFolder)) |
|
| 267 | 267 | { |
| 268 | 268 | throw new FileHelper_Exception( |
| 269 | 269 | sprintf('Target folder [%s] is not writable.', basename($targetFolder)), |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | ); |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if(copy($sourcePath, $targetPath)) { |
|
| 278 | + if (copy($sourcePath, $targetPath)) { |
|
| 279 | 279 | return; |
| 280 | 280 | } |
| 281 | 281 | |
@@ -302,11 +302,11 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | public static function deleteFile(string $filePath) : void |
| 304 | 304 | { |
| 305 | - if(!file_exists($filePath)) { |
|
| 305 | + if (!file_exists($filePath)) { |
|
| 306 | 306 | return; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if(unlink($filePath)) { |
|
| 309 | + if (unlink($filePath)) { |
|
| 310 | 310 | return; |
| 311 | 311 | } |
| 312 | 312 | |
@@ -330,10 +330,10 @@ discard block |
||
| 330 | 330 | * @return \parseCSV |
| 331 | 331 | * @todo Move this to the CSV helper. |
| 332 | 332 | */ |
| 333 | - public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : \parseCSV |
|
| 333 | + public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : \parseCSV |
|
| 334 | 334 | { |
| 335 | - if($delimiter==='') { $delimiter = ';'; } |
|
| 336 | - if($enclosure==='') { $enclosure = '"'; } |
|
| 335 | + if ($delimiter === '') { $delimiter = ';'; } |
|
| 336 | + if ($enclosure === '') { $enclosure = '"'; } |
|
| 337 | 337 | |
| 338 | 338 | $parser = new \parseCSV(null, null, null, array()); |
| 339 | 339 | |
@@ -361,11 +361,11 @@ discard block |
||
| 361 | 361 | * @see parseCSVFile() |
| 362 | 362 | * @see FileHelper::ERROR_PARSING_CSV |
| 363 | 363 | */ |
| 364 | - public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
| 364 | + public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
| 365 | 365 | { |
| 366 | 366 | $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading); |
| 367 | 367 | $result = $parser->parse_string(/** @scrutinizer ignore-type */ $csv); |
| 368 | - if(is_array($result)) { |
|
| 368 | + if (is_array($result)) { |
|
| 369 | 369 | return $result; |
| 370 | 370 | } |
| 371 | 371 | |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 394 | 394 | * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
| 395 | 395 | */ |
| 396 | - public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
| 396 | + public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
| 397 | 397 | { |
| 398 | 398 | $content = self::readContents($filePath); |
| 399 | 399 | |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | public static function detectMimeType(string $fileName) : ?string |
| 411 | 411 | { |
| 412 | 412 | $ext = self::getExtension($fileName); |
| 413 | - if(empty($ext)) { |
|
| 413 | + if (empty($ext)) { |
|
| 414 | 414 | return null; |
| 415 | 415 | } |
| 416 | 416 | |
@@ -434,11 +434,11 @@ discard block |
||
| 434 | 434 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 435 | 435 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
| 436 | 436 | */ |
| 437 | - public static function sendFile(string $filePath, $fileName = null, bool $asAttachment=true, bool $exit=true) |
|
| 437 | + public static function sendFile(string $filePath, $fileName = null, bool $asAttachment = true, bool $exit = true) |
|
| 438 | 438 | { |
| 439 | 439 | self::requireFileExists($filePath); |
| 440 | 440 | |
| 441 | - if(empty($fileName)) { |
|
| 441 | + if (empty($fileName)) { |
|
| 442 | 442 | $fileName = basename($filePath); |
| 443 | 443 | } |
| 444 | 444 | |
@@ -456,10 +456,10 @@ discard block |
||
| 456 | 456 | |
| 457 | 457 | header("Cache-Control: public", true); |
| 458 | 458 | header("Content-Description: File Transfer", true); |
| 459 | - header("Content-Type: " . $mime, true); |
|
| 459 | + header("Content-Type: ".$mime, true); |
|
| 460 | 460 | |
| 461 | 461 | $disposition = 'inline'; |
| 462 | - if($asAttachment) { |
|
| 462 | + if ($asAttachment) { |
|
| 463 | 463 | $disposition = 'attachment'; |
| 464 | 464 | } |
| 465 | 465 | |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | |
| 472 | 472 | readfile($filePath); |
| 473 | 473 | |
| 474 | - if($exit) |
|
| 474 | + if ($exit) |
|
| 475 | 475 | { |
| 476 | 476 | exit; |
| 477 | 477 | } |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | */ |
| 491 | 491 | public static function downloadFile($url) |
| 492 | 492 | { |
| 493 | - if(!function_exists('curl_init')) |
|
| 493 | + if (!function_exists('curl_init')) |
|
| 494 | 494 | { |
| 495 | 495 | throw new FileHelper_Exception( |
| 496 | 496 | 'The cURL extension is not installed.', |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | $ch = curl_init(); |
| 503 | - if($ch === false) |
|
| 503 | + if ($ch === false) |
|
| 504 | 504 | { |
| 505 | 505 | throw new FileHelper_Exception( |
| 506 | 506 | 'Could not initialize a new cURL instance.', |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | |
| 522 | 522 | $output = curl_exec($ch); |
| 523 | 523 | |
| 524 | - if($output === false) { |
|
| 524 | + if ($output === false) { |
|
| 525 | 525 | throw new FileHelper_Exception( |
| 526 | 526 | 'Unable to open URL', |
| 527 | 527 | sprintf( |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | |
| 536 | 536 | curl_close($ch); |
| 537 | 537 | |
| 538 | - if(is_string($output)) |
|
| 538 | + if (is_string($output)) |
|
| 539 | 539 | { |
| 540 | 540 | return $output; |
| 541 | 541 | } |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | */ |
| 558 | 558 | public static function isPHPFile($pathOrDirIterator) |
| 559 | 559 | { |
| 560 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
| 560 | + if (self::getExtension($pathOrDirIterator) == 'php') { |
|
| 561 | 561 | return true; |
| 562 | 562 | } |
| 563 | 563 | |
@@ -574,14 +574,14 @@ discard block |
||
| 574 | 574 | */ |
| 575 | 575 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
| 576 | 576 | { |
| 577 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 577 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 578 | 578 | $filename = $pathOrDirIterator->getFilename(); |
| 579 | 579 | } else { |
| 580 | 580 | $filename = basename($pathOrDirIterator); |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
| 584 | - if($lowercase) { |
|
| 584 | + if ($lowercase) { |
|
| 585 | 585 | $ext = mb_strtolower($ext); |
| 586 | 586 | } |
| 587 | 587 | |
@@ -603,13 +603,13 @@ discard block |
||
| 603 | 603 | public static function getFilename($pathOrDirIterator, $extension = true) |
| 604 | 604 | { |
| 605 | 605 | $path = $pathOrDirIterator; |
| 606 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 606 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 607 | 607 | $path = $pathOrDirIterator->getFilename(); |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | $path = self::normalizePath($path); |
| 611 | 611 | |
| 612 | - if(!$extension) { |
|
| 612 | + if (!$extension) { |
|
| 613 | 613 | return pathinfo($path, PATHINFO_FILENAME); |
| 614 | 614 | } |
| 615 | 615 | |
@@ -627,12 +627,12 @@ discard block |
||
| 627 | 627 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
| 628 | 628 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
| 629 | 629 | */ |
| 630 | - public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
|
| 630 | + public static function parseJSONFile(string $file, $targetEncoding = null, $sourceEncoding = null) |
|
| 631 | 631 | { |
| 632 | 632 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
| 633 | 633 | |
| 634 | 634 | $content = file_get_contents($file); |
| 635 | - if(!$content) { |
|
| 635 | + if (!$content) { |
|
| 636 | 636 | throw new FileHelper_Exception( |
| 637 | 637 | 'Cannot get file contents', |
| 638 | 638 | sprintf( |
@@ -643,12 +643,12 @@ discard block |
||
| 643 | 643 | ); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - if(isset($targetEncoding)) { |
|
| 646 | + if (isset($targetEncoding)) { |
|
| 647 | 647 | $content = mb_convert_encoding($content, $targetEncoding, $sourceEncoding); |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | $json = json_decode($content, true); |
| 651 | - if($json === false || $json === NULL) { |
|
| 651 | + if ($json === false || $json === NULL) { |
|
| 652 | 652 | throw new FileHelper_Exception( |
| 653 | 653 | 'Cannot decode json data', |
| 654 | 654 | sprintf( |
@@ -688,13 +688,13 @@ discard block |
||
| 688 | 688 | |
| 689 | 689 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
| 690 | 690 | |
| 691 | - while(strstr($name, ' ')) { |
|
| 691 | + while (strstr($name, ' ')) { |
|
| 692 | 692 | $name = str_replace(' ', ' ', $name); |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
| 696 | 696 | |
| 697 | - while(strstr($name, '..')) { |
|
| 697 | + while (strstr($name, '..')) { |
|
| 698 | 698 | $name = str_replace('..', '.', $name); |
| 699 | 699 | } |
| 700 | 700 | |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * |
| 725 | 725 | * @todo Convert this to use the file finder. |
| 726 | 726 | */ |
| 727 | - public static function findHTMLFiles(string $targetFolder, array $options=array()) : array |
|
| 727 | + public static function findHTMLFiles(string $targetFolder, array $options = array()) : array |
|
| 728 | 728 | { |
| 729 | 729 | return self::findFiles($targetFolder, array('html'), $options); |
| 730 | 730 | } |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | * |
| 740 | 740 | * @todo Convert this to use the file finder. |
| 741 | 741 | */ |
| 742 | - public static function findPHPFiles(string $targetFolder, array $options=array()) : array |
|
| 742 | + public static function findPHPFiles(string $targetFolder, array $options = array()) : array |
|
| 743 | 743 | { |
| 744 | 744 | return self::findFiles($targetFolder, array('php'), $options); |
| 745 | 745 | } |
@@ -755,39 +755,39 @@ discard block |
||
| 755 | 755 | * @deprecated Will be replaced by the file finder in the future. |
| 756 | 756 | * @see FileHelper::createFileFinder() |
| 757 | 757 | */ |
| 758 | - public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array |
|
| 758 | + public static function findFiles(string $targetFolder, array $extensions = array(), array $options = array(), array $files = array()) : array |
|
| 759 | 759 | { |
| 760 | - if(!isset($options['strip-extension'])) { |
|
| 760 | + if (!isset($options['strip-extension'])) { |
|
| 761 | 761 | $options['strip-extension'] = false; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - if(!isset($options['absolute-path'])) { |
|
| 764 | + if (!isset($options['absolute-path'])) { |
|
| 765 | 765 | $options['absolute-path'] = false; |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | - if(!isset($options['relative-path'])) { |
|
| 768 | + if (!isset($options['relative-path'])) { |
|
| 769 | 769 | $options['relative-path'] = false; |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | - if(!isset($options['recursive'])) { |
|
| 772 | + if (!isset($options['recursive'])) { |
|
| 773 | 773 | $options['recursive'] = false; |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - if($options['relative-path']) { |
|
| 776 | + if ($options['relative-path']) { |
|
| 777 | 777 | $options['absolute-path'] = true; |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | - if(!isset($options['__root'])) { |
|
| 780 | + if (!isset($options['__root'])) { |
|
| 781 | 781 | $options['__root'] = self::normalizePath($targetFolder); |
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | $checkExtensions = false; |
| 785 | - if(!empty($extensions)) { |
|
| 785 | + if (!empty($extensions)) { |
|
| 786 | 786 | $checkExtensions = true; |
| 787 | 787 | $extensions = array_map('strtolower', $extensions); |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | - if(!is_dir($targetFolder)) |
|
| 790 | + if (!is_dir($targetFolder)) |
|
| 791 | 791 | { |
| 792 | 792 | throw new FileHelper_Exception( |
| 793 | 793 | 'Target folder does not exist', |
@@ -800,32 +800,32 @@ discard block |
||
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | $d = new \DirectoryIterator($targetFolder); |
| 803 | - foreach($d as $item) { |
|
| 804 | - if($item->isDot()) { |
|
| 803 | + foreach ($d as $item) { |
|
| 804 | + if ($item->isDot()) { |
|
| 805 | 805 | continue; |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | - if($item->isDir()) { |
|
| 809 | - if($options['recursive']) { |
|
| 808 | + if ($item->isDir()) { |
|
| 809 | + if ($options['recursive']) { |
|
| 810 | 810 | $files = self::findFiles($item->getPathname(), $extensions, $options, $files); |
| 811 | 811 | } |
| 812 | 812 | continue; |
| 813 | 813 | } |
| 814 | 814 | |
| 815 | - if($checkExtensions && !in_array(self::getExtension($item, true), $extensions)) { |
|
| 815 | + if ($checkExtensions && !in_array(self::getExtension($item, true), $extensions)) { |
|
| 816 | 816 | continue; |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | $filename = $item->getFilename(); |
| 820 | - if($options['strip-extension']) { |
|
| 820 | + if ($options['strip-extension']) { |
|
| 821 | 821 | $filename = self::removeExtension($filename); |
| 822 | 822 | } |
| 823 | 823 | |
| 824 | - if($options['absolute-path']) { |
|
| 824 | + if ($options['absolute-path']) { |
|
| 825 | 825 | $filename = self::normalizePath($targetFolder.'/'.$filename); |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - if($options['relative-path']) { |
|
| 828 | + if ($options['relative-path']) { |
|
| 829 | 829 | $filename = ltrim(str_replace($options['__root'], '', $filename), '/'); |
| 830 | 830 | } |
| 831 | 831 | |
@@ -873,9 +873,9 @@ discard block |
||
| 873 | 873 | fclose($fp); |
| 874 | 874 | |
| 875 | 875 | $boms = self::getUTFBOMs(); |
| 876 | - foreach($boms as $bom => $value) { |
|
| 876 | + foreach ($boms as $bom => $value) { |
|
| 877 | 877 | $length = mb_strlen($value); |
| 878 | - if(mb_substr($text, 0, $length) == $value) { |
|
| 878 | + if (mb_substr($text, 0, $length) == $value) { |
|
| 879 | 879 | return $bom; |
| 880 | 880 | } |
| 881 | 881 | } |
@@ -894,13 +894,13 @@ discard block |
||
| 894 | 894 | */ |
| 895 | 895 | public static function getUTFBOMs() |
| 896 | 896 | { |
| 897 | - if(!isset(self::$utfBoms)) { |
|
| 897 | + if (!isset(self::$utfBoms)) { |
|
| 898 | 898 | self::$utfBoms = array( |
| 899 | - 'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF), |
|
| 900 | - 'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00), |
|
| 901 | - 'UTF16-BE' => chr(0xFE) . chr(0xFF), |
|
| 902 | - 'UTF16-LE' => chr(0xFF) . chr(0xFE), |
|
| 903 | - 'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF) |
|
| 899 | + 'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF), |
|
| 900 | + 'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00), |
|
| 901 | + 'UTF16-BE' => chr(0xFE).chr(0xFF), |
|
| 902 | + 'UTF16-LE' => chr(0xFF).chr(0xFE), |
|
| 903 | + 'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF) |
|
| 904 | 904 | ); |
| 905 | 905 | } |
| 906 | 906 | |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | $encodings = self::getKnownUnicodeEncodings(); |
| 922 | 922 | |
| 923 | 923 | $keep = array(); |
| 924 | - foreach($encodings as $string) |
|
| 924 | + foreach ($encodings as $string) |
|
| 925 | 925 | { |
| 926 | 926 | $withHyphen = str_replace('UTF', 'UTF-', $string); |
| 927 | 927 | |
@@ -955,15 +955,15 @@ discard block |
||
| 955 | 955 | return str_replace(array('\\', '//'), array('/', '/'), $path); |
| 956 | 956 | } |
| 957 | 957 | |
| 958 | - public static function saveAsJSON($data, $file, $pretty=false) |
|
| 958 | + public static function saveAsJSON($data, $file, $pretty = false) |
|
| 959 | 959 | { |
| 960 | 960 | $options = null; |
| 961 | - if($pretty) { |
|
| 961 | + if ($pretty) { |
|
| 962 | 962 | $options = JSON_PRETTY_PRINT; |
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | $json = json_encode($data, $options); |
| 966 | - if($json===false) |
|
| 966 | + if ($json === false) |
|
| 967 | 967 | { |
| 968 | 968 | $errorCode = json_last_error(); |
| 969 | 969 | throw new FileHelper_Exception( |
@@ -973,7 +973,7 @@ discard block |
||
| 973 | 973 | ); |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | - if(!file_put_contents($file, $json)) { |
|
| 976 | + if (!file_put_contents($file, $json)) { |
|
| 977 | 977 | throw new FileHelper_Exception( |
| 978 | 978 | sprintf('Could not write the JSON file [%s] to disk.', basename($file)), |
| 979 | 979 | sprintf('Full path: [%s].', $file), |
@@ -994,12 +994,12 @@ discard block |
||
| 994 | 994 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 995 | 995 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 996 | 996 | */ |
| 997 | - public static function saveFile(string $filePath, string $content='') : void |
|
| 997 | + public static function saveFile(string $filePath, string $content = '') : void |
|
| 998 | 998 | { |
| 999 | 999 | // target file already exists |
| 1000 | - if(file_exists($filePath)) |
|
| 1000 | + if (file_exists($filePath)) |
|
| 1001 | 1001 | { |
| 1002 | - if(!is_writable($filePath)) |
|
| 1002 | + if (!is_writable($filePath)) |
|
| 1003 | 1003 | { |
| 1004 | 1004 | throw new FileHelper_Exception( |
| 1005 | 1005 | sprintf('Cannot save file: target file [%s] exists, but is not writable.', basename($filePath)), |
@@ -1019,7 +1019,7 @@ discard block |
||
| 1019 | 1019 | // create the folder as needed |
| 1020 | 1020 | self::createFolder($targetFolder); |
| 1021 | 1021 | |
| 1022 | - if(!is_writable($targetFolder)) |
|
| 1022 | + if (!is_writable($targetFolder)) |
|
| 1023 | 1023 | { |
| 1024 | 1024 | throw new FileHelper_Exception( |
| 1025 | 1025 | sprintf('Cannot save file: target folder [%s] is not writable.', basename($targetFolder)), |
@@ -1032,7 +1032,7 @@ discard block |
||
| 1032 | 1032 | } |
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | - if(file_put_contents($filePath, $content) !== false) { |
|
| 1035 | + if (file_put_contents($filePath, $content) !== false) { |
|
| 1036 | 1036 | return; |
| 1037 | 1037 | } |
| 1038 | 1038 | |
@@ -1068,7 +1068,7 @@ discard block |
||
| 1068 | 1068 | { |
| 1069 | 1069 | static $checked = array(); |
| 1070 | 1070 | |
| 1071 | - if(isset($checked[$command])) { |
|
| 1071 | + if (isset($checked[$command])) { |
|
| 1072 | 1072 | return $checked[$command]; |
| 1073 | 1073 | } |
| 1074 | 1074 | |
@@ -1081,7 +1081,7 @@ discard block |
||
| 1081 | 1081 | |
| 1082 | 1082 | $os = strtolower(PHP_OS_FAMILY); |
| 1083 | 1083 | |
| 1084 | - if(!isset($osCommands[$os])) |
|
| 1084 | + if (!isset($osCommands[$os])) |
|
| 1085 | 1085 | { |
| 1086 | 1086 | throw new FileHelper_Exception( |
| 1087 | 1087 | 'Unsupported OS for CLI commands', |
@@ -1107,7 +1107,7 @@ discard block |
||
| 1107 | 1107 | $pipes |
| 1108 | 1108 | ); |
| 1109 | 1109 | |
| 1110 | - if($process === false) { |
|
| 1110 | + if ($process === false) { |
|
| 1111 | 1111 | $checked[$command] = false; |
| 1112 | 1112 | return false; |
| 1113 | 1113 | } |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | */ |
| 1139 | 1139 | public static function checkPHPFileSyntax($path) |
| 1140 | 1140 | { |
| 1141 | - if(!self::canMakePHPCalls()) { |
|
| 1141 | + if (!self::canMakePHPCalls()) { |
|
| 1142 | 1142 | return true; |
| 1143 | 1143 | } |
| 1144 | 1144 | |
@@ -1149,7 +1149,7 @@ discard block |
||
| 1149 | 1149 | // when the validation is successful, the first entry |
| 1150 | 1150 | // in the array contains the success message. When it |
| 1151 | 1151 | // is invalid, the first entry is always empty. |
| 1152 | - if(!empty($output[0])) { |
|
| 1152 | + if (!empty($output[0])) { |
|
| 1153 | 1153 | return true; |
| 1154 | 1154 | } |
| 1155 | 1155 | |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | public static function getModifiedDate($path) |
| 1171 | 1171 | { |
| 1172 | 1172 | $time = filemtime($path); |
| 1173 | - if($time !== false) { |
|
| 1173 | + if ($time !== false) { |
|
| 1174 | 1174 | $date = new \DateTime(); |
| 1175 | 1175 | $date->setTimestamp($time); |
| 1176 | 1176 | return $date; |
@@ -1197,7 +1197,7 @@ discard block |
||
| 1197 | 1197 | */ |
| 1198 | 1198 | public static function getSubfolders($targetFolder, $options = array()) |
| 1199 | 1199 | { |
| 1200 | - if(!is_dir($targetFolder)) |
|
| 1200 | + if (!is_dir($targetFolder)) |
|
| 1201 | 1201 | { |
| 1202 | 1202 | throw new FileHelper_Exception( |
| 1203 | 1203 | 'Target folder does not exist', |
@@ -1221,29 +1221,29 @@ discard block |
||
| 1221 | 1221 | |
| 1222 | 1222 | $d = new \DirectoryIterator($targetFolder); |
| 1223 | 1223 | |
| 1224 | - foreach($d as $item) |
|
| 1224 | + foreach ($d as $item) |
|
| 1225 | 1225 | { |
| 1226 | - if($item->isDir() && !$item->isDot()) |
|
| 1226 | + if ($item->isDir() && !$item->isDot()) |
|
| 1227 | 1227 | { |
| 1228 | 1228 | $name = $item->getFilename(); |
| 1229 | 1229 | |
| 1230 | - if(!$options['absolute-path']) { |
|
| 1230 | + if (!$options['absolute-path']) { |
|
| 1231 | 1231 | $result[] = $name; |
| 1232 | 1232 | } else { |
| 1233 | 1233 | $result[] = $targetFolder.'/'.$name; |
| 1234 | 1234 | } |
| 1235 | 1235 | |
| 1236 | - if(!$options['recursive']) |
|
| 1236 | + if (!$options['recursive']) |
|
| 1237 | 1237 | { |
| 1238 | 1238 | continue; |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | $subs = self::getSubfolders($targetFolder.'/'.$name, $options); |
| 1242 | - foreach($subs as $sub) |
|
| 1242 | + foreach ($subs as $sub) |
|
| 1243 | 1243 | { |
| 1244 | 1244 | $relative = $name.'/'.$sub; |
| 1245 | 1245 | |
| 1246 | - if(!$options['absolute-path']) { |
|
| 1246 | + if (!$options['absolute-path']) { |
|
| 1247 | 1247 | $result[] = $relative; |
| 1248 | 1248 | } else { |
| 1249 | 1249 | $result[] = $targetFolder.'/'.$relative; |
@@ -1311,7 +1311,7 @@ discard block |
||
| 1311 | 1311 | * @param int $depth The folder depth to reduce the path to |
| 1312 | 1312 | * @return string |
| 1313 | 1313 | */ |
| 1314 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
| 1314 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
| 1315 | 1315 | { |
| 1316 | 1316 | $path = self::normalizePath($path); |
| 1317 | 1317 | |
@@ -1319,17 +1319,17 @@ discard block |
||
| 1319 | 1319 | $tokens = array_filter($tokens); // remove empty entries (trailing slash for example) |
| 1320 | 1320 | $tokens = array_values($tokens); // re-index keys |
| 1321 | 1321 | |
| 1322 | - if(empty($tokens)) { |
|
| 1322 | + if (empty($tokens)) { |
|
| 1323 | 1323 | return ''; |
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | // remove the drive if present |
| 1327 | - if(strstr($tokens[0], ':')) { |
|
| 1327 | + if (strstr($tokens[0], ':')) { |
|
| 1328 | 1328 | array_shift($tokens); |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | // path was only the drive |
| 1332 | - if(count($tokens) == 0) { |
|
| 1332 | + if (count($tokens) == 0) { |
|
| 1333 | 1333 | return ''; |
| 1334 | 1334 | } |
| 1335 | 1335 | |
@@ -1338,8 +1338,8 @@ discard block |
||
| 1338 | 1338 | |
| 1339 | 1339 | // reduce the path to the specified depth |
| 1340 | 1340 | $length = count($tokens); |
| 1341 | - if($length > $depth) { |
|
| 1342 | - $tokens = array_slice($tokens, $length-$depth); |
|
| 1341 | + if ($length > $depth) { |
|
| 1342 | + $tokens = array_slice($tokens, $length - $depth); |
|
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | 1345 | // append the last element again |
@@ -1387,14 +1387,14 @@ discard block |
||
| 1387 | 1387 | * |
| 1388 | 1388 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 1389 | 1389 | */ |
| 1390 | - public static function requireFileExists(string $path, $errorCode=null) : string |
|
| 1390 | + public static function requireFileExists(string $path, $errorCode = null) : string |
|
| 1391 | 1391 | { |
| 1392 | 1392 | $result = realpath($path); |
| 1393 | - if($result !== false) { |
|
| 1393 | + if ($result !== false) { |
|
| 1394 | 1394 | return $result; |
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | - if($errorCode === null) { |
|
| 1397 | + if ($errorCode === null) { |
|
| 1398 | 1398 | $errorCode = self::ERROR_FILE_DOES_NOT_EXIST; |
| 1399 | 1399 | } |
| 1400 | 1400 | |
@@ -1423,15 +1423,15 @@ discard block |
||
| 1423 | 1423 | |
| 1424 | 1424 | $file = new \SplFileObject($path); |
| 1425 | 1425 | |
| 1426 | - if($file->eof()) { |
|
| 1426 | + if ($file->eof()) { |
|
| 1427 | 1427 | return ''; |
| 1428 | 1428 | } |
| 1429 | 1429 | |
| 1430 | - $targetLine = $lineNumber-1; |
|
| 1430 | + $targetLine = $lineNumber - 1; |
|
| 1431 | 1431 | |
| 1432 | 1432 | $file->seek($targetLine); |
| 1433 | 1433 | |
| 1434 | - if($file->key() !== $targetLine) { |
|
| 1434 | + if ($file->key() !== $targetLine) { |
|
| 1435 | 1435 | return null; |
| 1436 | 1436 | } |
| 1437 | 1437 | |
@@ -1457,7 +1457,7 @@ discard block |
||
| 1457 | 1457 | $number = $spl->key(); |
| 1458 | 1458 | |
| 1459 | 1459 | // if seeking to the end the cursor is still at 0, there are no lines. |
| 1460 | - if($number === 0) |
|
| 1460 | + if ($number === 0) |
|
| 1461 | 1461 | { |
| 1462 | 1462 | // since it's a very small file, to get reliable results, |
| 1463 | 1463 | // we read its contents and use that to determine what |
@@ -1465,13 +1465,13 @@ discard block |
||
| 1465 | 1465 | // that this is not pactical to solve with the SplFileObject. |
| 1466 | 1466 | $content = file_get_contents($path); |
| 1467 | 1467 | |
| 1468 | - if(empty($content)) { |
|
| 1468 | + if (empty($content)) { |
|
| 1469 | 1469 | return 0; |
| 1470 | 1470 | } |
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | 1473 | // return the line number we were able to reach + 1 (key is zero-based) |
| 1474 | - return $number+1; |
|
| 1474 | + return $number + 1; |
|
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | 1477 | /** |
@@ -1518,13 +1518,13 @@ discard block |
||
| 1518 | 1518 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
| 1519 | 1519 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 1520 | 1520 | */ |
| 1521 | - public static function readLines(string $filePath, int $amount=0) : array |
|
| 1521 | + public static function readLines(string $filePath, int $amount = 0) : array |
|
| 1522 | 1522 | { |
| 1523 | 1523 | self::requireFileExists($filePath); |
| 1524 | 1524 | |
| 1525 | 1525 | $fn = fopen($filePath, "r"); |
| 1526 | 1526 | |
| 1527 | - if($fn === false) |
|
| 1527 | + if ($fn === false) |
|
| 1528 | 1528 | { |
| 1529 | 1529 | throw new FileHelper_Exception( |
| 1530 | 1530 | 'Could not open file for reading.', |
@@ -1540,25 +1540,25 @@ discard block |
||
| 1540 | 1540 | $counter = 0; |
| 1541 | 1541 | $first = true; |
| 1542 | 1542 | |
| 1543 | - while(!feof($fn)) |
|
| 1543 | + while (!feof($fn)) |
|
| 1544 | 1544 | { |
| 1545 | 1545 | $counter++; |
| 1546 | 1546 | |
| 1547 | 1547 | $line = fgets($fn); |
| 1548 | 1548 | |
| 1549 | 1549 | // can happen with zero length files |
| 1550 | - if($line === false) { |
|
| 1550 | + if ($line === false) { |
|
| 1551 | 1551 | continue; |
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | // the first line may contain a unicode BOM marker. |
| 1555 | - if($first) { |
|
| 1555 | + if ($first) { |
|
| 1556 | 1556 | $line = ConvertHelper::stripUTFBom($line); |
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | 1559 | $result[] = $line; |
| 1560 | 1560 | |
| 1561 | - if($amount > 0 && $counter == $amount) { |
|
| 1561 | + if ($amount > 0 && $counter == $amount) { |
|
| 1562 | 1562 | break; |
| 1563 | 1563 | } |
| 1564 | 1564 | } |
@@ -1584,7 +1584,7 @@ discard block |
||
| 1584 | 1584 | |
| 1585 | 1585 | $result = file_get_contents($filePath); |
| 1586 | 1586 | |
| 1587 | - if($result !== false) { |
|
| 1587 | + if ($result !== false) { |
|
| 1588 | 1588 | return $result; |
| 1589 | 1589 | } |
| 1590 | 1590 | |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | * @param mixed $value |
| 52 | 52 | * @param array|null $serialized |
| 53 | 53 | */ |
| 54 | - public function __construct($value, $serialized=null) |
|
| 54 | + public function __construct($value, $serialized = null) |
|
| 55 | 55 | { |
| 56 | - if(is_array($serialized)) |
|
| 56 | + if (is_array($serialized)) |
|
| 57 | 57 | { |
| 58 | 58 | $this->parseSerialized($serialized); |
| 59 | 59 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->value = $value; |
| 102 | 102 | $this->type = strtolower(gettype($value)); |
| 103 | 103 | |
| 104 | - if(is_array($value) && is_callable($value)) { |
|
| 104 | + if (is_array($value) && is_callable($value)) { |
|
| 105 | 105 | $this->type = self::TYPE_CALLABLE; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param bool $enable |
| 135 | 135 | * @return VariableInfo |
| 136 | 136 | */ |
| 137 | - public function enableType(bool $enable=true) : VariableInfo |
|
| 137 | + public function enableType(bool $enable = true) : VariableInfo |
|
| 138 | 138 | { |
| 139 | 139 | return $this->setOption('prepend-type', $enable); |
| 140 | 140 | } |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | $converted = $this->string; |
| 145 | 145 | |
| 146 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 146 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 147 | 147 | { |
| 148 | - if($this->isString()) |
|
| 148 | + if ($this->isString()) |
|
| 149 | 149 | { |
| 150 | 150 | $converted = '"'.$converted.'"'; |
| 151 | 151 | } |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $converted = $this->$varMethod(); |
| 179 | 179 | |
| 180 | - if($format === 'HTML') |
|
| 180 | + if ($format === 'HTML') |
|
| 181 | 181 | { |
| 182 | 182 | $converted = '<span style="color:#'.self::$colors[$type].'" class="variable-value-'.$this->type.'">'.$converted.'</span>'; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 185 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 186 | 186 | { |
| 187 | 187 | $typeLabel = $type; |
| 188 | 188 | |
| 189 | - switch($format) |
|
| 189 | + switch ($format) |
|
| 190 | 190 | { |
| 191 | 191 | case 'HTML': |
| 192 | 192 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$type.'</span> '; |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | |
| 216 | 216 | // the array may not be encodable - for example if it contains |
| 217 | 217 | // broken unicode characters. |
| 218 | - if(is_string($result) && $result !== '') { |
|
| 218 | + if (is_string($result) && $result !== '') { |
|
| 219 | 219 | return $result; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | { |
| 227 | 227 | $string = ''; |
| 228 | 228 | |
| 229 | - if(is_string($this->value[0])) { |
|
| 229 | + if (is_string($this->value[0])) { |
|
| 230 | 230 | $string .= $this->value[0].'::'; |
| 231 | 231 | } else { |
| 232 | 232 | $string .= get_class($this->value[0]).'->'; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | str_replace(' ', '-', $this->type) |
| 354 | 354 | ); |
| 355 | 355 | |
| 356 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 356 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 357 | 357 | { |
| 358 | 358 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$this->type.'</span> '; |
| 359 | 359 | $converted = $typeLabel.' '.$converted; |