emacs-php / emacs-php/phpstan.el
Confused about `phpstan-working-dir`
- Dominant language
- Emacs Lisp
- Stars
- 28
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/emacs-php/phpstan.el/blob/master/flycheck-phpstan.el#L50) 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:
```diff
(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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.