@@ -198,9 +198,11 @@ public function printClass(
198198 }
199199
200200 $ properties = [];
201- if ($ class instanceof ClassType || $ class instanceof TraitType) {
201+ if ($ class instanceof ClassType || $ class instanceof TraitType || $ class instanceof InterfaceType ) {
202202 foreach ($ class ->getProperties () as $ property ) {
203- $ properties [] = $ this ->printProperty ($ property , $ readOnlyClass );
203+ if (!$ class instanceof InterfaceType || ($ property ->hasGetHook () || $ property ->hasSetHook ())) {
204+ $ properties [] = $ this ->printProperty ($ property , $ readOnlyClass , $ class ->isInterface ());
205+ }
204206 }
205207 }
206208
@@ -375,7 +377,7 @@ private function printConstant(Constant $const): string
375377 }
376378
377379
378- private function printProperty (Property $ property , bool $ readOnlyClass = false ): string
380+ private function printProperty (Property $ property , bool $ readOnlyClass = false , bool $ isInterface = false ): string
379381 {
380382 $ property ->validate ();
381383 $ type = $ property ->getType ();
@@ -386,11 +388,15 @@ private function printProperty(Property $property, bool $readOnlyClass = false):
386388 . ltrim ($ this ->printType ($ type , $ property ->isNullable ()) . ' ' )
387389 . '$ ' . $ property ->getName ());
388390
389- $ hooks = !$ property ->getSetHook () && !$ property ->getGetHook ()
390- ? '; '
391- : " { \n" . $ this ->printHooks ($ property ) . '} ' ;
391+ if (!$ property ->getSetHook () && !$ property ->getGetHook ()) {
392+ $ hooks = '; ' ;
393+ } elseif ($ isInterface ) {
394+ $ hooks = ' { ' . implode (' ' , array_filter ([$ property ->getSetHook () ? 'set; ' : null , $ property ->getGetHook () ? 'get; ' : null ])) . ' } ' ;
395+ } else {
396+ $ hooks = " { \n" . $ this ->printHooks ($ property ) . '} ' ;
397+ }
392398
393- $ defaultValue = $ property ->getValue () === null && !$ property ->isInitialized ()
399+ $ defaultValue = $ isInterface || ( $ property ->getValue () === null && !$ property ->isInitialized () )
394400 ? ''
395401 : ' = ' . $ this ->dump ($ property ->getValue (), strlen ($ def ) + 3 ); // 3 = ' = '
396402
0 commit comments