77use Closure ;
88use Error ;
99use OutOfBoundsException ;
10- use PhpParser \Modifiers ;
1110use PhpParser \Node ;
1211use PhpParser \Node \Stmt \Property as PropertyNode ;
1312use PhpParser \NodeTraverser ;
3534
3635use function array_map ;
3736use function assert ;
38- use function count ;
3937use function func_num_args ;
4038use function is_object ;
4139use function sprintf ;
@@ -675,8 +673,8 @@ private function computeModifiers(PropertyNode $node): int
675673 $ modifiers += $ node ->isProtected () ? CoreReflectionProperty::IS_PROTECTED : 0 ;
676674 $ modifiers += $ node ->isProtectedSet () ? ReflectionPropertyAdapter::IS_PROTECTED_SET_COMPATIBILITY : 0 ;
677675 $ modifiers += $ node ->isPublic () ? CoreReflectionProperty::IS_PUBLIC : 0 ;
678- $ modifiers += ( $ node ->flags & ReflectionPropertyAdapter:: IS_FINAL_COMPATIBILITY ) === ReflectionPropertyAdapter:: IS_FINAL_COMPATIBILITY ? ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY : 0 ;
679- $ modifiers += ( $ node ->flags & Modifiers:: ABSTRACT ) === Modifiers:: ABSTRACT ? ReflectionPropertyAdapter::IS_ABSTRACT_COMPATIBILITY : 0 ;
676+ $ modifiers += $ node ->isFinal () ? ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY : 0 ;
677+ $ modifiers += $ node ->isAbstract () ? ReflectionPropertyAdapter::IS_ABSTRACT_COMPATIBILITY : 0 ;
680678
681679 /** @phpstan-ignore return.type */
682680 return $ modifiers ;
@@ -699,51 +697,29 @@ private function computeImmediateVirtual(PropertyNode $node): bool
699697 }
700698 }
701699
702- if ($ setHook !== null && ! $ this ->computeImmediateVirtualBasedOnSetHook ($ setHook )) {
700+ if ($ setHook !== null && ! $ this ->computeImmediateVirtualBasedOnHook ($ setHook )) {
703701 return false ;
704702 }
705703
706704 if ($ getHook === null ) {
707705 return true ;
708706 }
709707
710- return $ this ->computeImmediateVirtualBasedOnGetHook ($ getHook );
708+ return $ this ->computeImmediateVirtualBasedOnHook ($ getHook );
711709 }
712710
713- private function computeImmediateVirtualBasedOnGetHook (Node \PropertyHook $ getHook ): bool
711+ private function computeImmediateVirtualBasedOnHook (Node \PropertyHook $ hook ): bool
714712 {
715- $ getHookBody = $ getHook ->getStmts ();
713+ $ hookBody = $ hook ->getStmts ();
716714
717715 // Abstract property or property in interface
718- if ($ getHookBody === null ) {
716+ if ($ hookBody === null ) {
719717 return true ;
720718 }
721719
722- return ! $ this ->isHookUsingThisProperty ($ getHook );
723- }
724-
725- private function computeImmediateVirtualBasedOnSetHook (Node \PropertyHook $ setHook ): bool
726- {
727- $ setHookBody = $ setHook ->getStmts ();
728-
729- // Abstract property or property in interface
730- if ($ setHookBody === null ) {
731- return true ;
732- }
733-
734- // Short syntax
735- if (count ($ setHookBody ) === 1 && $ setHookBody [0 ] instanceof Node \Stmt \Return_) {
736- return false ;
737- }
738-
739- return ! $ this ->isHookUsingThisProperty ($ setHook );
740- }
741-
742- private function isHookUsingThisProperty (Node \PropertyHook $ hook ): bool
743- {
744720 $ visitor = new FindingVisitor (static fn (Node $ node ): bool => $ node instanceof Node \Expr \PropertyFetch);
745721 $ traverser = new NodeTraverser ($ visitor );
746- $ traverser ->traverse ([ $ hook ] );
722+ $ traverser ->traverse ($ hookBody );
747723
748724 foreach ($ visitor ->getFoundNodes () as $ propertyFetchNode ) {
749725 assert ($ propertyFetchNode instanceof Node \Expr \PropertyFetch);
@@ -754,11 +730,11 @@ private function isHookUsingThisProperty(Node\PropertyHook $hook): bool
754730 && $ propertyFetchNode ->name instanceof Node \Identifier
755731 && $ propertyFetchNode ->name ->name === $ this ->name
756732 ) {
757- return true ;
733+ return false ;
758734 }
759735 }
760736
761- return false ;
737+ return true ;
762738 }
763739
764740 /** @return array{get?: ReflectionMethod, set?: ReflectionMethod} */
0 commit comments