Emacs interface to PHPStan, includes checker for Flycheck.
M-x package-install flycheck-phpstan
(defun my-php-mode-setup () "My PHP-mode hook." (require 'flycheck-phpstan) (flycheck-mode t)) (add-hook 'php-mode-hook 'my-php-mode-setup)
(add-hook 'php-mode-hook #'flymake-phpstan-turn-on)Using Docker (phpstan/docker-image)
Install Docker and phpstan/phpstan image.
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-memory-limit . "1G") (phpstan-level . 7))))Using composer (project specific)
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))))
Please install phpstan/phpstan package for each user environment or project by using Composer.
If you are unfamiliar with resolving dependencies, the following shell commands are recommended.
$ composer global require phpstan/phpstan
NOTICE: phpstan/phpstan-shim is deprecated. Please read PHPStan 0.12 Released!.
NOTICE: phpstan.el
requires PHPStan **0.10+**. We strongly recommend using the latest PHPStan.
Please download phpstan.phar
from Releases · phpstan/phpstan.
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.
Local variablephpstan-working-dir
Path to working directory of PHPStan.
"/path/to/phpstan.phar"
(root . STRING)
(root . "path/to/dir")
nil
(php-project-get-root-dir)
as working directory.
phpstan-config-file
Path to project specific configuration file of PHPStan.
phpstan
configuration file.
(root . STRING)
phpstan
configuration file from project root directory.
phpstan.neon(.dist)
in (phpstan-get-working-dir)
.
phpstan-level
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
.
phpstan-executable
"/path/to/phpstan.phar"
docker
(root . STRING)
(root . "script/phpstan")
(STRING . (ARGUMENTS ...))
("docker" "run" "--rm" "-v" "/path/to/project-dir/:/app" "your/docker-image")
nil
phpstan
executable file by composer dependencies of the project or executable command in PATH
environment variable.
phpstan-flycheck-auto-set-executable
Set flycheck phpstan-executable automatically when non-NIL.
Custom variablephpstan-memory-limit
Use phpstan memory limit option when non-NIL.
"1G"
nil
phpstan-docker-image
Docker image URL or Docker Hub image name or NIL. Default as "ghcr.io/phpstan/phpstan"
. See Docker - PHPStan Documentation and GitHub Container Registory - Package phpstan.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4