@@ -98,20 +98,21 @@ public function check(Input $input): ResultInterface
98
98
];
99
99
100
100
$ properties = collect ($ reflectionClass ->getProperties ());
101
- $ properties = $ properties ->flatMap (fn (\ReflectionProperty $ prop ) => [
101
+ $ visibilities = $ properties ->flatMap (fn (\ReflectionProperty $ prop ) => [
102
102
$ prop ->getName () => $ this ->getPropertyVisibility ($ prop )
103
- ])->getArrayCopy ();
104
- ksort ($ properties );
103
+ ])->ksort ();
105
104
106
- if ($ changedVisibility = array_keys (array_diff_assoc ($ expectedProperties , $ properties ))) {
105
+ if ($ changedVisibility = array_keys (array_diff_assoc ($ expectedProperties , $ visibilities -> getArrayCopy () ))) {
107
106
return Failure::fromNameAndReason ($ this ->getName (), pluralise (
108
107
'Visibility changed for property "%s" ' ,
109
108
$ changedVisibility ,
110
109
implode ('" & " ' , $ changedVisibility )
111
110
));
112
111
}
113
112
114
- $ types = $ properties ->map (fn (\ReflectionProperty $ prop ) => $ prop ->getType ()?->getName());
113
+ $ types = $ properties ->flatMap (fn (\ReflectionProperty $ prop ) => [
114
+ $ prop ->getName () => $ this ->getPropertyType ($ prop )
115
+ ]);
115
116
$ expected = ['visitor ' => 'Closure ' , 'key ' => 'string ' , 'basePath ' => 'string ' ];
116
117
if ([] !== $ typeDiff = array_diff_assoc ($ expected , $ types ->getArrayCopy ())) {
117
118
return Failure::fromNameAndReason ($ this ->getName (), pluralise (
@@ -132,7 +133,9 @@ public function check(Input $input): ResultInterface
132
133
133
134
$ actual = $ properties
134
135
->each (fn (\ReflectionProperty $ prop ) => $ prop ->setAccessible (true ))
135
- ->map (fn (\ReflectionProperty $ prop ) => $ prop ->isInitialized ($ obj ) ? $ prop ->getValue ($ obj ) : null )
136
+ ->flatMap (fn (\ReflectionProperty $ prop ) => [
137
+ $ prop ->getName () => $ prop ->isInitialized ($ obj ) ? $ prop ->getValue ($ obj ) : null
138
+ ])
136
139
->getArrayCopy ();
137
140
138
141
$ dataFailures = array_filter ([
@@ -160,4 +163,15 @@ private function getPropertyVisibility(\ReflectionProperty $prop): string
160
163
default => 'public ' ,
161
164
};
162
165
}
166
+
167
+ private function getPropertyType (\ReflectionProperty $ prop ): string
168
+ {
169
+ $ type = $ prop ->getType ();
170
+
171
+ if (null === $ type || !$ type instanceof \ReflectionNamedType) {
172
+ throw new \RuntimeException ('Invalid property "%s" ' , $ prop ->getName ());
173
+ }
174
+ /** @var \ReflectionNamedType $type */
175
+ return $ type ->getName ();
176
+ }
163
177
}
0 commit comments