@@ -315,24 +315,9 @@ private function rememberConstructorExpressions(array $currentExpressionTypes):
315315 continue ;
316316 }
317317 } elseif ($ expr instanceof PropertyFetch) {
318- if (
319- !$ expr ->name instanceof Node \Identifier
320- || !$ expr ->var instanceof Variable
321- || $ expr ->var ->name !== 'this '
322- || !$ this ->phpVersion ->supportsReadOnlyProperties ()
323- ) {
318+ if (!$ this ->isReadonlyPropertyFetchOnThis ($ expr )) {
324319 continue ;
325320 }
326-
327- $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
328- if ($ propertyReflection === null ) {
329- continue ;
330- }
331-
332- $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
333- if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
334- continue ;
335- }
336321 } elseif (!$ expr instanceof ConstFetch && !$ expr instanceof PropertyInitializationExpr) {
337322 continue ;
338323 }
@@ -369,6 +354,30 @@ public function rememberConstructorScope(): self
369354 );
370355 }
371356
357+ private function isReadonlyPropertyFetchOnThis (PropertyFetch $ expr ): bool
358+ {
359+ if (
360+ !$ expr ->name instanceof Node \Identifier
361+ || !$ expr ->var instanceof Variable
362+ || $ expr ->var ->name !== 'this '
363+ || !$ this ->phpVersion ->supportsReadOnlyProperties ()
364+ ) {
365+ return false ;
366+ }
367+
368+ $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
369+ if ($ propertyReflection === null ) {
370+ return false ;
371+ }
372+
373+ $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
374+ if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
375+ return false ;
376+ }
377+
378+ return true ;
379+ }
380+
372381 /** @api */
373382 public function isInClass (): bool
374383 {
0 commit comments