@@ -23,29 +23,29 @@ |
||
23 | 23 | * |
24 | 24 | * @throws \InvalidArgumentException If the test is not understood |
25 | 25 | */ |
26 | - public function __construct(string $test) |
|
26 | + public function __construct( string $test ) |
|
27 | 27 | { |
28 | - if (!preg_match('#^\s*(==|!=|[<>]=?|after|since|before|until)?\s*(.+?)\s*$#i', $test, $matches)) { |
|
29 | - throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test)); |
|
28 | + if ( ! preg_match( '#^\s*(==|!=|[<>]=?|after|since|before|until)?\s*(.+?)\s*$#i', $test, $matches ) ) { |
|
29 | + throw new \InvalidArgumentException( sprintf( 'Don\'t understand "%s" as a date test.', $test ) ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | try { |
33 | - $date = new \DateTime($matches[2]); |
|
34 | - $target = $date->format('U'); |
|
35 | - } catch (\Exception $e) { |
|
36 | - throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2])); |
|
33 | + $date = new \DateTime( $matches[ 2 ] ); |
|
34 | + $target = $date->format( 'U' ); |
|
35 | + } catch ( \Exception $e ) { |
|
36 | + throw new \InvalidArgumentException( sprintf( '"%s" is not a valid date.', $matches[ 2 ] ) ); |
|
37 | 37 | } |
38 | 38 | |
39 | - $operator = $matches[1] ?? '=='; |
|
40 | - if ('since' === $operator || 'after' === $operator) { |
|
39 | + $operator = $matches[ 1 ] ?? '=='; |
|
40 | + if ( 'since' === $operator || 'after' === $operator ) { |
|
41 | 41 | $operator = '>'; |
42 | 42 | } |
43 | 43 | |
44 | - if ('until' === $operator || 'before' === $operator) { |
|
44 | + if ( 'until' === $operator || 'before' === $operator ) { |
|
45 | 45 | $operator = '<'; |
46 | 46 | } |
47 | 47 | |
48 | - $this->setOperator($operator); |
|
49 | - $this->setTarget($target); |
|
48 | + $this->setOperator( $operator ); |
|
49 | + $this->setTarget( $target ); |
|
50 | 50 | } |
51 | 51 | } |
@@ -39,19 +39,19 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @throws \InvalidArgumentException If the test is not understood |
41 | 41 | */ |
42 | - public function __construct(?string $test) |
|
42 | + public function __construct( ?string $test ) |
|
43 | 43 | { |
44 | - if (null === $test || !preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) { |
|
45 | - throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test ?? 'null')); |
|
44 | + if ( null === $test || ! preg_match( '#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches ) ) { |
|
45 | + throw new \InvalidArgumentException( sprintf( 'Don\'t understand "%s" as a number test.', $test ?? 'null' ) ); |
|
46 | 46 | } |
47 | 47 | |
48 | - $target = $matches[2]; |
|
49 | - if (!is_numeric($target)) { |
|
50 | - throw new \InvalidArgumentException(sprintf('Invalid number "%s".', $target)); |
|
48 | + $target = $matches[ 2 ]; |
|
49 | + if ( ! is_numeric( $target ) ) { |
|
50 | + throw new \InvalidArgumentException( sprintf( 'Invalid number "%s".', $target ) ); |
|
51 | 51 | } |
52 | - if (isset($matches[3])) { |
|
52 | + if ( isset( $matches[ 3 ] ) ) { |
|
53 | 53 | // magnitude |
54 | - switch (strtolower($matches[3])) { |
|
54 | + switch ( strtolower( $matches[ 3 ] ) ) { |
|
55 | 55 | case 'k': |
56 | 56 | $target *= 1000; |
57 | 57 | break; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | - $this->setTarget($target); |
|
77 | - $this->setOperator($matches[1] ?? '=='); |
|
76 | + $this->setTarget( $target ); |
|
77 | + $this->setOperator( $matches[ 1 ] ?? '==' ); |
|
78 | 78 | } |
79 | 79 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | return $this->target; |
32 | 32 | } |
33 | 33 | |
34 | - public function setTarget(string $target) |
|
34 | + public function setTarget( string $target ) |
|
35 | 35 | { |
36 | 36 | $this->target = $target; |
37 | 37 | } |
@@ -51,14 +51,14 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @throws \InvalidArgumentException |
53 | 53 | */ |
54 | - public function setOperator(string $operator) |
|
54 | + public function setOperator( string $operator ) |
|
55 | 55 | { |
56 | - if ('' === $operator) { |
|
56 | + if ( '' === $operator ) { |
|
57 | 57 | $operator = '=='; |
58 | 58 | } |
59 | 59 | |
60 | - if (!\in_array($operator, ['>', '<', '>=', '<=', '==', '!='])) { |
|
61 | - throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator)); |
|
60 | + if ( ! \in_array( $operator, [ '>', '<', '>=', '<=', '==', '!=' ] ) ) { |
|
61 | + throw new \InvalidArgumentException( sprintf( 'Invalid operator "%s".', $operator ) ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | $this->operator = $operator; |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return bool |
73 | 73 | */ |
74 | - public function test($test) |
|
74 | + public function test( $test ) |
|
75 | 75 | { |
76 | - switch ($this->operator) { |
|
76 | + switch ( $this->operator ) { |
|
77 | 77 | case '>': |
78 | 78 | return $test > $this->target; |
79 | 79 | case '>=': |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | * @param string $relativePath The relative path |
27 | 27 | * @param string $relativePathname The relative path name |
28 | 28 | */ |
29 | - public function __construct(string $file, string $relativePath, string $relativePathname) |
|
29 | + public function __construct( string $file, string $relativePath, string $relativePathname ) |
|
30 | 30 | { |
31 | - parent::__construct($file); |
|
31 | + parent::__construct( $file ); |
|
32 | 32 | $this->relativePath = $relativePath; |
33 | 33 | $this->relativePathname = $relativePathname; |
34 | 34 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | { |
62 | 62 | $filename = $this->getFilename(); |
63 | 63 | |
64 | - return pathinfo($filename, \PATHINFO_FILENAME); |
|
64 | + return pathinfo( $filename, \PATHINFO_FILENAME ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function getContents() |
75 | 75 | { |
76 | - set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; }); |
|
77 | - $content = file_get_contents($this->getPathname()); |
|
76 | + set_error_handler( function( $type, $msg ) use ( &$error ) { $error = $msg; }); |
|
77 | + $content = file_get_contents( $this->getPathname() ); |
|
78 | 78 | restore_error_handler(); |
79 | - if (false === $content) { |
|
80 | - throw new \RuntimeException($error); |
|
79 | + if ( false === $content ) { |
|
80 | + throw new \RuntimeException( $error ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | return $content; |
@@ -20,31 +20,31 @@ discard block |
||
20 | 20 | { |
21 | 21 | private $iterator; |
22 | 22 | private $isRecursive; |
23 | - private $excludedDirs = []; |
|
23 | + private $excludedDirs = [ ]; |
|
24 | 24 | private $excludedPattern; |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param \Iterator $iterator The Iterator to filter |
28 | 28 | * @param string[] $directories An array of directories to exclude |
29 | 29 | */ |
30 | - public function __construct(\Iterator $iterator, array $directories) |
|
30 | + public function __construct( \Iterator $iterator, array $directories ) |
|
31 | 31 | { |
32 | 32 | $this->iterator = $iterator; |
33 | 33 | $this->isRecursive = $iterator instanceof \RecursiveIterator; |
34 | - $patterns = []; |
|
35 | - foreach ($directories as $directory) { |
|
36 | - $directory = rtrim($directory, '/'); |
|
37 | - if (!$this->isRecursive || str_contains($directory, '/')) { |
|
38 | - $patterns[] = preg_quote($directory, '#'); |
|
34 | + $patterns = [ ]; |
|
35 | + foreach ( $directories as $directory ) { |
|
36 | + $directory = rtrim( $directory, '/' ); |
|
37 | + if ( ! $this->isRecursive || str_contains( $directory, '/' ) ) { |
|
38 | + $patterns[ ] = preg_quote( $directory, '#' ); |
|
39 | 39 | } else { |
40 | - $this->excludedDirs[$directory] = true; |
|
40 | + $this->excludedDirs[ $directory ] = true; |
|
41 | 41 | } |
42 | 42 | } |
43 | - if ($patterns) { |
|
44 | - $this->excludedPattern = '#(?:^|/)(?:'.implode('|', $patterns).')(?:/|$)#'; |
|
43 | + if ( $patterns ) { |
|
44 | + $this->excludedPattern = '#(?:^|/)(?:' . implode( '|', $patterns ) . ')(?:/|$)#'; |
|
45 | 45 | } |
46 | 46 | |
47 | - parent::__construct($iterator); |
|
47 | + parent::__construct( $iterator ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | #[\ReturnTypeWillChange] |
56 | 56 | public function accept() |
57 | 57 | { |
58 | - if ($this->isRecursive && isset($this->excludedDirs[$this->getFilename()]) && $this->isDir()) { |
|
58 | + if ( $this->isRecursive && isset( $this->excludedDirs[ $this->getFilename() ] ) && $this->isDir() ) { |
|
59 | 59 | return false; |
60 | 60 | } |
61 | 61 | |
62 | - if ($this->excludedPattern) { |
|
62 | + if ( $this->excludedPattern ) { |
|
63 | 63 | $path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath(); |
64 | - $path = str_replace('\\', '/', $path); |
|
64 | + $path = str_replace( '\\', '/', $path ); |
|
65 | 65 | |
66 | - return !preg_match($this->excludedPattern, $path); |
|
66 | + return ! preg_match( $this->excludedPattern, $path ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return true; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | #[\ReturnTypeWillChange] |
85 | 85 | public function getChildren() |
86 | 86 | { |
87 | - $children = new self($this->iterator->getChildren(), []); |
|
87 | + $children = new self( $this->iterator->getChildren(), [ ] ); |
|
88 | 88 | $children->excludedDirs = $this->excludedDirs; |
89 | 89 | $children->excludedPattern = $this->excludedPattern; |
90 | 90 |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | #[\ReturnTypeWillChange] |
28 | 28 | public function accept() |
29 | 29 | { |
30 | - if (!$this->matchRegexps && !$this->noMatchRegexps) { |
|
30 | + if ( ! $this->matchRegexps && ! $this->noMatchRegexps ) { |
|
31 | 31 | return true; |
32 | 32 | } |
33 | 33 | |
34 | 34 | $fileinfo = $this->current(); |
35 | 35 | |
36 | - if ($fileinfo->isDir() || !$fileinfo->isReadable()) { |
|
36 | + if ( $fileinfo->isDir() || ! $fileinfo->isReadable() ) { |
|
37 | 37 | return false; |
38 | 38 | } |
39 | 39 | |
40 | 40 | $content = $fileinfo->getContents(); |
41 | - if (!$content) { |
|
41 | + if ( ! $content ) { |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | |
45 | - return $this->isAccepted($content); |
|
45 | + return $this->isAccepted( $content ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return string regexp corresponding to a given string or regexp |
54 | 54 | */ |
55 | - protected function toRegex(string $str) |
|
55 | + protected function toRegex( string $str ) |
|
56 | 56 | { |
57 | - return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/'; |
|
57 | + return $this->isRegex( $str ) ? $str : '/' . preg_quote( $str, '/' ) . '/'; |
|
58 | 58 | } |
59 | 59 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | #[\ReturnTypeWillChange] |
29 | 29 | public function accept() |
30 | 30 | { |
31 | - return $this->isAccepted($this->current()->getFilename()); |
|
31 | + return $this->isAccepted( $this->current()->getFilename() ); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return string regexp corresponding to a given glob or regexp |
43 | 43 | */ |
44 | - protected function toRegex(string $str) |
|
44 | + protected function toRegex( string $str ) |
|
45 | 45 | { |
46 | - return $this->isRegex($str) ? $str : Glob::toRegex($str); |
|
46 | + return $this->isRegex( $str ) ? $str : Glob::toRegex( $str ); |
|
47 | 47 | } |
48 | 48 | } |
@@ -34,47 +34,47 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @throws \InvalidArgumentException |
36 | 36 | */ |
37 | - public function __construct(\Traversable $iterator, $sort, bool $reverseOrder = false) |
|
37 | + public function __construct( \Traversable $iterator, $sort, bool $reverseOrder = false ) |
|
38 | 38 | { |
39 | 39 | $this->iterator = $iterator; |
40 | 40 | $order = $reverseOrder ? -1 : 1; |
41 | 41 | |
42 | - if (self::SORT_BY_NAME === $sort) { |
|
43 | - $this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) { |
|
44 | - return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname()); |
|
42 | + if ( self::SORT_BY_NAME === $sort ) { |
|
43 | + $this->sort = static function( \SplFileInfo $a, \SplFileInfo $b ) use ( $order ) { |
|
44 | + return $order * strcmp( $a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname() ); |
|
45 | 45 | }; |
46 | - } elseif (self::SORT_BY_NAME_NATURAL === $sort) { |
|
47 | - $this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) { |
|
48 | - return $order * strnatcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname()); |
|
46 | + } elseif ( self::SORT_BY_NAME_NATURAL === $sort ) { |
|
47 | + $this->sort = static function( \SplFileInfo $a, \SplFileInfo $b ) use ( $order ) { |
|
48 | + return $order * strnatcmp( $a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname() ); |
|
49 | 49 | }; |
50 | - } elseif (self::SORT_BY_TYPE === $sort) { |
|
51 | - $this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) { |
|
52 | - if ($a->isDir() && $b->isFile()) { |
|
50 | + } elseif ( self::SORT_BY_TYPE === $sort ) { |
|
51 | + $this->sort = static function( \SplFileInfo $a, \SplFileInfo $b ) use ( $order ) { |
|
52 | + if ( $a->isDir() && $b->isFile() ) { |
|
53 | 53 | return -$order; |
54 | - } elseif ($a->isFile() && $b->isDir()) { |
|
54 | + } elseif ( $a->isFile() && $b->isDir() ) { |
|
55 | 55 | return $order; |
56 | 56 | } |
57 | 57 | |
58 | - return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname()); |
|
58 | + return $order * strcmp( $a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname() ); |
|
59 | 59 | }; |
60 | - } elseif (self::SORT_BY_ACCESSED_TIME === $sort) { |
|
61 | - $this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) { |
|
62 | - return $order * ($a->getATime() - $b->getATime()); |
|
60 | + } elseif ( self::SORT_BY_ACCESSED_TIME === $sort ) { |
|
61 | + $this->sort = static function( \SplFileInfo $a, \SplFileInfo $b ) use ( $order ) { |
|
62 | + return $order * ( $a->getATime() - $b->getATime() ); |
|
63 | 63 | }; |
64 | - } elseif (self::SORT_BY_CHANGED_TIME === $sort) { |
|
65 | - $this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) { |
|
66 | - return $order * ($a->getCTime() - $b->getCTime()); |
|
64 | + } elseif ( self::SORT_BY_CHANGED_TIME === $sort ) { |
|
65 | + $this->sort = static function( \SplFileInfo $a, \SplFileInfo $b ) use ( $order ) { |
|
66 | + return $order * ( $a->getCTime() - $b->getCTime() ); |
|
67 | 67 | }; |
68 | - } elseif (self::SORT_BY_MODIFIED_TIME === $sort) { |
|
69 | - $this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) { |
|
70 | - return $order * ($a->getMTime() - $b->getMTime()); |
|
68 | + } elseif ( self::SORT_BY_MODIFIED_TIME === $sort ) { |
|
69 | + $this->sort = static function( \SplFileInfo $a, \SplFileInfo $b ) use ( $order ) { |
|
70 | + return $order * ( $a->getMTime() - $b->getMTime() ); |
|
71 | 71 | }; |
72 | - } elseif (self::SORT_BY_NONE === $sort) { |
|
72 | + } elseif ( self::SORT_BY_NONE === $sort ) { |
|
73 | 73 | $this->sort = $order; |
74 | - } elseif (\is_callable($sort)) { |
|
75 | - $this->sort = $reverseOrder ? static function (\SplFileInfo $a, \SplFileInfo $b) use ($sort) { return -$sort($a, $b); } : $sort; |
|
74 | + } elseif ( \is_callable( $sort ) ) { |
|
75 | + $this->sort = $reverseOrder ? static function( \SplFileInfo $a, \SplFileInfo $b ) use ( $sort ) { return -$sort( $a, $b ); } : $sort; |
|
76 | 76 | } else { |
77 | - throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.'); |
|
77 | + throw new \InvalidArgumentException( 'The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.' ); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -84,18 +84,18 @@ discard block |
||
84 | 84 | #[\ReturnTypeWillChange] |
85 | 85 | public function getIterator() |
86 | 86 | { |
87 | - if (1 === $this->sort) { |
|
87 | + if ( 1 === $this->sort ) { |
|
88 | 88 | return $this->iterator; |
89 | 89 | } |
90 | 90 | |
91 | - $array = iterator_to_array($this->iterator, true); |
|
91 | + $array = iterator_to_array( $this->iterator, true ); |
|
92 | 92 | |
93 | 93 | if (-1 === $this->sort) { |
94 | - $array = array_reverse($array); |
|
94 | + $array = array_reverse( $array ); |
|
95 | 95 | } else { |
96 | - uasort($array, $this->sort); |
|
96 | + uasort( $array, $this->sort ); |
|
97 | 97 | } |
98 | 98 | |
99 | - return new \ArrayIterator($array); |
|
99 | + return new \ArrayIterator( $array ); |
|
100 | 100 | } |
101 | 101 | } |
@@ -20,17 +20,17 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class DateRangeFilterIterator extends \FilterIterator |
22 | 22 | { |
23 | - private $comparators = []; |
|
23 | + private $comparators = [ ]; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @param \Iterator $iterator The Iterator to filter |
27 | 27 | * @param DateComparator[] $comparators An array of DateComparator instances |
28 | 28 | */ |
29 | - public function __construct(\Iterator $iterator, array $comparators) |
|
29 | + public function __construct( \Iterator $iterator, array $comparators ) |
|
30 | 30 | { |
31 | 31 | $this->comparators = $comparators; |
32 | 32 | |
33 | - parent::__construct($iterator); |
|
33 | + parent::__construct( $iterator ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | { |
44 | 44 | $fileinfo = $this->current(); |
45 | 45 | |
46 | - if (!file_exists($fileinfo->getPathname())) { |
|
46 | + if ( ! file_exists( $fileinfo->getPathname() ) ) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
50 | 50 | $filedate = $fileinfo->getMTime(); |
51 | - foreach ($this->comparators as $compare) { |
|
52 | - if (!$compare->test($filedate)) { |
|
51 | + foreach ( $this->comparators as $compare ) { |
|
52 | + if ( ! $compare->test( $filedate ) ) { |
|
53 | 53 | return false; |
54 | 54 | } |
55 | 55 | } |