|
72 | 72 | :type 'boolean
|
73 | 73 | :group 'phpstan)
|
74 | 74 |
|
| 75 | +(defcustom phpstan-enable-on-no-config-file t |
| 76 | + "If T, activate configuration from composer even when `phpstan.neon' is not found." |
| 77 | + :type 'boolean |
| 78 | + :group 'phpstan) |
| 79 | + |
75 | 80 | ;;;###autoload
|
76 | 81 | (progn
|
77 | 82 | (defvar phpstan-working-dir nil
|
|
112 | 117 | (and (eq 'root (car v)) (stringp (cdr v)))
|
113 | 118 | (null v) (stringp v)))))
|
114 | 119 |
|
| 120 | +;;;###autoload |
| 121 | +(progn |
| 122 | + (defvar-local phpstan-autoload-file nil |
| 123 | + "Path to autoload file for PHPStan. |
| 124 | +
|
| 125 | +STRING |
| 126 | + Path to `phpstan' autoload file. |
| 127 | +
|
| 128 | +`(root . STRING)' |
| 129 | + Relative path to `phpstan' configuration file from project root directory. |
| 130 | +
|
| 131 | +NIL |
| 132 | + If `phpstan-enable-on-no-config-file', search \"vendor/autoload.php\" in (phpstan-get-working-dir).") |
| 133 | + (put 'phpstan-autoload-file 'safe-local-variable |
| 134 | + #'(lambda (v) (if (consp v) |
| 135 | + (and (eq 'root (car v)) (stringp (cdr v))) |
| 136 | + (null v) (stringp v))))) |
| 137 | + |
115 | 138 | ;;;###autoload
|
116 | 139 | (progn
|
117 | 140 | (defvar-local phpstan-level nil
|
|
177 | 200 | ((stringp phpstan-working-dir) phpstan-working-dir)
|
178 | 201 | (t (php-project-get-root-dir))))
|
179 | 202 |
|
| 203 | +(defun phpstan-enabled () |
| 204 | + "Return non-NIL if PHPStan configured or Composer detected." |
| 205 | + (or (phpstan-get-config-file) |
| 206 | + (phpstan-get-autoload-file) |
| 207 | + (and phpstan-enable-on-no-config-file |
| 208 | + (php-project-get-root-dir)))) |
| 209 | + |
180 | 210 | (defun phpstan-get-config-file ()
|
181 | 211 | "Return path to phpstan configure file or `NIL'."
|
182 | 212 | (if phpstan-config-file
|
|
192 | 222 | if dir
|
193 | 223 | return (expand-file-name name dir))))))
|
194 | 224 |
|
| 225 | +(defun phpstan-get-autoload-file () |
| 226 | + "Return path to autoload file or NIL." |
| 227 | + (when phpstan-autoload-file |
| 228 | + (if (and (consp phpstan-autoload-file) |
| 229 | + (eq 'root (car phpstan-autoload-file))) |
| 230 | + (expand-file-name (cdr phpstan-autoload-file) (php-project-get-root-dir)) |
| 231 | + phpstan-autoload-file))) |
| 232 | + |
195 | 233 | (defun phpstan-normalize-path (source-original &optional source)
|
196 | 234 | "Return normalized source file path to pass by `SOURCE-ORIGINAL' OR `SOURCE'.
|
197 | 235 |
|
@@ -249,14 +287,15 @@ it returns the value of `SOURCE' as it is."
|
249 | 287 | (defun phpstan-get-command-args ()
|
250 | 288 | "Return command line argument for PHPStan."
|
251 | 289 | (let ((executable (phpstan-get-executable))
|
252 |
| - (args (list "analyze" "--error-format=raw" "--no-progress" "--no-interaction")) |
253 | 290 | (path (phpstan-normalize-path (phpstan-get-config-file)))
|
| 291 | + (autoload (phpstan-get-autoload-file)) |
254 | 292 | (level (phpstan-get-level)))
|
255 |
| - (when path |
256 |
| - (setq args (append args (list "-c" path)))) |
257 |
| - (when level |
258 |
| - (setq args (append args (list "-l" level)))) |
259 |
| - (append executable args))) |
| 293 | + (append executable |
| 294 | + (list "analyze" "--error-format=raw" "--no-progress" "--no-interaction") |
| 295 | + (and path (list "-c" path)) |
| 296 | + (and autoload (list "-a" autoload)) |
| 297 | + (and level (list "-l" level)) |
| 298 | + (list "--")))) |
260 | 299 |
|
261 | 300 | (provide 'phpstan)
|
262 | 301 | ;;; phpstan.el ends here
|
0 commit comments