@@ -43,9 +43,8 @@ async function wizardFileType(): Promise<string> {
43
43
const acceptedTypes = [
44
44
"class" ,
45
45
"interface" ,
46
- // "trait",
47
- // "enum",
48
- // "value object (immutable class)"
46
+ "enum" ,
47
+ "trait"
49
48
] ;
50
49
const type = await vscode . window . showQuickPick (
51
50
acceptedTypes ,
@@ -78,7 +77,13 @@ async function generatePhpSkeleton(type: string, fileName: string, namespace: st
78
77
if ( type === "interface" ) {
79
78
return await generatePhpInterfaceSkeleton ( fileName , namespace ) ;
80
79
}
81
- return "## TODO" ;
80
+ if ( type === "enum" ) {
81
+ return await generatePhpEnumSkeleton ( fileName , namespace ) ;
82
+ }
83
+ if ( type === "trait" ) {
84
+ return await generatePhpTraitSkeleton ( fileName , namespace ) ;
85
+ }
86
+ return "## not avaible" ;
82
87
}
83
88
84
89
async function generatePhpClassSkeleton ( className : string , namespace : string ) : Promise < string > {
@@ -90,6 +95,7 @@ async function generatePhpClassSkeleton(className: string, namespace: string): P
90
95
}
91
96
92
97
let gettersAndSetters = "" ;
98
+ let equalsCondition = [ ] ;
93
99
for ( const property of properties ) {
94
100
const capitalizedName = capitalize ( property . name ) ;
95
101
gettersAndSetters += `
@@ -101,7 +107,16 @@ async function generatePhpClassSkeleton(className: string, namespace: string): P
101
107
{
102
108
$this->${ property . name } = $${ property . name } ;
103
109
}` ;
110
+ equalsCondition . push ( `$this->get${ capitalizedName } () == $toCompare->get${ capitalizedName } ()` ) ;
111
+ }
112
+
113
+
114
+ const equalsMethod = equalsCondition . length ? `
115
+ public function equals(self $toCompare): boolean
116
+ {
117
+ return ${ equalsCondition . join ( '\n AND ' ) } ;
104
118
}
119
+ ` : '' ;
105
120
106
121
const skeleton = `<?php
107
122
@@ -116,6 +131,8 @@ class ${className}
116
131
}
117
132
118
133
${ gettersAndSetters }
134
+
135
+ ${ equalsMethod }
119
136
}` ;
120
137
121
138
return skeleton ;
@@ -226,4 +243,66 @@ async function wizardInterfaceMethods(): Promise<Array<{ name: string, returnTyp
226
243
}
227
244
228
245
return methods ;
246
+ }
247
+
248
+ async function generatePhpEnumSkeleton ( enumName : string , namespace : string ) : Promise < string > {
249
+ const cases = await wizardCasesEnum ( ) ;
250
+
251
+ let declareCases : Array < string > = [ ] ;
252
+ for ( const caseDeclaration of cases ) {
253
+ declareCases . push ( ` case ${ caseDeclaration . toUpperCase ( ) . replace ( ' ' , '_' ) } ;` ) ;
254
+ }
255
+
256
+ return `<?php
257
+
258
+ declare(strict_types=1);
259
+
260
+ namespace ${ namespace } ;
261
+
262
+ enum ${ enumName }
263
+ {
264
+ ${ declareCases . join ( '\n' ) }
265
+ }` ;
266
+ }
267
+
268
+ async function wizardCasesEnum ( ) : Promise < Array < string > > {
269
+ let cases = [ ] ;
270
+ let caseName = await vscode . window . showInputBox ( {
271
+ prompt : "Enter a case name (press 'Cancel' or leave empty to finish)"
272
+ } ) ;
273
+ while ( caseName ) {
274
+ cases . push ( caseName ) ;
275
+ caseName = await vscode . window . showInputBox ( {
276
+ prompt : "Enter another case name (press 'Cancel' or leave empty to finish)"
277
+ } ) ;
278
+ }
279
+ return cases ;
280
+ }
281
+
282
+ async function generatePhpTraitSkeleton ( traitName : string , namespace : string ) : Promise < string > {
283
+ const methods = await wizardInterfaceMethods ( ) ;
284
+
285
+ let declareMethods = [ ] ;
286
+ for ( const method of methods ) {
287
+ let paramsMethod : Array < string > = [ ] ;
288
+ for ( const param of method . params ) {
289
+ paramsMethod . push ( `${ param . type } $${ param . name } ` ) ;
290
+ }
291
+ declareMethods . push ( ` public function ${ method . name } (${ paramsMethod . join ( ', ' ) } ): ${ method . returnType }
292
+ {
293
+ ## TODO
294
+ }` ) ;
295
+ }
296
+
297
+ return `<?php
298
+
299
+ declare(strict_types=1);
300
+
301
+ namespace ${ namespace } ;
302
+
303
+ interface ${ traitName }
304
+ {
305
+ ${ declareMethods . join ( "\n\n" ) }
306
+ }
307
+ ` ;
229
308
}
0 commit comments