Emacs interface to PHPStan, includes checker for Flycheck.
- Emacs 24+
- PHPStan latest/dev-master (NOT support 0.9 seriese)
- If you have not set up MELPA, see Getting Started - MELPA.
M-x package-install flycheck-phpstan
(defun my-php-mode-hook ()
"My PHP-mode hook."
(require 'flycheck-phpstan)
(flycheck-mode t)
(flycheck-select-checker 'phpstan))
(add-hook 'php-mode-hook 'my-php-mode-hook)
The function for flymake will be implemented soon. You do not have to depend on flycheck.
Install Docker CE and phpstan/docker-image(latest).
If you always use Docker for PHPStan, add the following into your .emacs
file (~~/.emacs.d/init.el~)
(setq-default phpstan-executable 'docker)
Put the following into .dir-locals.el
files on the root directory of project.
((nil . ((php-project-root . git)
(phpstan-executable . docker)
(phpstan-working-dir . (root . "path/to/dir"))
(phpstan-config-file . (root . "path/to/dir/phpstan-docker.neon"))
(phpstan-level . 7))))
If your project Composer relies on phpstan, you do not need to set anything.
((nil . ((php-project-root . git)
(phpstan-executable . docker)
(phpstan-working-dir . (root . "path/to/dir"))
(phpstan-config-file . (root . "path/to/dir/phpstan-docker.neon"))
(phpstan-level . 7))))
NOTICE: phpstan.el
is incompatible with the 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.
If you want to use the Phar archive you built yourself, set the Phar archive path to phpstan-executable.
Variables for phpstan are mainly controlled by directory variables (.dir-locals.el
).
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.
Please be aware that the root directory of the PHP project may NOT match either of PHPStan’s %rootDir%
and/or %currentWorkingDirectory%
.
Typically, you would set the following .dir-locals.el
.
((nil . ((php-project-root . auto)
(phpstan-executable . docker)
(phpstan-working-dir . (root . "path/to/dir/"))
(phpstan-config-file . (root . "path/to/dir/phpstan-custom.neon"))
(phpstan-level . max))))
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
.
Most variables defined in this package are buffer local. If you want to set it for multiple projects, use setq-default.
Path to working directory of PHPStan.
- STRING
- Absolute path to `phpstan’ working directory.
- ex)
"/path/to/phpstan.phar"
- ex)
(root . STRING)
- Relative path to `phpstan’ working directory from project root directory.
- ex)
(root . "path/to/dir")
- ex)
nil
- Use
(php-project-get-root-dir)
as working directory.
Path to project specific configuration file of PHPStan.
- STRING
- Absolute path to
phpstan
configuration file. (root . STRING)
- Relative path to
phpstan
configuration file from project root directory. - NIL
- Search
phpstan.neon(.dist)
in(phpstan-get-working-dir)
.
Rule level of PHPStan analysis. Please see README #Rule levels of PHPStan.
0
is the loosest and you can also use max
as an alias for the highest level. Default level is 0
.
- STRING
- Absolute path to `phpstan’ executable file.
- ex)
"/path/to/phpstan.phar"
- ex)
- SYMBOL
docker
- Use Docker using phpstan/docker-image.
(root . STRING)
- Relative path to `phpstan’ executable file from project root directory.
- ex)
(root . "script/phpstan")
- ex)
(STRING . (ARGUMENTS ...))
- Command name and arguments.
- ex)
("docker" "run" "--rm" "-v" "/path/to/project-dir/:/app" "your/docker-image")
- ex)
nil
- Auto detect
phpstan
executable file by composer dependencies of the project or executable command inPATH
environment variable.
Set flycheck phpstan-executable automatically when non-NIL.