File tree 6 files changed +64
-4
lines changed 6 files changed +64
-4
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ services:
22
22
behaviorPaths : %ModelBehaviorsExtension.behaviorPaths%
23
23
tags :
24
24
- phpstan.broker.methodsClassReflectionExtension
25
+ - class : ARiddlestone\PHPStanCakePHP2\ModelModelsExtension
26
+ tags :
27
+ - phpstan.broker.propertiesClassReflectionExtension
25
28
parametersSchema :
26
29
ModelBehaviorsExtension : structure ([
27
30
behaviorPaths : listOf (string ())
Original file line number Diff line number Diff line change 91
91
*/
92
92
93
93
'requirements ' => [
94
- 'min-quality ' => 90 ,
95
- 'min-complexity ' => 90 ,
96
- 'min-architecture ' => 90 ,
97
- 'min-style ' => 90 ,
94
+ 'min-quality ' => 80 ,
95
+ 'min-complexity ' => 80 ,
96
+ 'min-architecture ' => 80 ,
97
+ 'min-style ' => 80 ,
98
98
'disable-security-check ' => false ,
99
99
],
100
100
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace ARiddlestone \PHPStanCakePHP2 ;
6
+
7
+ use PHPStan \Reflection \ClassReflection ;
8
+ use PHPStan \Reflection \PropertiesClassReflectionExtension ;
9
+ use PHPStan \Reflection \PropertyReflection ;
10
+ use PHPStan \Reflection \ReflectionProvider ;
11
+
12
+ /**
13
+ * Adds {@link Model}s as properties to {@link Model}s.
14
+ */
15
+ final class ModelModelsExtension implements
16
+ PropertiesClassReflectionExtension
17
+ {
18
+ private ReflectionProvider $ reflectionProvider ;
19
+
20
+ public function __construct (ReflectionProvider $ reflectionProvider )
21
+ {
22
+ $ this ->reflectionProvider = $ reflectionProvider ;
23
+ }
24
+
25
+ public function hasProperty (
26
+ ClassReflection $ classReflection ,
27
+ string $ propertyName
28
+ ): bool {
29
+ return $ classReflection ->is ('Model ' )
30
+ && $ this ->reflectionProvider ->hasClass ($ propertyName )
31
+ && $ this ->reflectionProvider ->getClass ($ propertyName )->is ('Model ' );
32
+ }
33
+
34
+ public function getProperty (
35
+ ClassReflection $ classReflection ,
36
+ string $ propertyName
37
+ ): PropertyReflection {
38
+ return new PublicReadOnlyPropertyReflection (
39
+ $ propertyName ,
40
+ $ classReflection
41
+ );
42
+ }
43
+ }
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public function dataFileAsserts(): iterable
14
14
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/core_model_behavior.php ' );
15
15
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/custom_model_behavior.php ' );
16
16
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/invalid_model_property.php ' );
17
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/existing_model_model.php ' );
17
18
}
18
19
19
20
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class SecondModel extends Model {}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types = 1 );
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ /** @var BasicModel $model */
8
+ $ secondModel = $ model ->SecondModel ;
9
+
10
+ assertType ('SecondModel ' , $ secondModel );
You can’t perform that action at this time.
0 commit comments