Skip to content

Commit d7a27b4

Browse files
committed
fix: plugin namespace arguments
1 parent ac3cbc3 commit d7a27b4

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to the "magento-toolbox" extension will be documented in thi
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7+
## [Unreleased]
8+
- Fixed: Generated plugin class arguments contain an incorrect namespace
9+
710
## [1.3.0] - 2025-03-17
811

912
- Added: Jump to module command

src/generator/plugin/PluginClassGenerator.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,22 @@ export default class PluginClassGenerator extends FileGenerator {
8989
return type;
9090
}
9191

92-
const namespace = this.subjectClass.namespace;
93-
const typeName = type.startsWith('\\') ? type.slice(1) : type;
92+
if (type.startsWith('\\')) {
93+
return type;
94+
}
95+
96+
if (type === this.subjectClass.name) {
97+
return `${this.subjectClass.namespace}\\${type}`;
98+
}
99+
100+
const useItems = this.subjectClass.parent.useItems;
101+
102+
for (const useItem of useItems) {
103+
if (useItem.name === type) {
104+
return useItem.fullName;
105+
}
106+
}
94107

95-
return `${namespace}\\${typeName}`;
108+
return type;
96109
}
97110
}

src/parser/php/PhpUseItem.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ export class PhpUseItem extends PhpNode<NodeKind.UseItem> {
1313
}
1414

1515
public get fullName() {
16-
if (this.ast.alias) {
17-
return this.ast.alias.name;
18-
}
1916
return this.ast.name;
2017
}
2118

2219
public get name() {
23-
if (this.ast.alias) {
24-
return this.ast.alias.name;
25-
}
26-
2720
const parts = this.ast.name.split('\\');
2821
return last(parts)!;
2922
}
23+
24+
public get alias() {
25+
return this.ast.alias?.name;
26+
}
3027
}

0 commit comments

Comments
 (0)