-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#45] Replace File_Iterator with Symfony Finder
[#23] Add command line input option to support includes/excludes
- Loading branch information
Showing
3 changed files
with
75 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace PHPSemVerChecker\Finder; | ||
|
||
use Finder\Adapter\SymfonyFinder as BaseFinder; | ||
|
||
class Finder | ||
{ | ||
/** | ||
* @param string $path | ||
* @param array $includes | ||
* @param array $excludes | ||
* @return array | ||
*/ | ||
public function find($path, array $includes, array $excludes = []) | ||
{ | ||
$finder = new BaseFinder(); | ||
$finder->ignoreDotFiles(true) | ||
->files() | ||
->name('*.php') | ||
->in($path); | ||
|
||
foreach ($includes as $include) { | ||
$finder->path($include); | ||
} | ||
|
||
foreach ($excludes as $exclude) { | ||
$finder->notPath($exclude); | ||
} | ||
|
||
$files = iterator_to_array($finder->getIterator()); | ||
|
||
return $files; | ||
} | ||
|
||
/** | ||
* @param string $path | ||
* @param string $includes | ||
* @param string $excludes | ||
* @return array | ||
*/ | ||
public function findFromString($path, $includes, $excludes) | ||
{ | ||
if ($includes === '*') { | ||
$includes = []; | ||
} else { | ||
$includes = preg_split('@(?:\s*,\s*|^\s*|\s*$)@', $includes, NULL, PREG_SPLIT_NO_EMPTY); | ||
} | ||
|
||
if ($excludes === '*') { | ||
$excludes = []; | ||
} else { | ||
$excludes = preg_split('@(?:\s*,\s*|^\s*|\s*$)@', $excludes, NULL, PREG_SPLIT_NO_EMPTY); | ||
} | ||
|
||
return $this->find($path, $includes, $excludes); | ||
} | ||
} |