-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed sebastian/finder-facade as a dependency and added replacement…
… for PHP8 compatibility (#20)
- Loading branch information
1 parent
c057e46
commit 1560e40
Showing
10 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scheb\Tombstone\Core; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
class FinderFacade | ||
{ | ||
private $items = []; | ||
|
||
private $excludes = []; | ||
|
||
private $names = []; | ||
|
||
private $notNames = []; | ||
|
||
public function __construct(array $items = [], array $excludes = [], array $names = [], array $notNames = []) | ||
{ | ||
$this->items = $items; | ||
$this->excludes = $excludes; | ||
$this->names = $names; | ||
$this->notNames = $notNames; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function findFiles(): array | ||
{ | ||
$files = []; | ||
$finder = new Finder(); | ||
$iterate = false; | ||
|
||
$finder->ignoreUnreadableDirs(); | ||
$finder->sortByName(); | ||
|
||
foreach ($this->items as $item) { | ||
if (!is_file($item)) { | ||
$finder->in($item); | ||
$iterate = true; | ||
} else { | ||
$files[] = realpath($item); | ||
} | ||
} | ||
|
||
foreach ($this->excludes as $exclude) { | ||
$finder->exclude($exclude); | ||
} | ||
|
||
foreach ($this->names as $name) { | ||
$finder->name($name); | ||
} | ||
|
||
foreach ($this->notNames as $notName) { | ||
$finder->notName($notName); | ||
} | ||
|
||
if ($iterate) { | ||
foreach ($finder as $file) { | ||
$files[] = $file->getRealpath(); | ||
} | ||
} | ||
|
||
return $files; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
declare(strict_types=1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
declare(strict_types=1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scheb\Tombstone\Tests\Core; | ||
|
||
use Scheb\Tombstone\Core\FinderFacade; | ||
use Scheb\Tombstone\Tests\TestCase; | ||
|
||
class FinderFacadeTest extends TestCase | ||
{ | ||
private $fixtureDir; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->fixtureDir = __DIR__.DIRECTORY_SEPARATOR.'FinderFacadeFiles'.DIRECTORY_SEPARATOR; | ||
} | ||
|
||
public function testFilesCanBeFoundBasedOnConstructorArguments(): void | ||
{ | ||
$facade = new FinderFacade( | ||
[$this->fixtureDir, $this->fixtureDir.'bar.phtml'], | ||
['bar'], | ||
['*.php'], | ||
['*Fail.php'] | ||
); | ||
|
||
$this->assertEquals( | ||
[ | ||
$this->fixtureDir.'bar.phtml', | ||
$this->fixtureDir.'subdir'.DIRECTORY_SEPARATOR.'bar.php', | ||
], | ||
$facade->findFiles() | ||
); | ||
} | ||
} |