1818use Go \Proxy \Generator \PropertyNodeProvider ;
1919use Go \Proxy \Generator \TypeGenerator ;
2020use InvalidArgumentException ;
21+ use PhpParser \Comment \Doc ;
2122use PhpParser \Node \Arg ;
2223use PhpParser \Node \Expr \ArrayDimFetch ;
2324use PhpParser \Node \Expr \Assign ;
@@ -146,15 +147,17 @@ public function getNode(): PropertyNode
146147 private function createGetHook (bool $ returnsByReference ): PropertyHook
147148 {
148149 $ propertyName = $ this ->property ->getName ();
150+ $ fieldAccessExpression = new Expression (new Assign (
151+ new Variable ('fieldAccess ' ),
152+ new ArrayDimFetch (
153+ new StaticPropertyFetch (new Name ('self ' ), JoinPointPropertyGenerator::NAME ),
154+ new String_ ('prop: ' . $ propertyName )
155+ )
156+ ));
157+ $ fieldAccessExpression ->setDocComment (new Doc ('/** @var ClassFieldAccess<self> $fieldAccess */ ' ));
149158
150159 return new PropertyHook ('get ' , [
151- new Expression (new Assign (
152- new Variable ('fieldAccess ' ),
153- new ArrayDimFetch (
154- new StaticPropertyFetch (new Name ('self ' ), JoinPointPropertyGenerator::NAME ),
155- new String_ ('prop: ' . $ propertyName )
156- )
157- )),
160+ $ fieldAccessExpression ,
158161 new Expression (new AssignRef (
159162 new Variable ('value ' ),
160163 new MethodCall (new Variable ('fieldAccess ' ), '__invoke ' , [
@@ -181,15 +184,17 @@ private function createGetHook(bool $returnsByReference): PropertyHook
181184 private function createSetHook (): PropertyHook
182185 {
183186 $ propertyName = $ this ->property ->getName ();
187+ $ fieldAccessExpression = new Expression (new Assign (
188+ new Variable ('fieldAccess ' ),
189+ new ArrayDimFetch (
190+ new StaticPropertyFetch (new Name ('self ' ), JoinPointPropertyGenerator::NAME ),
191+ new String_ ('prop: ' . $ propertyName )
192+ )
193+ ));
194+ $ fieldAccessExpression ->setDocComment (new Doc ('/** @var ClassFieldAccess<self> $fieldAccess */ ' ));
184195
185196 return new PropertyHook ('set ' , [
186- new Expression (new Assign (
187- new Variable ('fieldAccess ' ),
188- new ArrayDimFetch (
189- new StaticPropertyFetch (new Name ('self ' ), JoinPointPropertyGenerator::NAME ),
190- new String_ ('prop: ' . $ propertyName )
191- )
192- )),
197+ $ fieldAccessExpression ,
193198 new Expression (new Assign (
194199 new PropertyFetch (new Variable ('this ' ), $ propertyName ),
195200 new MethodCall (new Variable ('fieldAccess ' ), '__invoke ' , [
0 commit comments