Skip to content

Commit d559ee1

Browse files
committed
Add phpstan-get-config-file-and-set-flycheck-variable as side effect
1 parent 4555592 commit d559ee1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

phpstan.el

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
(and (stringp v)
6868
(string-match-p "\\`[0-9]\\'" v))))))
6969

70+
;; Usually it is defined dynamically by flycheck
71+
(defvar flycheck-phpstan-executable)
72+
7073
;;;###autoload
7174
(progn
7275
(defvar phpstan-executable nil
@@ -103,6 +106,17 @@ NIL
103106
if dir
104107
return (expand-file-name name dir))))
105108

109+
(defun phpstan-get-config-file-and-set-flycheck-variable ()
110+
"Return path to phpstan configure file, and set buffer execute in side effect."
111+
(prog1 (phpstan-get-config-file)
112+
(when (and phpstan-flycheck-auto-set-executable
113+
(not (and (boundp 'flycheck-phpstan-executable)
114+
(symbol-value 'flycheck-phpstan-executable)))
115+
(stringp (car phpstan-executable))
116+
(listp (cdr phpstan-executable)))
117+
(set (make-local-variable 'flycheck-phpstan-executable)
118+
(car phpstan-executable)))))
119+
106120
(defun phpstan-get-level ()
107121
"Return path to phpstan configure file or `NIL'."
108122
(cond
@@ -139,7 +153,7 @@ NIL
139153
"-l" (eval (phpstan-get-level))
140154
source)
141155
:working-directory (lambda (_) (php-project-get-root-dir))
142-
:enabled (lambda () (phpstan-get-config-file))
156+
:enabled (lambda () (phpstan-get-config-file-and-set-flycheck-variable))
143157
:error-patterns
144158
((error line-start (1+ (not (any ":"))) ":" line ":" (message) line-end))
145159
:modes (php-mode)

0 commit comments

Comments
 (0)