Skip to content

Commit 0526c43

Browse files
authored
Merge pull request #710 from emacs-php/feature/phpdoc-type-names
Supports PHPDoc tags and types for static analysis tools
2 parents 29bbf49 + 9424e19 commit 0526c43

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
88

99
* **New feature: `php-complete`**
1010
* Add `php-complete-complete-function` to autocomplete function names ([#708])
11+
* Supports PHPDoc tags and types for static analysis tools ([#710])
1112

1213
### Changed
1314

@@ -22,6 +23,7 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
2223
[#704]: https://github.com/emacs-php/php-mode/pull/704
2324
[#707]: https://github.com/emacs-php/php-mode/pull/707
2425
[#708]: https://github.com/emacs-php/php-mode/pull/708
26+
[#710]: https://github.com/emacs-php/php-mode/pull/710
2527

2628
## [1.24.1] - 2022-10-08
2729

lisp/php-mode.el

+10-2
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,15 @@ for \\[find-tag] (which see)."
12791279
(list "string" "integer" "int" "boolean" "bool" "float"
12801280
"double" "object" "mixed" "array" "resource"
12811281
"void" "null" "false" "true" "self" "static"
1282-
"callable" "iterable" "number"))
1282+
"callable" "iterable" "number"
1283+
;; PHPStan and Psalm types
1284+
"array-key" "associative-array" "callable-array" "callable-object"
1285+
"callable-string" "class-string" "empty" "enum-string" "list"
1286+
"literal-string" "negative-int" "non-positive-int" "non-negative-int"
1287+
"never" "never-return" "never-returns" "no-return" "non-empty-array"
1288+
"non-empty-list" "non-empty-string" "non-falsy-string"
1289+
"numeric" "numeric-string" "positive-int" "scalar"
1290+
"trait-string" "truthy-string"))
12831291

12841292
(defconst php-phpdoc-type-tags
12851293
(list "package" "param" "property" "property-read" "property-write"
@@ -1293,7 +1301,7 @@ for \\[find-tag] (which see)."
12931301
(1 'php-doc-variable-sigil prepend nil)
12941302
(2 'php-variable-name prepend nil))
12951303
("\\(\\$\\)\\(this\\)\\>" (1 'php-doc-$this-sigil prepend nil) (2 'php-doc-$this prepend nil))
1296-
(,(concat "\\s-@" (regexp-opt php-phpdoc-type-tags) "\\s-+"
1304+
(,(concat "\\s-@" (rx (? (or "phpstan" "psalm") "-")) (regexp-opt php-phpdoc-type-tags) "\\s-+"
12971305
"\\(" (rx (+ (? "?") (? "\\") (+ (in "0-9A-Z_a-z")) (? "[]") (? "|"))) "\\)+")
12981306
1 'php-string prepend nil)
12991307
(,(concat "\\(?:|\\|\\?\\|\\s-\\)\\("

tests/lang/doc-comment/return-type.php.faces

+15-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
(" " . font-lock-doc-face)
3333
("int" font-lock-type-face php-string font-lock-doc-face)
3434
("[]" php-string font-lock-doc-face)
35-
(" A list of " . font-lock-doc-face)
35+
(" A " . font-lock-doc-face)
36+
("list" font-lock-type-face font-lock-doc-face)
37+
(" of " . font-lock-doc-face)
3638
("integer" font-lock-type-face font-lock-doc-face)
3739
(" values */" . font-lock-doc-face)
3840
("\n\n\n")
@@ -59,7 +61,9 @@
5961
("@return" php-doc-annotation-tag font-lock-doc-face)
6062
(" " . font-lock-doc-face)
6163
("DateTime[]" php-string font-lock-doc-face)
62-
(" A list of DateTime " . font-lock-doc-face)
64+
(" A " . font-lock-doc-face)
65+
("list" font-lock-type-face font-lock-doc-face)
66+
(" of DateTime " . font-lock-doc-face)
6367
("object" font-lock-type-face font-lock-doc-face)
6468
(" values */" . font-lock-doc-face)
6569
("\n\n\n")
@@ -86,7 +90,9 @@
8690
("@return" php-doc-annotation-tag font-lock-doc-face)
8791
(" " . font-lock-doc-face)
8892
("stdClass[]" php-string font-lock-doc-face)
89-
(" A list of stdClass " . font-lock-doc-face)
93+
(" A " . font-lock-doc-face)
94+
("list" font-lock-type-face font-lock-doc-face)
95+
(" of stdClass " . font-lock-doc-face)
9096
("object" font-lock-type-face font-lock-doc-face)
9197
(" values */" . font-lock-doc-face)
9298
("\n\n")
@@ -113,7 +119,9 @@
113119
("@return" php-doc-annotation-tag font-lock-doc-face)
114120
(" " . font-lock-doc-face)
115121
("\\App\\User[]" php-string font-lock-doc-face)
116-
(" A list of \\App\\User " . font-lock-doc-face)
122+
(" A " . font-lock-doc-face)
123+
("list" font-lock-type-face font-lock-doc-face)
124+
(" of \\App\\User " . font-lock-doc-face)
117125
("object" font-lock-type-face font-lock-doc-face)
118126
(" values */" . font-lock-doc-face)
119127
("\n\n")
@@ -138,7 +146,9 @@
138146
("int" font-lock-type-face php-string font-lock-doc-face)
139147
("[]|" php-string font-lock-doc-face)
140148
("string" font-lock-type-face php-string font-lock-doc-face)
141-
(" Multiple types by list of " . font-lock-doc-face)
149+
(" Multiple types by " . font-lock-doc-face)
150+
("list" font-lock-type-face font-lock-doc-face)
151+
(" of " . font-lock-doc-face)
142152
("int" font-lock-type-face font-lock-doc-face)
143153
(" and " . font-lock-doc-face)
144154
("string" font-lock-type-face font-lock-doc-face)

0 commit comments

Comments
 (0)