-
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.
Merge pull request #373 from kukulich/source-stubber
Source stubber based on `jetbrains/phpstorm-stubs`
- Loading branch information
Showing
110 changed files
with
882 additions
and
8,439 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
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
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; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/SourceLocator/SourceStubber/Exception/CouldNotFindPhpStormStubs.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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Roave\BetterReflection\SourceLocator\SourceStubber\Exception; | ||
|
||
use RuntimeException; | ||
|
||
class CouldNotFindPhpStormStubs extends RuntimeException | ||
{ | ||
public static function create() : self | ||
{ | ||
return new self('Could not find PhpStorm stubs'); | ||
} | ||
} |
Oops, something went wrong.