Skip to content

Commit afcacb9

Browse files
authored
Merge pull request #3 from adrigar94/feature/new-type-of-skeleton-for-enum
feat: add enum type skeleton
2 parents 6d0c274 + b5cad11 commit afcacb9

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/wizardPhpSkeletons.ts

Lines changed: 39 additions & 1 deletion
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"
4647
// "trait",
47-
// "enum"
4848
];
4949
const type = await vscode.window.showQuickPick(
5050
acceptedTypes,
@@ -77,6 +77,9 @@ async function generatePhpSkeleton(type: string, fileName: string, namespace: st
7777
if (type === "interface") {
7878
return await generatePhpInterfaceSkeleton(fileName, namespace);
7979
}
80+
if (type === "enum") {
81+
return await generatePhpEnumSkeleton(fileName, namespace);
82+
}
8083
return "## TODO";
8184
}
8285

@@ -237,4 +240,39 @@ async function wizardInterfaceMethods(): Promise<Array<{ name: string, returnTyp
237240
}
238241

239242
return methods;
243+
}
244+
245+
async function generatePhpEnumSkeleton(className: string, namespace: string): Promise<string> {
246+
const cases = await wizardCasesEnum();
247+
248+
let declareCases: Array<string> = [];
249+
for (const caseDeclaration of cases) {
250+
declareCases.push(` case ${caseDeclaration.toUpperCase().replace(' ','_')};`);
251+
}
252+
253+
return `<?php
254+
255+
declare(strict_types=1);
256+
257+
namespace ${namespace};
258+
259+
enum ${className}
260+
{
261+
${declareCases.join('\n')}
262+
}`;
263+
}
264+
265+
async function wizardCasesEnum(): Promise<Array<string>>
266+
{
267+
let cases = [];
268+
let caseName = await vscode.window.showInputBox({
269+
prompt: "Enter a case name (press 'Cancel' or leave empty to finish)"
270+
});
271+
while (caseName) {
272+
cases.push(caseName);
273+
caseName = await vscode.window.showInputBox({
274+
prompt: "Enter another case name (press 'Cancel' or leave empty to finish)"
275+
});
276+
}
277+
return cases;
240278
}

0 commit comments

Comments
 (0)