-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add notInNamespace filter in finders
- Loading branch information
Showing
13 changed files
with
169 additions
and
13 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
50 changes: 50 additions & 0 deletions
50
lib/FilterIterator/PhpDocumentor/NotNamespaceFilterIterator.php
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kcs\ClassFinder\FilterIterator\PhpDocumentor; | ||
|
||
use FilterIterator; | ||
use Iterator; | ||
use phpDocumentor\Reflection\Element; | ||
|
||
use function assert; | ||
use function ltrim; | ||
use function Safe\substr; | ||
use function strpos; | ||
use function strrpos; | ||
|
||
final class NotNamespaceFilterIterator extends FilterIterator | ||
{ | ||
/** @var string[] */ | ||
private array $namespaces; | ||
|
||
/** | ||
* @param Iterator<Element> $iterator | ||
* @param string[] $namespaces | ||
*/ | ||
public function __construct(Iterator $iterator, array $namespaces) | ||
{ | ||
parent::__construct($iterator); | ||
|
||
$this->namespaces = $namespaces; | ||
} | ||
|
||
public function accept(): bool | ||
{ | ||
$reflector = $this->getInnerIterator()->current(); | ||
assert($reflector instanceof Element); | ||
|
||
$fqen = (string) $reflector->getFqsen(); | ||
$index = strrpos($fqen, '\\'); | ||
$classNamespace = ltrim($index !== false ? substr($fqen, 0, $index) : $fqen, '\\'); | ||
|
||
foreach ($this->namespaces as $namespace) { | ||
if ($classNamespace === $namespace || strpos($classNamespace, $namespace . '\\') === 0) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
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
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
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