Skip to content

Commit 541552b

Browse files
committed
050
1 parent 5aad2d0 commit 541552b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "php-namespace-resolver",
33
"displayName": "PHP Namespace Resolver",
44
"description": "Import and expand php namespaces",
5-
"version": "0.4.9",
5+
"version": "0.5.0",
66
"publisher": "ctf0",
77
"author": "ctf0",
88
"repository": "https://github.com/ctf0/PHP-Namespace-Resolver",

src/Resolver.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import BUILT_IN_CLASSES_FB from './classes';
99

1010
const COMP_JSON = 'composer.json';
1111
const regexWordWithNamespace = new RegExp(/[a-zA-Z0-9\\]+/);
12+
const DATA_TYPES = ['object', 'resource', 'array', 'string', 'int', 'float', 'bool', 'null', 'void', 'mixed'];
1213

1314
export default class Resolver {
1415
BUILT_IN_CLASSES: any = BUILT_IN_CLASSES_FB;
@@ -160,22 +161,26 @@ export default class Resolver {
160161
const phpClasses: any = [];
161162

162163
while (matches = regex.exec(text)) {
163-
phpClasses.push(matches[1]);
164+
const txt = matches[1];
165+
166+
if (!this.BUILT_IN_CLASSES.includes(txt)) {
167+
phpClasses.push(txt);
168+
}
164169
}
165170

166171
return phpClasses;
167172
}
168173

169174
getFromReturnType(text) {
170-
const regex = /(?<=\): )([A-Z_][A-Za-z0-9_]*)/gm;
175+
const regex = /(?<=\):( )?)([A-Z_][A-Za-z0-9_]*)/gm;
171176

172177
let matches: any = [];
173178
const phpClasses: any = [];
174179

175180
while (matches = regex.exec(text)) {
176181
const txt = matches[1];
177182

178-
if (txt !== 'self') {
183+
if (!this.BUILT_IN_CLASSES.includes(txt)) {
179184
phpClasses.push(txt);
180185
}
181186
}

0 commit comments

Comments
 (0)