-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
src/SourceLocator/SourceStubber/AggregateSourceStubber.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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Roave\BetterReflection\SourceLocator\SourceStubber; | ||
|
||
use ReflectionClass as CoreReflectionClass; | ||
use ReflectionFunction as CoreReflectionFunction; | ||
use function array_merge; | ||
|
||
class AggregateSourceStubber implements SourceStubber | ||
{ | ||
/** @var SourceStubber[] */ | ||
private $sourceStubbers; | ||
|
||
public function __construct(SourceStubber $sourceStubber, SourceStubber ...$otherSourceStubbers) | ||
{ | ||
$this->sourceStubbers = array_merge([$sourceStubber], $otherSourceStubbers); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function generateClassStub(CoreReflectionClass $classReflection) : ?string | ||
{ | ||
foreach ($this->sourceStubbers as $sourceStubber) { | ||
$stub = $sourceStubber->generateClassStub($classReflection); | ||
|
||
if ($stub !== null) { | ||
return $stub; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function generateFunctionStub(CoreReflectionFunction $functionReflection) : ?string | ||
{ | ||
foreach ($this->sourceStubbers as $sourceStubber) { | ||
$stub = $sourceStubber->generateFunctionStub($functionReflection); | ||
|
||
if ($stub !== null) { | ||
return $stub; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |