Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused about phpstan-working-dir #14

Open
MarkRedeman opened this issue Aug 23, 2018 · 0 comments
Open

Confused about phpstan-working-dir #14

MarkRedeman opened this issue Aug 23, 2018 · 0 comments

Comments

@MarkRedeman
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant