-
Notifications
You must be signed in to change notification settings - Fork 457
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
1 parent
28d1c34
commit b02ee14
Showing
15 changed files
with
657 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\PhpDoc\Tag; | ||
|
||
use PHPStan\Type\Type; | ||
|
||
class MixinTag | ||
{ | ||
|
||
/** @var \PHPStan\Type\Type */ | ||
private $type; | ||
|
||
public function __construct(Type $type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
public function getType(): Type | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @param mixed[] $properties | ||
* @return self | ||
*/ | ||
public static function __set_state(array $properties): self | ||
{ | ||
return new self( | ||
$properties['type'] | ||
); | ||
} | ||
|
||
} |
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
51 changes: 51 additions & 0 deletions
51
src/Reflection/Mixin/MixinMethodsClassReflectionExtension.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,51 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Reflection\Mixin; | ||
|
||
use PHPStan\Analyser\OutOfClassScope; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Reflection\MethodsClassReflectionExtension; | ||
|
||
class MixinMethodsClassReflectionExtension implements MethodsClassReflectionExtension | ||
{ | ||
|
||
public function hasMethod(ClassReflection $classReflection, string $methodName): bool | ||
{ | ||
return $this->findMethod($classReflection, $methodName) !== null; | ||
} | ||
|
||
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection | ||
{ | ||
$method = $this->findMethod($classReflection, $methodName); | ||
if ($method === null) { | ||
throw new \PHPStan\ShouldNotHappenException(); | ||
} | ||
|
||
return $method; | ||
} | ||
|
||
private function findMethod(ClassReflection $classReflection, string $methodName): ?MethodReflection | ||
{ | ||
$mixinTypes = $classReflection->getResolvedMixinTypes(); | ||
foreach ($mixinTypes as $type) { | ||
if (!$type->hasMethod($methodName)->yes()) { | ||
continue; | ||
} | ||
|
||
return $type->getMethod($methodName, new OutOfClassScope()); | ||
} | ||
|
||
foreach ($classReflection->getParents() as $parentClass) { | ||
$method = $this->findMethod($parentClass, $methodName); | ||
if ($method === null) { | ||
continue; | ||
} | ||
|
||
return $method; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/Reflection/Mixin/MixinPropertiesClassReflectionExtension.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,51 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Reflection\Mixin; | ||
|
||
use PHPStan\Analyser\OutOfClassScope; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\PropertiesClassReflectionExtension; | ||
use PHPStan\Reflection\PropertyReflection; | ||
|
||
class MixinPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension | ||
{ | ||
|
||
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool | ||
{ | ||
return $this->findProperty($classReflection, $propertyName) !== null; | ||
} | ||
|
||
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection | ||
{ | ||
$property = $this->findProperty($classReflection, $propertyName); | ||
if ($property === null) { | ||
throw new \PHPStan\ShouldNotHappenException(); | ||
} | ||
|
||
return $property; | ||
} | ||
|
||
private function findProperty(ClassReflection $classReflection, string $propertyName): ?PropertyReflection | ||
{ | ||
$mixinTypes = $classReflection->getResolvedMixinTypes(); | ||
foreach ($mixinTypes as $type) { | ||
if (!$type->hasProperty($propertyName)->yes()) { | ||
continue; | ||
} | ||
|
||
return $type->getProperty($propertyName, new OutOfClassScope()); | ||
} | ||
|
||
foreach ($classReflection->getParents() as $parentClass) { | ||
$property = $this->findProperty($parentClass, $propertyName); | ||
if ($property === null) { | ||
continue; | ||
} | ||
|
||
return $property; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.