Skip to content

Commit e123008

Browse files
authored
Merge pull request #4 from adrigar94/feature/new-type-of-skeleton-for-trait
feat: add trait type skeleton
2 parents afcacb9 + dfac5c1 commit e123008

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

src/wizardPhpSkeletons.ts

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ async function wizardFileType(): Promise<string> {
4343
const acceptedTypes = [
4444
"class",
4545
"interface",
46-
"enum"
47-
// "trait",
46+
"enum",
47+
"trait"
4848
];
4949
const type = await vscode.window.showQuickPick(
5050
acceptedTypes,
@@ -80,7 +80,10 @@ async function generatePhpSkeleton(type: string, fileName: string, namespace: st
8080
if (type === "enum") {
8181
return await generatePhpEnumSkeleton(fileName, namespace);
8282
}
83-
return "## TODO";
83+
if (type === "trait") {
84+
return await generatePhpTraitSkeleton(fileName, namespace);
85+
}
86+
return "## not avaible";
8487
}
8588

8689
async function generatePhpClassSkeleton(className: string, namespace: string): Promise<string> {
@@ -242,12 +245,12 @@ async function wizardInterfaceMethods(): Promise<Array<{ name: string, returnTyp
242245
return methods;
243246
}
244247

245-
async function generatePhpEnumSkeleton(className: string, namespace: string): Promise<string> {
248+
async function generatePhpEnumSkeleton(enumName: string, namespace: string): Promise<string> {
246249
const cases = await wizardCasesEnum();
247250

248251
let declareCases: Array<string> = [];
249252
for (const caseDeclaration of cases) {
250-
declareCases.push(` case ${caseDeclaration.toUpperCase().replace(' ','_')};`);
253+
declareCases.push(` case ${caseDeclaration.toUpperCase().replace(' ', '_')};`);
251254
}
252255

253256
return `<?php
@@ -256,14 +259,13 @@ declare(strict_types=1);
256259
257260
namespace ${namespace};
258261
259-
enum ${className}
262+
enum ${enumName}
260263
{
261264
${declareCases.join('\n')}
262265
}`;
263266
}
264267

265-
async function wizardCasesEnum(): Promise<Array<string>>
266-
{
268+
async function wizardCasesEnum(): Promise<Array<string>> {
267269
let cases = [];
268270
let caseName = await vscode.window.showInputBox({
269271
prompt: "Enter a case name (press 'Cancel' or leave empty to finish)"
@@ -275,4 +277,32 @@ async function wizardCasesEnum(): Promise<Array<string>>
275277
});
276278
}
277279
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+
`;
278308
}

0 commit comments

Comments
 (0)