Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This extension contributes the following settings:
* `phpstan.memoryLimit`: memory limit, default 512M
* `phpstan.configuration`: path of configuration
* `phpstan.autoloadFile`: path of autoload file
* `phpstan.binPath`: path to the phpstan executable

## Known Issues

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"type": "string",
"default": null,
"description": "PhpStan autoload-file path"
},
"phpstan.binPath": {
"type": "string",
"default": null,
"description": "Path to phpstan executable"
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface PhpStanArgs {
memoryLimit?: string;
noProgress?: boolean;
path?: string;
binPath?: string;
}

export class PhpStanController {
Expand Down Expand Up @@ -128,6 +129,7 @@ export class PhpStanController {
"256M"
);
this._config.noProgress = workspace_config.get("phpstan.noProgress", true);
this._config.binPath = workspace_config.get("phpstan.binPath", undefined);
}

private _shouldAnalyseFile(document?: TextDocument) {
Expand Down Expand Up @@ -249,7 +251,7 @@ export class PhpStanController {
}

let phpstan = child_process.spawn(
this.makeCommandPath(cwd),
this.makeCommandPath(cwd, args.binPath),
this.makeCommandArgs(args),
this.setCommandOptions(cwd)
);
Expand Down Expand Up @@ -289,13 +291,16 @@ export class PhpStanController {
});
}

protected makeCommandPath(cwd: string) {
let binDir = "vendor/bin";
const basename = process.platform === "win32" ? "phpstan.bat" : "phpstan";
try {
binDir = child_process.execSync("composer config bin-dir", {cwd}).toString().trim();
} catch (err) {}
const binary = path.resolve(cwd, binDir, basename);
protected makeCommandPath(cwd: string, binary?: string) {

if (binary === undefined) {
let binDir = "vendor/bin";
try {
binDir = child_process.execSync("composer config bin-dir", {cwd}).toString().trim();
} catch (err) {}
binary = path.resolve(cwd, binDir, this._phpstan);
}

try {
fs.accessSync(binary, fs.constants.X_OK);
return binary;
Expand Down