Skip to content

Commit 3b6b24a

Browse files
authored
Merge pull request #8 from adrigar94/bugfix/fix-generate-namespace-in-root-src
fix: add case when files is created at root namespace
2 parents ca035c6 + ec76b44 commit 3b6b24a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/utils/files.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,28 @@ function getPsr4(): { [key: string]: string } {
6262
return autoload['psr-4'];
6363
}
6464

65-
export function generateNamespace(folder: vscode.Uri, fileName: string): string {
65+
export function generateNamespace(folder: vscode.Uri): string {
6666
let folderPath = folder.fsPath;
6767
const psr4 = getPsr4();
6868

6969
const rootPath = getRootPath();
7070
folderPath = folderPath.replace(rootPath??'', '');
7171
folderPath = folderPath.replace(/\/|\\/g, '\\').replace(/\\/, '');
7272

73+
74+
7375
for (const prefix of Object.keys(psr4)) {
7476
const basePath = psr4[prefix].replace(/\/|\\/g, '\\\\');
7577
const prefixRegex = new RegExp(`^${basePath}`);
7678

7779
if (prefixRegex.test(folderPath)) {
7880
const relativePath = folderPath.replace(prefixRegex, '');
7981
const namespace = prefix + relativePath;
80-
vscode.window.showInformationMessage("in1");
8182
return namespace;
8283
}
84+
else if(basePath === folderPath.concat('\\\\')){
85+
return prefix.replace(/\\/, '');
86+
}
8387
}
84-
vscode.window.showInformationMessage("out");
8588
return folderPath;
8689
}

src/wizardPhpSkeletons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function wizardGeneratePhpSkeleton() {
88
const type = await wizardFileType();
99
const fileName = await wizardFileName(type);
1010

11-
const namespace = generateNamespace(folder, fileName);
11+
const namespace = generateNamespace(folder);
1212

1313
const classSkeleton = await generatePhpSkeleton(type, fileName, namespace);
1414

0 commit comments

Comments
 (0)