@@ -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,9 +388,9 @@ private function printProperty(Property $property, bool $readOnlyClass = false):
386388 . ltrim ($ this ->printType ($ type , $ property ->isNullable ()) . ' ' )
387389 . '$ ' . $ property ->getName ());
388390
389- $ hooks = $ this ->printHooks ($ property );
391+ $ hooks = $ this ->printHooks ($ property, $ isInterface );
390392
391- $ defaultValue = $ property ->getValue () === null && !$ property ->isInitialized ()
393+ $ defaultValue = $ isInterface || ( $ property ->getValue () === null && !$ property ->isInitialized () )
392394 ? ''
393395 : ' = ' . $ this ->dump ($ property ->getValue (), strlen ($ def ) + 3 ); // 3 = ' = '
394396
@@ -496,7 +498,7 @@ protected function isBraceOnNextLine(bool $multiLine, bool $hasReturnType): bool
496498 }
497499
498500
499- private function printHooks (Property $ property ): ?string
501+ private function printHooks (Property $ property, bool $ isInterface = false ): ?string
500502 {
501503 $ getHook = $ property ->getGetHook ();
502504 $ setHook = $ property ->getSetHook ();
@@ -505,15 +507,19 @@ private function printHooks(Property $property): ?string
505507 return null ;
506508 }
507509
508- $ out = " { \n" ;
510+ $ out = ' { ' . ( $ isInterface ? ' ' : " \n") ;
509511
510512 if ($ getHook !== null ) {
511- $ out .= $ this ->indent ("get { \n" . $ this ->indent ($ this ->printFunctionBody ($ getHook )) . "} \n" );
513+ $ out .= $ isInterface
514+ ? 'get; '
515+ : $ this ->indent ("get { \n" . $ this ->indent ($ this ->printFunctionBody ($ getHook )) . "} \n" );
512516 }
513517
514518 if ($ setHook !== null ) {
515519 $ params = $ this ->printParameters ($ setHook );
516- $ out .= $ this ->indent ('set ' . $ params . ' { ' . "\n" . $ this ->indent ($ this ->printFunctionBody ($ setHook )) . "} \n" );
520+ $ out .= $ isInterface
521+ ? 'set; '
522+ : $ this ->indent ('set ' . $ params . ' { ' . "\n" . $ this ->indent ($ this ->printFunctionBody ($ setHook )) . "} \n" );
517523 }
518524
519525 return $ out . '} ' ;
0 commit comments