-
-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support scopes defined in model docblocks
- Loading branch information
Showing
5 changed files
with
236 additions
and
0 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
70 changes: 70 additions & 0 deletions
70
src/Reflection/AnnotationScopeMethodParameterReflection.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,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NunoMaduro\Larastan\Reflection; | ||
|
||
use PHPStan\Reflection\ParameterReflection; | ||
use PHPStan\Reflection\PassedByReference; | ||
use PHPStan\Type\Type; | ||
|
||
final class AnnotationScopeMethodParameterReflection implements ParameterReflection | ||
{ | ||
/** @var string */ | ||
private $name; | ||
|
||
/** @var Type */ | ||
private $type; | ||
|
||
/** @var PassedByReference */ | ||
private $passedByReference; | ||
|
||
/** @var bool */ | ||
private $isOptional; | ||
|
||
/** @var bool */ | ||
private $isVariadic; | ||
|
||
/** @var Type|null */ | ||
private $defaultValue; | ||
|
||
public function __construct(string $name, Type $type, PassedByReference $passedByReference, bool $isOptional, bool $isVariadic, ?Type $defaultValue) | ||
{ | ||
$this->name = $name; | ||
$this->type = $type; | ||
$this->passedByReference = $passedByReference; | ||
$this->isOptional = $isOptional; | ||
$this->isVariadic = $isVariadic; | ||
$this->defaultValue = $defaultValue; | ||
} | ||
|
||
public function getName() : string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function isOptional() : bool | ||
{ | ||
return $this->isOptional; | ||
} | ||
|
||
public function getType() : Type | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function passedByReference() : PassedByReference | ||
{ | ||
return $this->passedByReference; | ||
} | ||
|
||
public function isVariadic() : bool | ||
{ | ||
return $this->isVariadic; | ||
} | ||
|
||
public function getDefaultValue() : ?Type | ||
{ | ||
return $this->defaultValue; | ||
} | ||
} |
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,131 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NunoMaduro\Larastan\Reflection; | ||
|
||
use PHPStan\Reflection\ClassMemberReflection; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\FunctionVariant; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Reflection\ParametersAcceptor; | ||
use PHPStan\TrinaryLogic; | ||
use PHPStan\Type\Generic\TemplateTypeMap; | ||
use PHPStan\Type\Type; | ||
|
||
final class AnnotationScopeMethodReflection implements MethodReflection | ||
{ | ||
/** @var string */ | ||
private $name; | ||
|
||
/** @var ClassReflection */ | ||
private $declaringClass; | ||
|
||
/** @var Type */ | ||
private $returnType; | ||
|
||
/** @var bool */ | ||
private $isStatic; | ||
|
||
/** @var AnnotationScopeMethodParameterReflection[] */ | ||
private $parameters; | ||
|
||
/** @var bool */ | ||
private $isVariadic; | ||
|
||
/** @var FunctionVariant[]|null */ | ||
private $variants = null; | ||
|
||
/** | ||
* @param string $name | ||
* @param ClassReflection $declaringClass | ||
* @param Type $returnType | ||
* @param AnnotationScopeMethodParameterReflection[] $parameters | ||
* @param bool $isStatic | ||
* @param bool $isVariadic | ||
*/ | ||
public function __construct(string $name, ClassReflection $declaringClass, Type $returnType, array $parameters, bool $isStatic, bool $isVariadic) | ||
{ | ||
$this->name = $name; | ||
$this->declaringClass = $declaringClass; | ||
$this->returnType = $returnType; | ||
$this->parameters = $parameters; | ||
$this->isStatic = $isStatic; | ||
$this->isVariadic = $isVariadic; | ||
} | ||
|
||
public function getDeclaringClass() : ClassReflection | ||
{ | ||
return $this->declaringClass; | ||
} | ||
|
||
public function getPrototype() : ClassMemberReflection | ||
{ | ||
return $this; | ||
} | ||
|
||
public function isStatic() : bool | ||
{ | ||
return $this->isStatic; | ||
} | ||
|
||
public function isPrivate() : bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function isPublic() : bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function getName() : string | ||
{ | ||
return $this->name; | ||
} | ||
/** | ||
* @return ParametersAcceptor[] | ||
*/ | ||
public function getVariants() : array | ||
{ | ||
if ($this->variants === null) { | ||
$this->variants = [new FunctionVariant(TemplateTypeMap::createEmpty(), null, $this->parameters, $this->isVariadic, $this->returnType)]; | ||
} | ||
return $this->variants; | ||
} | ||
|
||
public function isDeprecated() : TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function getDeprecatedDescription() : ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function isFinal() : TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function isInternal() : TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function getThrowType() : ?Type | ||
{ | ||
return null; | ||
} | ||
|
||
public function hasSideEffects() : TrinaryLogic | ||
{ | ||
return TrinaryLogic::createMaybe(); | ||
} | ||
|
||
public function getDocComment() : ?string | ||
{ | ||
return null; | ||
} | ||
} |
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