diff --git a/Comparator/NumberComparator.php b/Comparator/NumberComparator.php index ff85d967..dd308207 100644 --- a/Comparator/NumberComparator.php +++ b/Comparator/NumberComparator.php @@ -35,7 +35,7 @@ class NumberComparator extends Comparator { /** - * @param string|int $test A comparison string or an integer + * @param string|null $test A comparison string or null * * @throws \InvalidArgumentException If the test is not understood */ diff --git a/Iterator/ExcludeDirectoryFilterIterator.php b/Iterator/ExcludeDirectoryFilterIterator.php index d9e182c1..39797c82 100644 --- a/Iterator/ExcludeDirectoryFilterIterator.php +++ b/Iterator/ExcludeDirectoryFilterIterator.php @@ -17,6 +17,7 @@ * @author Fabien Potencier * * @extends \FilterIterator + * * @implements \RecursiveIterator */ class ExcludeDirectoryFilterIterator extends \FilterIterator implements \RecursiveIterator diff --git a/Iterator/MultiplePcreFilterIterator.php b/Iterator/MultiplePcreFilterIterator.php index 99051724..564765d8 100644 --- a/Iterator/MultiplePcreFilterIterator.php +++ b/Iterator/MultiplePcreFilterIterator.php @@ -84,7 +84,13 @@ protected function isAccepted(string $string) */ protected function isRegex(string $str) { - if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) { + $availableModifiers = 'imsxuADU'; + + if (\PHP_VERSION_ID >= 80200) { + $availableModifiers .= 'n'; + } + + if (preg_match('/^(.{3,}?)['.$availableModifiers.']*$/', $str, $m)) { $start = substr($m[1], 0, 1); $end = substr($m[1], -1); diff --git a/LICENSE b/LICENSE index 88bf75bb..0138f8f0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2022 Fabien Potencier +Copyright (c) 2004-present Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/Comparator/ComparatorTest.php b/Tests/Comparator/ComparatorTest.php index a04cc62f..aee59251 100644 --- a/Tests/Comparator/ComparatorTest.php +++ b/Tests/Comparator/ComparatorTest.php @@ -65,7 +65,7 @@ public function testTestSucceeds(string $operator, string $target, string $teste $this->assertTrue($c->test($testedValue)); } - public function provideMatches(): array + public static function provideMatches(): array { return [ ['<', '1000', '500'], @@ -91,7 +91,7 @@ public function testTestFails(string $operator, string $target, string $testedVa $this->assertFalse($c->test($testedValue)); } - public function provideNonMatches(): array + public static function provideNonMatches(): array { return [ ['>', '1000', '500'], diff --git a/Tests/Comparator/DateComparatorTest.php b/Tests/Comparator/DateComparatorTest.php index f89a1a28..47bcc483 100644 --- a/Tests/Comparator/DateComparatorTest.php +++ b/Tests/Comparator/DateComparatorTest.php @@ -49,7 +49,7 @@ public function testTest($test, $match, $noMatch) } } - public function getTestData() + public static function getTestData() { return [ ['< 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]], diff --git a/Tests/Comparator/NumberComparatorTest.php b/Tests/Comparator/NumberComparatorTest.php index 6458133e..60c5f1c6 100644 --- a/Tests/Comparator/NumberComparatorTest.php +++ b/Tests/Comparator/NumberComparatorTest.php @@ -51,7 +51,7 @@ public function testTest($test, $match, $noMatch) } } - public function getTestData() + public static function getTestData() { return [ ['< 1000', ['500', '999'], ['1000', '1500']], @@ -81,7 +81,7 @@ public function getTestData() ]; } - public function getConstructorTestData() + public static function getConstructorTestData() { return [ [ diff --git a/Tests/FinderTest.php b/Tests/FinderTest.php index cb180e8f..183a09cf 100644 --- a/Tests/FinderTest.php +++ b/Tests/FinderTest.php @@ -1274,7 +1274,7 @@ public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartF $this->assertIterator($this->toAbsoluteFixtures($expected), $finder); } - public function getContainsTestData() + public static function getContainsTestData() { return [ ['', '', []], @@ -1292,7 +1292,7 @@ public function getContainsTestData() ]; } - public function getRegexNameTestData() + public static function getRegexNameTestData() { return [ ['~.*t\\.p.+~i'], @@ -1313,7 +1313,7 @@ public function testPath($matchPatterns, $noMatchPatterns, array $expected) $this->assertIterator($this->toAbsoluteFixtures($expected), $finder); } - public function getTestPathData() + public static function getTestPathData() { return [ ['', '', []], @@ -1338,12 +1338,12 @@ public function getTestPathData() ], ['A/B', 'foobar', [ - //dirs + // dirs 'A'.\DIRECTORY_SEPARATOR.'B', 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C', 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B', 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C', - //files + // files 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat', 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat', 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat.copy', diff --git a/Tests/Fixtures/gitignore/search_root/a.txt b/Tests/Fixtures/gitignore/search_root/a.txt new file mode 100644 index 00000000..e69de29b diff --git a/Tests/Fixtures/gitignore/search_root/c.txt b/Tests/Fixtures/gitignore/search_root/c.txt new file mode 100644 index 00000000..e69de29b diff --git a/Tests/Fixtures/gitignore/search_root/dir/b.txt b/Tests/Fixtures/gitignore/search_root/dir/b.txt new file mode 100644 index 00000000..e69de29b diff --git a/Tests/Fixtures/gitignore/search_root/dir/c.txt b/Tests/Fixtures/gitignore/search_root/dir/c.txt new file mode 100644 index 00000000..e69de29b diff --git a/Tests/GitignoreTest.php b/Tests/GitignoreTest.php index 76806407..574e9f32 100644 --- a/Tests/GitignoreTest.php +++ b/Tests/GitignoreTest.php @@ -1,4 +1,5 @@ provider(); + $basicCases = self::provider(); $cases = []; foreach ($basicCases as $case) { @@ -478,7 +479,7 @@ public function testToRegexMatchingNegatedPatterns(array $gitignoreLines, array } } - public function provideNegatedPatternsCases(): iterable + public static function provideNegatedPatternsCases(): iterable { yield [ [''], @@ -822,7 +823,7 @@ public function provideNegatedPatternsCases(): iterable '!logs/important.log', ], [], - ['logs/debug.log'/* must be pruned on traversal 'logs/important.log'*/], + ['logs/debug.log'/* must be pruned on traversal 'logs/important.log' */], ]; yield [ diff --git a/Tests/Iterator/CustomFilterIteratorTest.php b/Tests/Iterator/CustomFilterIteratorTest.php index 7c3c65ce..3b1f662e 100644 --- a/Tests/Iterator/CustomFilterIteratorTest.php +++ b/Tests/Iterator/CustomFilterIteratorTest.php @@ -33,7 +33,7 @@ public function testAccept($filters, $expected) $this->assertIterator($expected, $iterator); } - public function getAcceptData() + public static function getAcceptData() { return [ [[function (\SplFileInfo $fileinfo) { return false; }], []], diff --git a/Tests/Iterator/DateRangeFilterIteratorTest.php b/Tests/Iterator/DateRangeFilterIteratorTest.php index 2d8cfb30..b02d8f4f 100644 --- a/Tests/Iterator/DateRangeFilterIteratorTest.php +++ b/Tests/Iterator/DateRangeFilterIteratorTest.php @@ -22,7 +22,7 @@ class DateRangeFilterIteratorTest extends RealIteratorTestCase public function testAccept($size, $expected) { $files = self::$files; - $files[] = self::toAbsolute('doesnotexist'); + $files[] = static::toAbsolute('doesnotexist'); $inner = new Iterator($files); $iterator = new DateRangeFilterIterator($inner, $size); @@ -30,7 +30,7 @@ public function testAccept($size, $expected) $this->assertIterator($expected, $iterator); } - public function getAcceptData() + public static function getAcceptData() { $since20YearsAgo = [ '.git', @@ -84,9 +84,9 @@ public function getAcceptData() ]; return [ - [[new DateComparator('since 20 years ago')], $this->toAbsolute($since20YearsAgo)], - [[new DateComparator('since 2 months ago')], $this->toAbsolute($since2MonthsAgo)], - [[new DateComparator('until last month')], $this->toAbsolute($untilLastMonth)], + [[new DateComparator('since 20 years ago')], static::toAbsolute($since20YearsAgo)], + [[new DateComparator('since 2 months ago')], static::toAbsolute($since2MonthsAgo)], + [[new DateComparator('until last month')], static::toAbsolute($untilLastMonth)], ]; } } diff --git a/Tests/Iterator/DepthRangeFilterIteratorTest.php b/Tests/Iterator/DepthRangeFilterIteratorTest.php index b2a5303b..c90df8ec 100644 --- a/Tests/Iterator/DepthRangeFilterIteratorTest.php +++ b/Tests/Iterator/DepthRangeFilterIteratorTest.php @@ -30,7 +30,7 @@ public function testAccept($minDepth, $maxDepth, $expected) $this->assertEquals($expected, $actual); } - public function getAcceptData() + public static function getAcceptData() { $lessThan1 = [ '.git', @@ -93,11 +93,11 @@ public function getAcceptData() ]; return [ - [0, 0, $this->toAbsolute($lessThan1)], - [0, 1, $this->toAbsolute($lessThanOrEqualTo1)], + [0, 0, self::toAbsolute($lessThan1)], + [0, 1, self::toAbsolute($lessThanOrEqualTo1)], [2, \PHP_INT_MAX, []], - [1, \PHP_INT_MAX, $this->toAbsolute($graterThanOrEqualTo1)], - [1, 1, $this->toAbsolute($equalTo1)], + [1, \PHP_INT_MAX, self::toAbsolute($graterThanOrEqualTo1)], + [1, 1, self::toAbsolute($equalTo1)], ]; } } diff --git a/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php b/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php index 1729766f..9b5ed98a 100644 --- a/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php +++ b/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php @@ -28,7 +28,7 @@ public function testAccept($directories, $expected) $this->assertIterator($expected, $iterator); } - public function getAcceptData() + public static function getAcceptData() { $foo = [ '.bar', @@ -99,9 +99,9 @@ public function getAcceptData() ]; return [ - [['foo'], $this->toAbsolute($foo)], - [['fo'], $this->toAbsolute($fo)], - [['toto/'], $this->toAbsolute($toto)], + [['foo'], self::toAbsolute($foo)], + [['fo'], self::toAbsolute($fo)], + [['toto/'], self::toAbsolute($toto)], ]; } } diff --git a/Tests/Iterator/FileTypeFilterIteratorTest.php b/Tests/Iterator/FileTypeFilterIteratorTest.php index e15c0352..3ed1cc06 100644 --- a/Tests/Iterator/FileTypeFilterIteratorTest.php +++ b/Tests/Iterator/FileTypeFilterIteratorTest.php @@ -27,7 +27,7 @@ public function testAccept($mode, $expected) $this->assertIterator($expected, $iterator); } - public function getAcceptData() + public static function getAcceptData() { $onlyFiles = [ 'test.py', @@ -57,8 +57,8 @@ public function getAcceptData() ]; return [ - [FileTypeFilterIterator::ONLY_FILES, $this->toAbsolute($onlyFiles)], - [FileTypeFilterIterator::ONLY_DIRECTORIES, $this->toAbsolute($onlyDirectories)], + [FileTypeFilterIterator::ONLY_FILES, self::toAbsolute($onlyFiles)], + [FileTypeFilterIterator::ONLY_DIRECTORIES, self::toAbsolute($onlyDirectories)], ]; } } diff --git a/Tests/Iterator/FilecontentFilterIteratorTest.php b/Tests/Iterator/FilecontentFilterIteratorTest.php index f4f70c8e..34ba50dd 100644 --- a/Tests/Iterator/FilecontentFilterIteratorTest.php +++ b/Tests/Iterator/FilecontentFilterIteratorTest.php @@ -45,7 +45,7 @@ public function testFilter(\Iterator $inner, array $matchPatterns, array $noMatc $this->assertIterator($resultArray, $iterator); } - public function getTestFilterData() + public static function getTestFilterData() { $inner = new MockFileListIterator(); diff --git a/Tests/Iterator/FilenameFilterIteratorTest.php b/Tests/Iterator/FilenameFilterIteratorTest.php index a12072c6..db4eb2b9 100644 --- a/Tests/Iterator/FilenameFilterIteratorTest.php +++ b/Tests/Iterator/FilenameFilterIteratorTest.php @@ -27,7 +27,7 @@ public function testAccept($matchPatterns, $noMatchPatterns, $expected) $this->assertIterator($expected, $iterator); } - public function getAcceptData() + public static function getAcceptData() { return [ [['test.*'], [], ['test.php', 'test.py']], diff --git a/Tests/Iterator/MultiplePcreFilterIteratorTest.php b/Tests/Iterator/MultiplePcreFilterIteratorTest.php index d7059b5e..e6abf944 100644 --- a/Tests/Iterator/MultiplePcreFilterIteratorTest.php +++ b/Tests/Iterator/MultiplePcreFilterIteratorTest.php @@ -25,26 +25,28 @@ public function testIsRegex($string, $isRegex, $message) $this->assertEquals($isRegex, $testIterator->isRegex($string), $message); } - public function getIsRegexFixtures() + public static function getIsRegexFixtures() { - return [ - ['foo', false, 'string'], - [' foo ', false, '" " is not a valid delimiter'], - ['\\foo\\', false, '"\\" is not a valid delimiter'], - ['afooa', false, '"a" is not a valid delimiter'], - ['//', false, 'the pattern should contain at least 1 character'], - ['/a/', true, 'valid regex'], - ['/foo/', true, 'valid regex'], - ['/foo/i', true, 'valid regex with a single modifier'], - ['/foo/imsxu', true, 'valid regex with multiple modifiers'], - ['#foo#', true, '"#" is a valid delimiter'], - ['{foo}', true, '"{,}" is a valid delimiter pair'], - ['[foo]', true, '"[,]" is a valid delimiter pair'], - ['(foo)', true, '"(,)" is a valid delimiter pair'], - ['', true, '"<,>" is a valid delimiter pair'], - ['*foo.*', false, '"*" is not considered as a valid delimiter'], - ['?foo.?', false, '"?" is not considered as a valid delimiter'], - ]; + yield ['foo', false, 'string']; + yield [' foo ', false, '" " is not a valid delimiter']; + yield ['\\foo\\', false, '"\\" is not a valid delimiter']; + yield ['afooa', false, '"a" is not a valid delimiter']; + yield ['//', false, 'the pattern should contain at least 1 character']; + yield ['/a/', true, 'valid regex']; + yield ['/foo/', true, 'valid regex']; + yield ['/foo/i', true, 'valid regex with a single modifier']; + yield ['/foo/imsxu', true, 'valid regex with multiple modifiers']; + yield ['#foo#', true, '"#" is a valid delimiter']; + yield ['{foo}', true, '"{,}" is a valid delimiter pair']; + yield ['[foo]', true, '"[,]" is a valid delimiter pair']; + yield ['(foo)', true, '"(,)" is a valid delimiter pair']; + yield ['', true, '"<,>" is a valid delimiter pair']; + yield ['*foo.*', false, '"*" is not considered as a valid delimiter']; + yield ['?foo.?', false, '"?" is not considered as a valid delimiter']; + + if (\PHP_VERSION_ID >= 80200) { + yield ['/foo/n', true, 'valid regex with the no-capture modifier']; + } } } diff --git a/Tests/Iterator/PathFilterIteratorTest.php b/Tests/Iterator/PathFilterIteratorTest.php index 9040ee04..5c0663e5 100644 --- a/Tests/Iterator/PathFilterIteratorTest.php +++ b/Tests/Iterator/PathFilterIteratorTest.php @@ -24,41 +24,41 @@ public function testFilter(\Iterator $inner, array $matchPatterns, array $noMatc $this->assertIterator($resultArray, $iterator); } - public function getTestFilterData() + public static function getTestFilterData() { $inner = new MockFileListIterator(); - //PATH: A/B/C/abc.dat + // PATH: A/B/C/abc.dat $inner[] = new MockSplFileInfo([ 'name' => 'abc.dat', 'relativePathname' => 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat', ]); - //PATH: A/B/ab.dat + // PATH: A/B/ab.dat $inner[] = new MockSplFileInfo([ 'name' => 'ab.dat', 'relativePathname' => 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat', ]); - //PATH: A/a.dat + // PATH: A/a.dat $inner[] = new MockSplFileInfo([ 'name' => 'a.dat', 'relativePathname' => 'A'.\DIRECTORY_SEPARATOR.'a.dat', ]); - //PATH: copy/A/B/C/abc.dat.copy + // PATH: copy/A/B/C/abc.dat.copy $inner[] = new MockSplFileInfo([ 'name' => 'abc.dat.copy', 'relativePathname' => 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat', ]); - //PATH: copy/A/B/ab.dat.copy + // PATH: copy/A/B/ab.dat.copy $inner[] = new MockSplFileInfo([ 'name' => 'ab.dat.copy', 'relativePathname' => 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat', ]); - //PATH: copy/A/a.dat.copy + // PATH: copy/A/a.dat.copy $inner[] = new MockSplFileInfo([ 'name' => 'a.dat.copy', 'relativePathname' => 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'a.dat', diff --git a/Tests/Iterator/RealIteratorTestCase.php b/Tests/Iterator/RealIteratorTestCase.php index ac998d00..8b727f4c 100644 --- a/Tests/Iterator/RealIteratorTestCase.php +++ b/Tests/Iterator/RealIteratorTestCase.php @@ -70,9 +70,9 @@ public static function setUpBeforeClass(): void public static function tearDownAfterClass(): void { $paths = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator(self::$tmpDir, \RecursiveDirectoryIterator::SKIP_DOTS), - \RecursiveIteratorIterator::CHILD_FIRST - ); + new \RecursiveDirectoryIterator(self::$tmpDir, \RecursiveDirectoryIterator::SKIP_DOTS), + \RecursiveIteratorIterator::CHILD_FIRST + ); foreach ($paths as $path) { if ($path->isDir()) { diff --git a/Tests/Iterator/SizeRangeFilterIteratorTest.php b/Tests/Iterator/SizeRangeFilterIteratorTest.php index 129d565d..e5f3b6a1 100644 --- a/Tests/Iterator/SizeRangeFilterIteratorTest.php +++ b/Tests/Iterator/SizeRangeFilterIteratorTest.php @@ -28,7 +28,7 @@ public function testAccept($size, $expected) $this->assertIterator($expected, $iterator); } - public function getAcceptData() + public static function getAcceptData() { $lessThan1KGreaterThan05K = [ '.foo', @@ -41,7 +41,7 @@ public function getAcceptData() ]; return [ - [[new NumberComparator('< 1K'), new NumberComparator('> 0.5K')], $this->toAbsolute($lessThan1KGreaterThan05K)], + [[new NumberComparator('< 1K'), new NumberComparator('> 0.5K')], self::toAbsolute($lessThan1KGreaterThan05K)], ]; } } diff --git a/Tests/Iterator/SortableIteratorTest.php b/Tests/Iterator/SortableIteratorTest.php index 098cd756..a4f13fee 100644 --- a/Tests/Iterator/SortableIteratorTest.php +++ b/Tests/Iterator/SortableIteratorTest.php @@ -68,7 +68,7 @@ public function testAccept($mode, $expected) } } - public function getAcceptData() + public static function getAcceptData() { $sortByName = [ '.bar', @@ -247,13 +247,13 @@ public function getAcceptData() ]; return [ - [SortableIterator::SORT_BY_NAME, $this->toAbsolute($sortByName)], - [SortableIterator::SORT_BY_TYPE, $this->toAbsolute($sortByType)], - [SortableIterator::SORT_BY_ACCESSED_TIME, $this->toAbsolute($sortByAccessedTime)], - [SortableIterator::SORT_BY_CHANGED_TIME, $this->toAbsolute($sortByChangedTime)], - [SortableIterator::SORT_BY_MODIFIED_TIME, $this->toAbsolute($sortByModifiedTime)], - [SortableIterator::SORT_BY_NAME_NATURAL, $this->toAbsolute($sortByNameNatural)], - [function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, $this->toAbsolute($customComparison)], + [SortableIterator::SORT_BY_NAME, self::toAbsolute($sortByName)], + [SortableIterator::SORT_BY_TYPE, self::toAbsolute($sortByType)], + [SortableIterator::SORT_BY_ACCESSED_TIME, self::toAbsolute($sortByAccessedTime)], + [SortableIterator::SORT_BY_CHANGED_TIME, self::toAbsolute($sortByChangedTime)], + [SortableIterator::SORT_BY_MODIFIED_TIME, self::toAbsolute($sortByModifiedTime)], + [SortableIterator::SORT_BY_NAME_NATURAL, self::toAbsolute($sortByNameNatural)], + [function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, self::toAbsolute($customComparison)], ]; } } diff --git a/Tests/Iterator/VcsIgnoredFilterIteratorTest.php b/Tests/Iterator/VcsIgnoredFilterIteratorTest.php index 14cb3c44..61da148d 100644 --- a/Tests/Iterator/VcsIgnoredFilterIteratorTest.php +++ b/Tests/Iterator/VcsIgnoredFilterIteratorTest.php @@ -59,7 +59,7 @@ public function testAccept(array $gitIgnoreFiles, array $otherFileNames, array $ $this->assertIterator($this->toAbsolute($expectedResult), $iterator); } - public function getAcceptData(): iterable + public static function getAcceptData(): iterable { yield 'simple file' => [ [