From d392fb7ec8007ff689e8cf95ab8f1acd3da0f58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hansl=C3=ADk?= Date: Fri, 22 Sep 2017 16:05:12 +0200 Subject: [PATCH] Added AggregateSourceStubber --- src/BetterReflection.php | 7 ++- .../SourceStubber/AggregateSourceStubber.php | 52 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/SourceLocator/SourceStubber/AggregateSourceStubber.php diff --git a/src/BetterReflection.php b/src/BetterReflection.php index 86720b968..d723fef36 100644 --- a/src/BetterReflection.php +++ b/src/BetterReflection.php @@ -11,6 +11,8 @@ use Roave\BetterReflection\Reflector\FunctionReflector; use Roave\BetterReflection\SourceLocator\Ast\Locator as AstLocator; use Roave\BetterReflection\SourceLocator\Ast\Parser\MemoizingParser; +use Roave\BetterReflection\SourceLocator\SourceStubber\AggregateSourceStubber; +use Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber; use Roave\BetterReflection\SourceLocator\SourceStubber\ReflectionSourceStubber; use Roave\BetterReflection\SourceLocator\SourceStubber\SourceStubber; use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator; @@ -94,6 +96,9 @@ public function findReflectionsOnLine() : FindReflectionOnLine public function sourceStubber() : SourceStubber { return $this->sourceStubber - ?? $this->sourceStubber = new ReflectionSourceStubber(); + ?? $this->sourceStubber = new AggregateSourceStubber( + new PhpStormStubsSourceStubber($this->phpParser()), + new ReflectionSourceStubber() + ); } } diff --git a/src/SourceLocator/SourceStubber/AggregateSourceStubber.php b/src/SourceLocator/SourceStubber/AggregateSourceStubber.php new file mode 100644 index 000000000..78880f1a4 --- /dev/null +++ b/src/SourceLocator/SourceStubber/AggregateSourceStubber.php @@ -0,0 +1,52 @@ +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; + } +}