Skip to content

Commit 21cf970

Browse files
committed
Modify doc comment and README
1 parent 56355b0 commit 21cf970

File tree

2 files changed

+129
-15
lines changed

2 files changed

+129
-15
lines changed

README.org

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,98 @@
11
* phpstan.el
22
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.

phpstan.el

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@
5050

5151
;;;###autoload
5252
(progn
53-
(defvar phpstan-working-dir nil)
53+
(defvar phpstan-working-dir nil
54+
"Path to working directory of PHPStan.
55+
56+
*NOTICE*: This is different from the project root.
57+
58+
STRING
59+
Absolute path to `phpstan' working directory.
60+
61+
`(root . STRING)'
62+
Relative path to `phpstan' working directory from project root directory.
63+
64+
NIL
65+
Use (php-project-get-root-dir) as working directory.")
5466
(make-variable-buffer-local 'phpstan-working-dir)
5567
(put 'phpstan-working-dir 'safe-local-variable
5668
#'(lambda (v) (if (consp v)
@@ -59,7 +71,17 @@
5971

6072
;;;###autoload
6173
(progn
62-
(defvar phpstan-config-file nil)
74+
(defvar phpstan-config-file nil
75+
"Path to project specific configuration file of PHPStan.
76+
77+
STRING
78+
Absolute path to `phpstan' configuration file.
79+
80+
`(root . STRING)'
81+
Relative path to `phpstan' configuration file from project root directory.
82+
83+
NIL
84+
Search phpstan.neon(.dist) in (phpstan-get-working-dir).")
6385
(make-variable-buffer-local 'phpstan-config-file)
6486
(put 'phpstan-config-file 'safe-local-variable
6587
#'(lambda (v) (if (consp v)
@@ -68,7 +90,14 @@
6890

6991
;;;###autoload
7092
(progn
71-
(defvar phpstan-level "0")
93+
(defvar phpstan-level "0"
94+
"Rule level of PHPStan.
95+
96+
INTEGER or STRING
97+
Number of PHPStan rule level.
98+
99+
max
100+
The highest of PHPStan rule level.")
72101
(make-variable-buffer-local 'phpstan-level)
73102
(put 'phpstan-level 'safe-local-variable
74103
#'(lambda (v) (or (null v)
@@ -118,18 +147,7 @@ NIL
118147

119148
;; Functions:
120149
(defun phpstan-get-working-dir ()
121-
"Return working directory of PHPStan.
122-
123-
This is different from the project root.
124-
125-
STRING
126-
Absolute path to `phpstan' working directory.
127-
128-
`(root . STRING)'
129-
Relative path to `phpstan' working directory.
130-
131-
NIL
132-
Use (php-project-get-root-dir) as working directory."
150+
"Return path to working directory of PHPStan."
133151
(if (and phpstan-working-dir (consp phpstan-working-dir) (eq 'root (car phpstan-working-dir)))
134152
(expand-file-name (cdr phpstan-working-dir) (php-project-get-root-dir))
135153
(php-project-get-root-dir)))

0 commit comments

Comments
 (0)