Skip to content

Commit

Permalink
Removed sebastian/finder-facade as a dependency and added replacement…
Browse files Browse the repository at this point in the history
… for PHP8 compatibility (#20)
  • Loading branch information
swarrenwecareconnectorg committed Nov 16, 2021
1 parent c057e46 commit 1560e40
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"nikic/php-parser": "^4.0",
"phpunit/php-text-template": "^1.2.1|^2.0",
"psr/log": "^1.0",
"sebastian/finder-facade": "^1.2|^2.0",
"symfony/finder": "^4.1|^5.0",
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/console": "^3.4|^4.0|^5.0",
"symfony/yaml": "^3.4|^4.0|^5.0"
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/Log/AnalyzerLogProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Scheb\Tombstone\Analyzer\Log;

use Scheb\Tombstone\Analyzer\Cli\ConsoleOutputInterface;
use Scheb\Tombstone\Core\FinderFacade;
use Scheb\Tombstone\Core\Model\RootPath;
use SebastianBergmann\FinderFacade\FinderFacade;

class AnalyzerLogProvider implements LogProviderInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/Stock/ParserTombstoneProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
use Scheb\Tombstone\Analyzer\Cli\ConsoleOutputInterface;
use Scheb\Tombstone\Core\FinderFacade;
use Scheb\Tombstone\Core\Model\RootPath;
use SebastianBergmann\FinderFacade\FinderFacade;

class ParserTombstoneProvider implements TombstoneProviderInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"nikic/php-parser": "^4.0",
"phpunit/php-text-template": "^1.2.1|^2.0",
"scheb/tombstone-core": "self.version",
"sebastian/finder-facade": "^1.2|^2.0",
"symfony/finder": "^4.1|^5.0",
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/console": "^3.4|^4.0|^5.0",
"symfony/yaml": "^3.4|^4.0|^5.0"
Expand Down
68 changes: 68 additions & 0 deletions src/core/FinderFacade.php
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;
}
}
2 changes: 1 addition & 1 deletion tests/Analyzer/Stock/ParserTombstoneProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Scheb\Tombstone\Analyzer\Cli\ConsoleOutputInterface;
use Scheb\Tombstone\Analyzer\Stock\ParserTombstoneProvider;
use Scheb\Tombstone\Analyzer\Stock\TombstoneExtractor;
use Scheb\Tombstone\Core\FinderFacade;
use Scheb\Tombstone\Core\Model\Tombstone;
use Scheb\Tombstone\Tests\TestCase;
use SebastianBergmann\FinderFacade\FinderFacade;

class ParserTombstoneProviderTest extends TestCase
{
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions tests/Core/FinderFacadeFiles/subdir/bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

declare(strict_types=1);
3 changes: 3 additions & 0 deletions tests/Core/FinderFacadeFiles/subdir/fooFail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

declare(strict_types=1);
36 changes: 36 additions & 0 deletions tests/Core/FinderFacadeTest.php
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()
);
}
}

0 comments on commit 1560e40

Please sign in to comment.