77use PHPStan \DependencyInjection \RegisteredRule ;
88use PHPStan \Node \ClassPropertiesNode ;
99use PHPStan \Reflection \PropertyReflection ;
10- use PHPStan \Rules \Properties \PropertyReflectionFinder ;
1110use PHPStan \Rules \Properties \ReadWritePropertiesExtensionProvider ;
1211use PHPStan \Rules \Rule ;
13- use PHPStan \Type \TypeCombinator ;
14- use function count ;
1512use function sprintf ;
1613
1714/**
@@ -23,7 +20,6 @@ final class TooWidePropertyTypeRule implements Rule
2320
2421 public function __construct (
2522 private ReadWritePropertiesExtensionProvider $ extensionProvider ,
26- private PropertyReflectionFinder $ propertyReflectionFinder ,
2723 private TooWideTypeCheck $ check ,
2824 )
2925 {
@@ -55,13 +51,6 @@ public function processNode(Node $node, Scope $scope): array
5551 }
5652
5753 $ propertyReflection = $ classReflection ->getNativeProperty ($ propertyName );
58- $ propertyType = $ propertyReflection ->getWritableType ();
59- $ phpdocType = $ propertyReflection ->getPhpDocType ();
60-
61- $ propertyType = $ this ->check ->findTypeToCheck ($ propertyType , $ phpdocType , $ scope );
62- if ($ propertyType === null ) {
63- continue ;
64- }
6554
6655 foreach ($ this ->extensionProvider ->getExtensions () as $ extension ) {
6756 if ($ extension ->isAlwaysRead ($ propertyReflection , $ propertyName )) {
@@ -75,33 +64,17 @@ public function processNode(Node $node, Scope $scope): array
7564 }
7665 }
7766
78- $ assignedTypes = [];
79- foreach ($ node ->getPropertyAssigns () as $ assign ) {
80- $ assignNode = $ assign ->getAssign ();
81- $ assignPropertyReflections = $ this ->propertyReflectionFinder ->findPropertyReflectionsFromNode ($ assignNode ->getPropertyFetch (), $ assign ->getScope ());
82- foreach ($ assignPropertyReflections as $ assignPropertyReflection ) {
83- if ($ propertyName !== $ assignPropertyReflection ->getName ()) {
84- continue ;
85- }
86- if ($ propertyReflection ->getDeclaringClass ()->getName () !== $ assignPropertyReflection ->getDeclaringClass ()->getName ()) {
87- continue ;
88- }
89-
90- $ assignedTypes [] = $ assignPropertyReflection ->getScope ()->getType ($ assignNode ->getAssignedExpr ());
91- }
92- }
93-
94- if ($ property ->getDefault () !== null ) {
95- $ assignedTypes [] = $ scope ->getType ($ property ->getDefault ());
96- }
97-
98- if (count ($ assignedTypes ) === 0 ) {
99- continue ;
100- }
101-
102- $ assignedType = TypeCombinator::union (...$ assignedTypes );
10367 $ propertyDescription = $ this ->describePropertyByName ($ propertyReflection , $ propertyName );
104- foreach ($ this ->check ->checkProperty ($ property , $ propertyType , $ propertyDescription , $ assignedType ) as $ error ) {
68+ $ propertyErrors = $ this ->check ->checkProperty (
69+ $ property ,
70+ $ propertyReflection ->getDeclaringClass (),
71+ $ node ->getPropertyAssigns (),
72+ $ propertyReflection ->getNativeType (),
73+ $ propertyReflection ->getPhpDocType (),
74+ $ propertyDescription ,
75+ $ scope ,
76+ );
77+ foreach ($ propertyErrors as $ error ) {
10578 $ errors [] = $ error ;
10679 }
10780 }
0 commit comments