@@ -30,13 +30,14 @@ private function __construct(
30
30
private bool $ isFinal = true ,
31
31
private string $ rootNamespace = 'App ' ,
32
32
private ?string $ classSuffix = null ,
33
+ public readonly ?string $ implements = null ,
33
34
) {
34
35
if (str_starts_with (haystack: $ this ->namespace , needle: $ this ->rootNamespace )) {
35
36
$ this ->namespace = substr_replace (string: $ this ->namespace , replace: '' , offset: 0 , length: \strlen ($ this ->rootNamespace ) + 1 );
36
37
}
37
38
}
38
39
39
- public static function create (string $ class , ?string $ suffix = null , ?string $ extendsClass = null , bool $ isEntity = false , array $ useStatements = []): self
40
+ public static function create (string $ class , ?string $ suffix = null , ?string $ extendsClass = null , bool $ isEntity = false , array $ useStatements = [], ? string $ implements = null ): self
40
41
{
41
42
$ className = Str::getShortClassName ($ class );
42
43
@@ -50,13 +51,18 @@ public static function create(string $class, ?string $suffix = null, ?string $ex
50
51
$ useStatements ->addUseStatement ($ extendsClass );
51
52
}
52
53
54
+ if ($ implements ) {
55
+ $ useStatements ->addUseStatement ($ implements );
56
+ }
57
+
53
58
return new self (
54
59
className: Str::asClassName ($ className ),
55
60
namespace: Str::getNamespace ($ class ),
56
61
extends: null === $ extendsClass ? null : Str::getShortClassName ($ extendsClass ),
57
62
isEntity: $ isEntity ,
58
63
useStatementGenerator: $ useStatements ,
59
64
classSuffix: $ suffix ,
65
+ implements: null === $ implements ? null : Str::getShortClassName ($ implements ),
60
66
);
61
67
}
62
68
@@ -130,10 +136,17 @@ public function getClassDeclaration(): string
130
136
$ extendsDeclaration = \sprintf (' extends %s ' , $ this ->extends );
131
137
}
132
138
139
+ $ implementsDeclaration = '' ;
140
+
141
+ if (null !== $ this ->implements ) {
142
+ $ implementsDeclaration = \sprintf (' implements %s ' , $ this ->implements );
143
+ }
144
+
133
145
return \sprintf ('%sclass %s%s ' ,
134
146
$ this ->isFinal ? 'final ' : '' ,
135
147
$ this ->className ,
136
148
$ extendsDeclaration ,
149
+ $ implementsDeclaration
137
150
);
138
151
}
139
152
0 commit comments