@@ -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,9 +388,9 @@ private function printProperty(Property $property, bool $readOnlyClass = false):
386
388
. ltrim ($ this ->printType ($ type , $ property ->isNullable ()) . ' ' )
387
389
. '$ ' . $ property ->getName ());
388
390
389
- $ hooks = $ this ->printHooks ($ property );
391
+ $ hooks = $ this ->printHooks ($ property, $ isInterface );
390
392
391
- $ defaultValue = $ property ->getValue () === null && !$ property ->isInitialized ()
393
+ $ defaultValue = $ isInterface || ( $ property ->getValue () === null && !$ property ->isInitialized () )
392
394
? ''
393
395
: ' = ' . $ this ->dump ($ property ->getValue (), strlen ($ def ) + 3 ); // 3 = ' = '
394
396
@@ -496,7 +498,7 @@ protected function isBraceOnNextLine(bool $multiLine, bool $hasReturnType): bool
496
498
}
497
499
498
500
499
- private function printHooks (Property $ property ): ?string
501
+ private function printHooks (Property $ property, bool $ isInterface = false ): ?string
500
502
{
501
503
$ getHook = $ property ->getGetHook ();
502
504
$ setHook = $ property ->getSetHook ();
@@ -505,15 +507,19 @@ private function printHooks(Property $property): ?string
505
507
return null ;
506
508
}
507
509
508
- $ out = " { \n" ;
510
+ $ out = ' { ' . ( $ isInterface ? ' ' : " \n") ;
509
511
510
512
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" );
512
516
}
513
517
514
518
if ($ setHook !== null ) {
515
519
$ 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" );
517
523
}
518
524
519
525
return $ out . '} ' ;
0 commit comments