|
1 | 1 | * phpstan.el |
2 | 2 | Emacs interface to [[https://github.com/phpstan/phpstan][PHPStan]], includes checker for [[http://www.flycheck.org/en/latest/][Flycheck]]. |
| 3 | +** Support version |
| 4 | +- Emacs 24+ |
| 5 | +- PHPStan latest/dev-master (NOT support 0.9 seriese) |
| 6 | +** How to install |
| 7 | +*** Install from MELPA |
| 8 | +/TBD/ |
| 9 | +** How to use |
| 10 | +*** For Flycheck user |
| 11 | +/TBD/ |
| 12 | +*** For Flymake user |
| 13 | +The function for flymake will be implemented soon. You do not have to depend on flycheck. |
| 14 | +*** Using Docker (phpstan/docker-image) |
| 15 | +Install [[https://www.docker.com/community-edition][Docker CE]] and [[https://github.com/phpstan/docker-image][phpstan/docker-image]](latest). |
| 16 | + |
| 17 | +If you always use Docker for PHPStan, add the following into your ~.emacs~ file (~~/.emacs.d/init.el~) |
| 18 | +#+BEGIN_SRC emacs-lisp |
| 19 | +(setq-default phpstan-executable 'docker) |
| 20 | +#+END_SRC |
| 21 | + |
| 22 | +Put the following into ~.dir-locals.el~ files on the root directory of project. |
| 23 | +#+BEGIN_SRC emacs-lisp |
| 24 | +((nil . ((php-project-root . git) |
| 25 | + (phpstan-executable . docker) |
| 26 | + (phpstan-working-dir . (root . "path/to/dir")) |
| 27 | + (phpstan-config-file . (root . "path/to/dir/phpstan-docker.neon")) |
| 28 | + (phpstan-level . 7)))) |
| 29 | +#+END_SRC |
| 30 | + |
| 31 | +*** Using composer (project specific) |
| 32 | +If your project Composer relies on phpstan, you do not need to set anything. |
| 33 | +#+BEGIN_SRC emacs-lisp |
| 34 | +((nil . ((php-project-root . git) |
| 35 | + (phpstan-executable . docker) |
| 36 | + (phpstan-working-dir . (root . "path/to/dir")) |
| 37 | + (phpstan-config-file . (root . "path/to/dir/phpstan-docker.neon")) |
| 38 | + (phpstan-level . 7)))) |
| 39 | +#+END_SRC |
| 40 | +*** Using PHAR archive |
| 41 | +*NOTICE*: ~phpstan.el~ is incompatible with the [[https://github.com/phpstan/phpstan/releases][released versions]] of PHPStan. It will probably be distributed in the form of the Phar archive when the current development version is officially released in the near future. |
| 42 | + |
| 43 | +If you want to use the Phar archive you built yourself, set the Phar archive path to phpstan-executable. |
| 44 | + |
| 45 | +** Settings |
| 46 | +Variables for phpstan are mainly controlled by [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html][directory variables]] (~.dir-locals.el~). |
| 47 | + |
| 48 | +Frequently ~(root. "path/to/file")~ notation appears in these variables. It is relative to the top level directory of the project. In general, the directory containing one of ~.projectile~, ~composer.json~, ~.git~ file (or directory) is at the top level. |
| 49 | + |
| 50 | +Please be aware that the root directory of the PHP project may *NOT* match either of PHPStan's ~%rootDir%~ and/or ~%currentWorkingDirectory%~. |
| 51 | + |
| 52 | +Typically, you would set the following ~.dir-locals.el~. |
| 53 | + |
| 54 | +#+BEGIN_SRC emacs-lisp |
| 55 | +((nil . ((php-project-root . auto) |
| 56 | + (phpstan-executable . docker) |
| 57 | + (phpstan-working-dir . (root . "path/to/dir/")) |
| 58 | + (phpstan-config-file . (root . "path/to/dir/phpstan-custom.neon")) |
| 59 | + (phpstan-level . max)))) |
| 60 | +#+END_SRC |
| 61 | + |
| 62 | +If there is a ~phpstan.neon~ file in the root directory of the project, you do not need to set both ~phpstan-working-dir~ and ~phpstan-config-file~. |
| 63 | + |
| 64 | +** API |
| 65 | +Most variables defined in this package are buffer local. If you want to set it for multiple projects, use [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Default-Value.html][setq-default]]. |
| 66 | + |
| 67 | +*** Local variable ~phpstan-working-dir~ |
| 68 | +Path to working directory of PHPStan. |
| 69 | + |
| 70 | +- STRING :: Absolute path to `phpstan' working directory. |
| 71 | + - ex) ~"/path/to/phpstan.phar"~ |
| 72 | +- ~(root . STRING)~ :: Relative path to `phpstan' working directory from project root directory. |
| 73 | + - ex) ~(root . "path/to/dir")~ |
| 74 | +- ~nil~ :: Use ~(php-project-get-root-dir)~ as working directory. |
| 75 | + |
| 76 | +*** Local variable ~phpstan-config-file~ |
| 77 | +Path to project specific configuration file of PHPStan. |
| 78 | + |
| 79 | +- STRING :: Absolute path to ~phpstan~ configuration file. |
| 80 | +- ~(root . STRING)~ :: Relative path to ~phpstan~ configuration file from project root directory. |
| 81 | +- NIL :: Search ~phpstan.neon(.dist)~ in ~(phpstan-get-working-dir)~. |
| 82 | + |
| 83 | +*** Local variable ~phpstan-level~ |
| 84 | +Rule level of PHPStan analysis. Please see [[https://github.com/phpstan/phpstan/blob/master/README.md#rule-levels][README #Rule levels of PHPStan]]. |
| 85 | +~0~ is the loosest and you can also use ~max~ as an alias for the highest level. Default level is ~0~. |
| 86 | + |
| 87 | +*** Local variable ~phpstan-executable~ |
| 88 | +- STRING :: Absolute path to `phpstan' executable file. |
| 89 | + - ex) ~"/path/to/phpstan.phar"~ |
| 90 | +- SYMBOL ~docker~ :: Use Docker using phpstan/docker-image. |
| 91 | +- ~(root . STRING)~ :: Relative path to `phpstan' executable file from project root directory. |
| 92 | + - ex) ~(root . "script/phpstan")~ |
| 93 | +- ~(STRING . (ARGUMENTS ...))~ :: Command name and arguments. |
| 94 | + - ex) ~("docker" "run" "--rm" "-v" "/path/to/project-dir/:/app" "your/docker-image")~ |
| 95 | +- ~nil~ :: Auto detect ~phpstan~ executable file by composer dependencies of the project or executable command in ~PATH~ environment variable. |
| 96 | + |
| 97 | +*** Custom variable ~phpstan-flycheck-auto-set-executable~ |
| 98 | +Set flycheck phpstan-executable automatically when non-NIL. |
0 commit comments