forked from ariddlestone/phpstan-cakephp2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClassPropertiesExtension.php
More file actions
64 lines (53 loc) · 1.81 KB
/
ClassPropertiesExtension.php
File metadata and controls
64 lines (53 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace PHPStanCakePHP2;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
abstract class ClassPropertiesExtension implements PropertiesClassReflectionExtension
{
private ReflectionProvider $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function hasProperty(
ClassReflection $classReflection,
string $propertyName
): bool {
$propertyClassName = $this->getClassNameFromPropertyName($propertyName);
return array_filter(
$this->getContainingClassNames(),
[$classReflection, 'is']
)
&& $this->reflectionProvider->hasClass($propertyClassName)
&& $this->reflectionProvider->getClass($propertyClassName)
->is($this->getPropertyParentClassName());
}
public function getProperty(
ClassReflection $classReflection,
string $propertyName
): PropertyReflection {
return new PublicReadOnlyPropertyReflection(
$this->getClassNameFromPropertyName($propertyName),
$classReflection
);
}
/**
* Get the class name of the type of property.
*/
abstract protected function getPropertyParentClassName(): string;
/**
* Get the class names which can contain the property.
*
* @return array<string>
*/
abstract protected function getContainingClassNames(): array;
/**
* Return the class name from the property name.
*/
abstract protected function getClassNameFromPropertyName(
string $propertyName
): string;
}