@@ -285,22 +285,30 @@ it returns the value of `SOURCE' as it is."
285285
286286(defun phpstan-analyze-file (file )
287287 " 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)) " " )))
290290
291- (defun phpstan-get-executable ()
291+ (defun phpstan-get-executable-and-args ()
292292 " Return PHPStan excutable file and arguments."
293293 (cond
294294 ((eq 'docker phpstan-executable)
295- (list " run" " --rm" " -v"
295+ (list phpstan-docker-executable " run" " --rm" " -v"
296296 (concat (expand-file-name (php-project-get-root-dir)) " :/app" )
297297 phpstan-docker-image))
298298 ((and (consp phpstan-executable)
299299 (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)))
304312 ((and phpstan-flycheck-auto-set-executable
305313 (listp phpstan-executable)
306314 (stringp (car phpstan-executable))
@@ -310,18 +318,22 @@ it returns the value of `SOURCE' as it is."
310318 (let ((vendor-phpstan (expand-file-name " vendor/bin/phpstan"
311319 (php-project-get-root-dir))))
312320 (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)))
314325 ((executable-find " phpstan" ) (list (executable-find " phpstan" )))
315326 (t (error " PHPStan executable not found " )))))))
316327
317- (defun phpstan-get-command-args ()
328+ (defun phpstan-get-command-args (&optional include-executable )
318329 " Return command line argument for PHPStan."
319- (let ((executable (phpstan-get-executable))
330+ (let ((executable-and-args (phpstan-get-executable-and-args ))
320331 (path (phpstan-normalize-path (phpstan-get-config-file)))
321332 (autoload (phpstan-get-autoload-file))
322333 (memory-limit (phpstan-get-memory-limit))
323334 (level (phpstan-get-level)))
324- (append executable
335+ (append (if include-executable (list (car executable-and-args)) nil )
336+ (cdr executable-and-options)
325337 (list " analyze" " --error-format=raw" " --no-progress" " --no-interaction" )
326338 (and path (list " -c" path))
327339 (and autoload (list " -a" autoload))
0 commit comments