Skip to content

Commit 4555592

Browse files
committed
Modify phpstan-executable specification
1 parent 63fd9eb commit 4555592

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

phpstan.el

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,26 @@
6969

7070
;;;###autoload
7171
(progn
72-
(defvar phpstan-executable nil)
72+
(defvar phpstan-executable nil
73+
"PHPStan excutable file.
74+
75+
STRING
76+
Absolute path to `phpstan' executable file.
77+
78+
`(root . STRING)'
79+
Relative path to `phpstan' executable file.
80+
81+
`(STRING . (ARGUMENTS ...))'
82+
Command name and arguments.
83+
84+
NIL
85+
Auto detect `phpstan' executable file.")
7386
(make-variable-buffer-local 'phpstan-executable)
7487
(put 'phpstan-executable 'safe-local-variable
7588
#'(lambda (v) (if (consp v)
76-
(and (eq 'root (car v)) (stringp (cdr v)))
77-
(null v) (stringp v)))))
89+
(or (and (eq 'root (car v)) (stringp (cdr v)))
90+
(and (stringp (car v)) (listp (cdr v))))
91+
(or (null v) (stringp v))))))
7892

7993
;; Functions:
8094
(defun phpstan-get-config-file ()
@@ -98,15 +112,22 @@
98112

99113
(defun phpstan-get-executable ()
100114
"Return PHPStan excutable file."
101-
(let ((executable (or phpstan-executable '(root . "vendor/bin/phpstan"))))
102-
(when (and (consp executable)
103-
(eq 'root (car executable)))
104-
(setq executable
105-
(expand-file-name (cdr executable) (php-project-get-root-dir))))
106-
(if (file-exists-p executable)
107-
executable
108-
(or (executable-find "phpstan")
109-
(error "PHPStan executable not found")))))
115+
(cond
116+
((and (consp phpstan-executable)
117+
(eq 'root (car phpstan-executable)))
118+
(expand-file-name (cdr phpstan-executable) (php-project-get-root-dir)))
119+
((and phpstan-flycheck-auto-set-executable
120+
(listp phpstan-executable)
121+
(stringp (car phpstan-executable))
122+
(listp (cdr phpstan-executable)))
123+
(cdr phpstan-executable))
124+
((null phpstan-executable)
125+
(let ((vendor-phpstan (expand-file-name "vendor/bin/phpstan"
126+
(php-project-get-root-dir))))
127+
(cond
128+
((file-exists-p vendor-phpstan) vendor-phpstan)
129+
((executable-find "phpstan") (executable-find "phpstan"))
130+
(t (error "PHPStan executable not found")))))))
110131

111132
;;;###autoload
112133
(when (featurep 'flycheck)

0 commit comments

Comments
 (0)