|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Base daft objects. |
|
4
|
|
|
* |
|
5
|
|
|
* @author SignpostMarv |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace SignpostMarv\DaftObject\PHPStan; |
|
10
|
|
|
|
|
11
|
|
|
use PHPStan\Broker\Broker; |
|
12
|
|
|
use PHPStan\Reflection\BrokerAwareExtension; |
|
13
|
|
|
use PHPStan\Reflection\ClassReflection; |
|
14
|
|
|
use PHPStan\Reflection\PropertiesClassReflectionExtension; |
|
15
|
|
|
use PHPStan\Reflection\PropertyReflection; |
|
16
|
|
|
use SignpostMarv\DaftObject\DaftObject; |
|
17
|
|
|
use SignpostMarv\DaftObject\TypeUtilities; |
|
18
|
|
|
|
|
19
|
|
|
class ClassReflectionExtension implements BrokerAwareExtension, PropertiesClassReflectionExtension |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Broker|null |
|
23
|
|
|
*/ |
|
24
|
|
|
private $broker; |
|
25
|
|
|
|
|
26
|
|
|
public function setBroker(Broker $broker) : void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->broker = $broker; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool |
|
32
|
|
|
{ |
|
33
|
|
|
$className = $classReflection->getName(); |
|
34
|
|
|
|
|
35
|
|
|
$property = ucfirst($propertyName); |
|
36
|
|
|
$getter = static::MethodNameFromProperty($property); |
|
37
|
|
|
$setter = static::MethodNameFromProperty($property, true); |
|
38
|
|
|
|
|
39
|
|
|
return |
|
40
|
|
|
is_a($className, DaftObject::class, true) && |
|
41
|
|
|
( |
|
42
|
|
|
$classReflection->getNativeReflection()->hasMethod($getter) || |
|
43
|
|
|
$classReflection->getNativeReflection()->hasMethod($setter) |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getProperty(ClassReflection $ref, string $propertyName) : PropertyReflection |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* @var Broker $broker |
|
51
|
|
|
*/ |
|
52
|
|
|
$broker = $this->broker; |
|
53
|
|
|
|
|
54
|
|
|
return new PropertyReflectionExtension($ref, $broker, $propertyName); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected static function MethodNameFromProperty( |
|
58
|
|
|
string $prop, |
|
59
|
|
|
bool $SetNotGet = false |
|
60
|
|
|
) : string { |
|
61
|
|
|
return TypeUtilities::MethodNameFromProperty($prop, $SetNotGet); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|