Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
* 4.4:
  Leverage str_contains/str_starts_with
  Leverage str_ends_with
  • Loading branch information
nicolas-grekas committed Jul 21, 2021
2 parents f1b7140 + 030c59d commit abc5571
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gitignore.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ private static function lineToRegex(string $gitignoreLine): string

return ($isAbsolute ? '' : '(?:[^/]+/)*')
.$regex
.('/' !== substr($gitignoreLine, -1) ? '(?:$|/)' : '');
.(!str_ends_with($gitignoreLine, '/') ? '(?:$|/)' : '');
}
}
2 changes: 1 addition & 1 deletion Iterator/ExcludeDirectoryFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(\Iterator $iterator, array $directories)
$patterns = [];
foreach ($directories as $directory) {
$directory = rtrim($directory, '/');
if (!$this->isRecursive || false !== strpos($directory, '/')) {
if (!$this->isRecursive || str_contains($directory, '/')) {
$patterns[] = preg_quote($directory, '#');
} else {
$this->excludedDirs[$directory] = true;
Expand Down
2 changes: 1 addition & 1 deletion Tests/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ public function testSortAcrossDirectories()
public function testFilter()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); }));
$this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return str_contains($f, 'test'); }));
$this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Iterator/CustomFilterIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getAcceptData()
{
return [
[[function (\SplFileInfo $fileinfo) { return false; }], []],
[[function (\SplFileInfo $fileinfo) { return 0 === strpos($fileinfo, 'test'); }], ['test.php', 'test.py']],
[[function (\SplFileInfo $fileinfo) { return str_starts_with($fileinfo, 'test'); }], ['test.php', 'test.py']],
[['is_dir'], []],
];
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Iterator/MockSplFileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($param)
public function isFile(): bool
{
if (null === $this->type) {
return false !== strpos($this->getFilename(), 'file');
return str_contains($this->getFilename(), 'file');
}

return self::TYPE_FILE === $this->type;
Expand All @@ -60,7 +60,7 @@ public function isFile(): bool
public function isDir(): bool
{
if (null === $this->type) {
return false !== strpos($this->getFilename(), 'directory');
return str_contains($this->getFilename(), 'directory');
}

return self::TYPE_DIRECTORY === $this->type;
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
}
],
"require": {
"php": ">=7.2.5"
"php": ">=7.2.5",
"symfony/polyfill-php80": "^1.16"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Finder\\": "" },
Expand Down

0 comments on commit abc5571

Please sign in to comment.