Skip to content

Commit 3748533

Browse files
committed
Add phpstan-working-dir for working directory of PHPStan
1 parent dffcad7 commit 3748533

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

phpstan.el

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
:type 'boolean
4949
:group 'phpstan)
5050

51+
;;;###autoload
52+
(progn
53+
(defvar phpstan-working-dir nil)
54+
(make-variable-buffer-local 'phpstan-working-dir)
55+
(put 'phpstan-working-dir 'safe-local-variable
56+
#'(lambda (v) (if (consp v)
57+
(and (eq 'root (car v)) (stringp (cdr v)))
58+
(null v) (stringp v)))))
59+
5160
;;;###autoload
5261
(progn
5362
(defvar phpstan-config-file nil)
@@ -108,6 +117,23 @@ NIL
108117
(or (eq 'docker v) (null v) (stringp v))))))
109118

110119
;; Functions:
120+
(defun phpstan-get-working-dir ()
121+
"Return working directory of PHPStan.
122+
123+
This is different from the project root.
124+
125+
STRING
126+
Absolute path to `phpstan' working directory.
127+
128+
`(root . STRING)'
129+
Relative path to `phpstan' working directory.
130+
131+
NIL
132+
Use (php-project-get-root-dir) as working directory."
133+
(if (and phpstan-working-dir (consp phpstan-working-dir) (eq 'root (car phpstan-working-dir)))
134+
(expand-file-name (cdr phpstan-working-dir) (php-project-get-root-dir))
135+
(php-project-get-root-dir)))
136+
111137
(defun phpstan-get-config-file ()
112138
"Return path to phpstan configure file or `NIL'."
113139
(if phpstan-config-file
@@ -197,7 +223,7 @@ it returns the value of `SOURCE' as it is."
197223
(eval (phpstan-normalize-path
198224
(flycheck-save-buffer-to-temp #'flycheck-temp-file-inplace)
199225
(flycheck-save-buffer-to-temp #'flycheck-temp-file-system))))
200-
:working-directory (lambda (_) (php-project-get-root-dir))
226+
:working-directory (lambda (_) (phpstan-get-working-dir))
201227
:enabled (lambda () (phpstan-get-config-file-and-set-flycheck-variable))
202228
:error-patterns
203229
((error line-start (1+ (not (any ":"))) ":" line ":" (message) line-end))

test-docker.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// Local Variables:
1111
// phpstan-executable: docker
12+
// phpstan-working-dir: (root . "tests/")
1213
// phpstan-config-file: (root . "tests/phpstan-docker.neon")
1314
// phpstan-level: 7
1415
// End:

tests/phpstan-docker.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
parameters:
2-
bootstrap: %rootDir%/../../../../app/tests/bootstrap.php
2+
bootstrap: %currentWorkingDirectory%/../app/tests/bootstrap.php

0 commit comments

Comments
 (0)