Skip to content

Commit

Permalink
Leverage str_contains/str_starts_with
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander M. Turek <me@derrabus.de>
  • Loading branch information
derrabus authored and nicolas-grekas committed Jul 21, 2021
1 parent dcbdc31 commit 030c59d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
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

0 comments on commit 030c59d

Please sign in to comment.