@@ -285,22 +285,30 @@ it returns the value of `SOURCE' as it is."
285
285
286
286
(defun phpstan-analyze-file (file )
287
287
" Analyze a PHPScript FILE using PHPStan."
288
- (interactive " fChoose a PHP script: " )
289
- (compile (mapconcat #'shell-quote-argument (append (phpstan-get-command-args) (list file)) " " )))
288
+ (interactive ( list ( expand-file-name ( read-file-name " Choose a PHP script: " ))) )
289
+ (compile (mapconcat #'shell-quote-argument (append (phpstan-get-command-args t ) (list file)) " " )))
290
290
291
- (defun phpstan-get-executable ()
291
+ (defun phpstan-get-executable-and-args ()
292
292
" Return PHPStan excutable file and arguments."
293
293
(cond
294
294
((eq 'docker phpstan-executable)
295
- (list " run" " --rm" " -v"
295
+ (list phpstan-docker-executable " run" " --rm" " -v"
296
296
(concat (expand-file-name (php-project-get-root-dir)) " :/app" )
297
297
phpstan-docker-image))
298
298
((and (consp phpstan-executable)
299
299
(eq 'root (car phpstan-executable)))
300
- (list
301
- (expand-file-name (cdr phpstan-executable) (php-project-get-root-dir))))
302
- ((and (stringp phpstan-executable) (file-exists-p phpstan-executable))
303
- (list phpstan-executable))
300
+ (let ((phpstan (expand-file-name (cdr phpstan-executable) (php-project-get-root-dir))))
301
+ (if (file-executable-p phpstan)
302
+ (list phpstan)
303
+ (list php-executable phpstan))))
304
+ ((and (stringp phpstan-executable))
305
+ (unless (file-exists-p phpstan-executable)
306
+ (user-error " File %s is not exists. Please check `phpstan-executable' variable" phpstan-executable))
307
+ (when (file-directory-p phpstan-executable)
308
+ (user-error " Path %s is a directory. Please check `phpstan-executable' variable" phpstan-executable))
309
+ (if (file-executable-p phpstan-executable)
310
+ (list phpstan-executable)
311
+ (list php-executable phpstan-executable)))
304
312
((and phpstan-flycheck-auto-set-executable
305
313
(listp phpstan-executable)
306
314
(stringp (car phpstan-executable))
@@ -310,18 +318,22 @@ it returns the value of `SOURCE' as it is."
310
318
(let ((vendor-phpstan (expand-file-name " vendor/bin/phpstan"
311
319
(php-project-get-root-dir))))
312
320
(cond
313
- ((file-exists-p vendor-phpstan) (list vendor-phpstan))
321
+ ((file-exists-p vendor-phpstan)
322
+ (if (file-executable-p vendor-phpstan)
323
+ (list vendor-phpstan)
324
+ (list php-executable vendor-phpstan)))
314
325
((executable-find " phpstan" ) (list (executable-find " phpstan" )))
315
326
(t (error " PHPStan executable not found " )))))))
316
327
317
- (defun phpstan-get-command-args ()
328
+ (defun phpstan-get-command-args (&optional include-executable )
318
329
" Return command line argument for PHPStan."
319
- (let ((executable (phpstan-get-executable))
330
+ (let ((executable-and-args (phpstan-get-executable-and-args ))
320
331
(path (phpstan-normalize-path (phpstan-get-config-file)))
321
332
(autoload (phpstan-get-autoload-file))
322
333
(memory-limit (phpstan-get-memory-limit))
323
334
(level (phpstan-get-level)))
324
- (append executable
335
+ (append (if include-executable (list (car executable-and-args)) nil )
336
+ (cdr executable-and-options)
325
337
(list " analyze" " --error-format=raw" " --no-progress" " --no-interaction" )
326
338
(and path (list " -c" path))
327
339
(and autoload (list " -a" autoload))
0 commit comments