@@ -198,9 +198,11 @@ public function printClass(
198
198
}
199
199
200
200
$ properties = [];
201
- if ($ class instanceof ClassType || $ class instanceof TraitType) {
201
+ if ($ class instanceof ClassType || $ class instanceof TraitType || $ class instanceof InterfaceType ) {
202
202
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
+ }
204
206
}
205
207
}
206
208
@@ -375,7 +377,7 @@ private function printConstant(Constant $const): string
375
377
}
376
378
377
379
378
- private function printProperty (Property $ property , bool $ readOnlyClass = false ): string
380
+ private function printProperty (Property $ property , bool $ readOnlyClass = false , bool $ isInterface = false ): string
379
381
{
380
382
$ property ->validate ();
381
383
$ type = $ property ->getType ();
@@ -386,11 +388,15 @@ private function printProperty(Property $property, bool $readOnlyClass = false):
386
388
. ltrim ($ this ->printType ($ type , $ property ->isNullable ()) . ' ' )
387
389
. '$ ' . $ property ->getName ());
388
390
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
+ }
392
398
393
- $ defaultValue = $ property ->getValue () === null && !$ property ->isInitialized ()
399
+ $ defaultValue = $ isInterface || ( $ property ->getValue () === null && !$ property ->isInitialized () )
394
400
? ''
395
401
: ' = ' . $ this ->dump ($ property ->getValue (), strlen ($ def ) + 3 ); // 3 = ' = '
396
402
0 commit comments