Skip to content

Commit 70cb256

Browse files
committed
Add 'docker keyword
1 parent 05c9f76 commit 70cb256

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

phpstan.el

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
(put 'phpstan-replace-path-prefix 'safe-local-variable
7575
#'(lambda (v) (or (null v) (stringp v)))))
7676

77+
(defconst phpstan-docker-executable "docker")
78+
7779
;; Usually it is defined dynamically by flycheck
7880
(defvar flycheck-phpstan-executable)
7981

@@ -85,6 +87,9 @@
8587
STRING
8688
Absolute path to `phpstan' executable file.
8789
90+
`docker'
91+
Use Docker using phpstan/docker-image.
92+
8893
`(root . STRING)'
8994
Relative path to `phpstan' executable file.
9095
@@ -98,7 +103,7 @@ NIL
98103
#'(lambda (v) (if (consp v)
99104
(or (and (eq 'root (car v)) (stringp (cdr v)))
100105
(and (stringp (car v)) (listp (cdr v))))
101-
(or (null v) (stringp v))))))
106+
(or (eq 'docker v) (null v) (stringp v))))))
102107

103108
;; Functions:
104109
(defun phpstan-get-config-file ()
@@ -119,10 +124,14 @@ NIL
119124
(when (and phpstan-flycheck-auto-set-executable
120125
(not (and (boundp 'flycheck-phpstan-executable)
121126
(symbol-value 'flycheck-phpstan-executable)))
122-
(stringp (car phpstan-executable))
123-
(listp (cdr phpstan-executable)))
127+
(or (eq 'docker phpstan-executable)
128+
(and (consp phpstan-executable)
129+
(stringp (car phpstan-executable))
130+
(listp (cdr phpstan-executable)))))
124131
(set (make-local-variable 'flycheck-phpstan-executable)
125-
(car phpstan-executable)))))
132+
(if (eq 'docker phpstan-executable)
133+
phpstan-docker-executable
134+
(car phpstan-executable))))))
126135

127136
(defun phpstan-normalize-path (source-original source)
128137
"Return normalized source file path to pass by `SOURCE-ORIGINAL' OR `SOURCE'.
@@ -133,6 +142,7 @@ it returns the value of `SOURCE' as it is."
133142
(prefix
134143
(cond
135144
((not (null phpstan-replace-path-prefix)) phpstan-replace-path-prefix)
145+
((eq 'docker phpstan-executable) "/app")
136146
((and (consp phpstan-executable)
137147
(string= "docker" (car phpstan-executable))) "/app"))))
138148
(if prefix
@@ -153,6 +163,10 @@ it returns the value of `SOURCE' as it is."
153163
(defun phpstan-get-executable ()
154164
"Return PHPStan excutable file."
155165
(cond
166+
((eq 'docker phpstan-executable)
167+
(list "run" "--rm" "-v"
168+
(concat (expand-file-name (php-project-get-root-dir)) ":/app")
169+
"phpstan/phpstan"))
156170
((and (consp phpstan-executable)
157171
(eq 'root (car phpstan-executable)))
158172
(expand-file-name (cdr phpstan-executable) (php-project-get-root-dir)))

test-docker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
echo FOO;
99

1010
// Local Variables:
11-
// phpstan-executable: ("docker" "run" "--rm" "-v" "/Users/megurine/repo/emacs/phpstan.el/:/app" "phpstan/phpstan")
11+
// phpstan-executable: docker
1212
// phpstan-config-file: "/app/tests/phpstan-docker.neon"
1313
// phpstan-level: 7
1414
// End:

0 commit comments

Comments
 (0)