Hi, thanks for this great package!
I'm a bit confused about the usage of the phpstan-working-dir variable.
I'm trying to setup phpstan.el so that I don't have to have a phpstan.neon file in a project.
I got this working by setting (setq phpstan-working-dir ".") so that the enabled check passes, however this seems very hacky.
Could you explain to me the use of phpstan-working-dir? The documentation mentions it should be different than the project root but doesn't give an explicit example.
In addition, I think I've found a bug while trying to figure out the use case of phpstan-working-dir. I tried the same "hack" (not having a phpstan.neon file and setting (setq phpstan-working-dir ".")) when using Docker.
In this case phpstan-get-config-file returns NIL which is passed to phpstan-normalize-path however since prefix is set to /app the function throws an error
Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
replace-regexp-in-string("\\`/home/mark/Projects/testing-phpstan/" "" nil t t)
This is easily fixed by changing the function:
(defun phpstan-normalize-path (source-original &optional source)
"Return normalized source file path to pass by `SOURCE-ORIGINAL' OR `SOURCE'.
If neither `phpstan-replace-path-prefix' nor executable docker is set,
it returns the value of `SOURCE' as it is."
(let ((root-directory (expand-file-name (php-project-get-root-dir)))
(prefix
(or phpstan-replace-path-prefix
(cond
((eq 'docker phpstan-executable) "/app")
((and (consp phpstan-executable)
(string= "docker" (car phpstan-executable))) "/app")))))
- (if prefix
+ (if (and prefix source-original)
(expand-file-name
(replace-regexp-in-string (concat "\\`" (regexp-quote root-directory))
""
source-original t t)
prefix)
(or source source-original))))
I'm happy to send a PR to fix the above issue however, it seems quite hacky.
Hi, thanks for this great package!
I'm a bit confused about the usage of the
phpstan-working-dirvariable.I'm trying to setup phpstan.el so that I don't have to have a
phpstan.neonfile in a project.I got this working by setting
(setq phpstan-working-dir ".")so that the enabled check passes, however this seems very hacky.Could you explain to me the use of
phpstan-working-dir? The documentation mentions it should be different than the project root but doesn't give an explicit example.In addition, I think I've found a bug while trying to figure out the use case of
phpstan-working-dir. I tried the same "hack" (not having aphpstan.neonfile and setting(setq phpstan-working-dir ".")) when using Docker.In this case
phpstan-get-config-filereturnsNILwhich is passed tophpstan-normalize-pathhowever sinceprefixis set to/appthe function throws an errorThis is easily fixed by changing the function:
(defun phpstan-normalize-path (source-original &optional source) "Return normalized source file path to pass by `SOURCE-ORIGINAL' OR `SOURCE'. If neither `phpstan-replace-path-prefix' nor executable docker is set, it returns the value of `SOURCE' as it is." (let ((root-directory (expand-file-name (php-project-get-root-dir))) (prefix (or phpstan-replace-path-prefix (cond ((eq 'docker phpstan-executable) "/app") ((and (consp phpstan-executable) (string= "docker" (car phpstan-executable))) "/app"))))) - (if prefix + (if (and prefix source-original) (expand-file-name (replace-regexp-in-string (concat "\\`" (regexp-quote root-directory)) "" source-original t t) prefix) (or source source-original))))I'm happy to send a PR to fix the above issue however, it seems quite hacky.