@@ -211,7 +211,7 @@ it returns the value of `SOURCE' as it is."
211211 (t phpstan-level)))
212212
213213(defun phpstan-get-executable ()
214- " Return PHPStan excutable file."
214+ " Return PHPStan excutable file and arguments ."
215215 (cond
216216 ((eq 'docker phpstan-executable)
217217 (list " run" " --rm" " -v"
@@ -229,18 +229,27 @@ it returns the value of `SOURCE' as it is."
229229 (let ((vendor-phpstan (expand-file-name " vendor/bin/phpstan"
230230 (php-project-get-root-dir))))
231231 (cond
232- ((file-exists-p vendor-phpstan) vendor-phpstan)
233- ((executable-find " phpstan" ) (executable-find " phpstan" ))
232+ ((file-exists-p vendor-phpstan) ( list vendor-phpstan) )
233+ ((executable-find " phpstan" ) (list ( executable-find " phpstan" ) ))
234234 (t (error " PHPStan executable not found " )))))))
235235
236+ (defun phpstan-get-command-args ()
237+ " Return command line argument for PHPStan."
238+ (let ((executable (phpstan-get-executable))
239+ (args (list " analyze" " --errorFormat=raw" " --no-progress" " --no-interaction" ))
240+ (path (phpstan-normalize-path (phpstan-get-config-file)))
241+ (level (phpstan-get-level)))
242+ (when path
243+ (setq args (append args (list " -c" path))))
244+ (when level
245+ (setq args (append args (list " -l" level))))
246+ (append executable args)))
247+
236248;;;### autoload
237249(when (featurep 'flycheck )
238250 (flycheck-define-checker phpstan
239251 " PHP static analyzer based on PHPStan."
240- :command (" php" (eval (phpstan-get-executable))
241- " analyze" " --errorFormat=raw" " --no-progress" " --no-interaction"
242- " -c" (eval (phpstan-normalize-path (phpstan-get-config-file)))
243- " -l" (eval (phpstan-get-level))
252+ :command (" php" (eval (phpstan-get-command-args))
244253 (eval (phpstan-normalize-path
245254 (flycheck-save-buffer-to-temp #'flycheck-temp-file-inplace )
246255 (flycheck-save-buffer-to-temp #'flycheck-temp-file-system ))))
0 commit comments