Skip to content

Commit f639c7a

Browse files
committed
Add new and adjust existing keyword highlighting rules
1 parent 38fd629 commit f639c7a

File tree

2 files changed

+104
-6
lines changed

2 files changed

+104
-6
lines changed

src/KeywordEnhancer.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@ class KeywordEnhancer {
66
protected const array CODIFY_PATTERNS = [
77
'/\b(?<!`)(?:zend|php)_[a-z_]+\(\)(?!`)/i', // zend_foo_bar()
88
'/\b(?<!`)(?:zend|php|_php)_[a-z_*]+\b(?![`.(=])\*?/i', // zend_foo_bar
9+
'/(?<![`>()-])\bext\/[a-z_\d\/-]+\.phpt\b(?![`])/i', // ext/test/test/test.phpt
910
'/\b(?<![`\/])[a-z][a-z\d_-]+(.stubs?)?\.(phpt?|c|h)(?![`.?])/', // run-tests.php / foo.stub.php foo.stubs.php / test-foo-bar.phpt,
1011
'/\b(?<!`)ext\/[a-z_]+\b(?![`\/])/', // ext-names
12+
'/\b(?<!`)__[a-z][a-zA-Z\d_]+\(\)(?![`ws])/', // __debugInfo()
1113
'/\b(?<!`)[A-Za-z][A-Za-z\d]+::(?:__)?[a-z][A-Za-z\d_]+\(\)(?![`\/-])/', // Class::methods()
1214
'/\b(?<!`)[A-Z][A-Za-z]+::(?:__)[a-z][A-Za-z\d_]+(?![`\/-])\b(?![)(])/', // Class::__magicMethods
13-
'/\b(?<!`)[A-Z][A-Za-z]+::[A-Z_]+\b(?![`\/(])/', // Class::CONSTANTS
15+
'/\b(?<!`)[A-Z][A-Za-z]+::[A-Z][A-Z_\d]+\b(?![`\/(])/', // Class::CONSTANTS
1416
'/\b(?<![`\\\\])[A-Z][A-Z\\\\a-z]+::[a-z][A-Za-z_\d]+\b(?![`\/(])/', // Class::constants
1517
'/\b(?<!`-)[a-z]+_[a-z]+(?:_[a-z_]+)?\(\)(?![`\/])/', // Functions with underscores and ()
1618
'/\b(?<![`>])[a-z_][a-z][a-z\d_]+\(\)(?![`.>\/-])/', // Functions with underscores and ()
1719
'/\b(?<!`)(?:ldap|ftp|array|mb|stream|open|hash|xml|proc|pcntl|curl|intl|date|grapheme|socket|stream)_[a-z_]+\d?\b(?![`\/])/', // Functions with underscores and no ()
1820
'/\b(?<!`)(xleak|xfail|skipif)\b(?![`\/])/i', // xleak
1921
'/(?<![`>()-])--[a-z][a-z-]+(?![`])/i', // --flags, --flags-and-more
20-
'/(?<![`>()-])\bext\/[a-z_\d\/-]+\.phpt\b(?![`])/i', // ext/test/test/test.phpt
2122
'/\b(?<![`>:-])__[A-Z\d_]+(?![`])/i', // __PROPERTY__
2223
'/(?<=\s)(?<![`>-])\\\\[A-Z][a-z]+\\\\[A-Z][A-Za-z]+(?![`])\b/', // Stricter, class name like \Dom\HTMLDocument
23-
'/\b(?<![`>()-])(?:(main|ext|Zend|tests|win32|scripts|sapi|pear|docs|build)\/(?:[a-z\d\/_]+))(?:\.(c|php|phpt|yml|yaml|cpp|m4|txt|w32|h))(?::\d+)?(?![`])/i', // files in php-src
24-
'/\b(?<!`)(?:(SOAP|SO|TCP|SOCK|FILTER|XML|FTP|CURL|CURLOPT|CURLE|CURLINFO|GREP|X509|ZEND|USE_ZEND))_[A-Z_]+\b(?![`\/(])/', // CONSTANTS (with fixed prefixes)
24+
'/\b(?<![`>()-])(?:(main|ext|Zend|tests|win32|scripts|sapi|pear|docs|build)\/(?:[a-z\d\/_]+))(?:\.(c|php|phpt|yml|yaml|cpp|m4|txt|w32|h))(?::\d+)?(?![`\w])/i', // files in php-src
25+
'/\b(?<!`)(?:(DATE|SOAP|SO|TCP|SOCK|FILTER|XML|FTP|CURL|CURLOPT|CURLE|CURLINFO|GREP|X509|ZEND|USE_ZEND|TEST|HASH))_[A-Z_\d]+\b(?![`\/(*_\S])/', // CONSTANTS (with fixed prefixes)
26+
'/\b(?<![`\w])(HASH|DATE|MHASH)_[A-Z_]+_\*(?![`\/(\w\S])/', // Const names with * at the end
27+
'/(?<![`\w])#\[\\\\?[A-Z][A-Za-z\d_]+](?![`\w\/])/', // Attributes
28+
'/\B(?<![`\S\w])\$[a-z_\d]+(?![`\w\S])/', // Variable names, lowercase
2529
];
2630

2731
public static function enhance(string $inputText): string {

tests/KeywordEnhancerTest.php

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,106 @@ public static function dataLinkToGitHub(): array {
6868

6969
public static function dataCodifyText(): array {
7070
return [
71-
['password_hash()', '`password_hash()`'],
72-
['`password_hash()`', '`password_hash()`'],
71+
[
72+
'password_hash()',
73+
'`password_hash()`'
74+
],
75+
[
76+
'`password_hash()`',
77+
'`password_hash()`'
78+
],
7379
[
7480
'`password_hash()` and password_hash()',
7581
'`password_hash()` and `password_hash()`',
7682
],
83+
[
84+
'Non-canonical cast names (boolean), (integer), (double), and (binary) have been deprecated.',
85+
'Non-canonical cast names (boolean), (integer), (double), and (binary) have been deprecated.',
86+
],
87+
[
88+
'The $exclude_disabled parameter of the get_defined_functions() function has been deprecated, as it no longer has any effect since PHP 8.0.',
89+
'The `$exclude_disabled` parameter of the `get_defined_functions()` function has been deprecated, as it no longer has any effect since PHP 8.0.',
90+
],
91+
[
92+
'The backtick operator as an alias for shell_exec() has been deprecated.',
93+
'The backtick operator as an alias for `shell_exec()` has been deprecated.',
94+
],
95+
[
96+
'Returning null from __debugInfo() has been deprecated.',
97+
'Returning null from `__debugInfo()` has been deprecated.',
98+
],
99+
[
100+
'Returning null from `__debugInfo()` has been deprecated.',
101+
'Returning null from `__debugInfo()` has been deprecated.',
102+
],
103+
[
104+
'Returning null from __debugInfo has been deprecated.',
105+
'Returning null from `__debugInfo` has been deprecated.',
106+
],
107+
[
108+
'Support #[\Override] on properties.',
109+
'Support `#[\Override]` on properties.',
110+
],
111+
[
112+
'Support #[Override] on properties.',
113+
'Support `#[Override]` on properties.',
114+
],
115+
[
116+
'Support `#[Override]` on properties.',
117+
'Support `#[Override]` on properties.',
118+
],
119+
[
120+
'Support https://example.com#test on properties.',
121+
'Support https://example.com#test on properties.',
122+
],
123+
[
124+
'The curl_close() function has been deprecated.',
125+
'The `curl_close()` function has been deprecated.',
126+
],
127+
[
128+
'The curl_share_close() function has been deprecated.',
129+
'The `curl_share_close()` function has been deprecated.',
130+
],
131+
[
132+
'The DATE_RFC7231 and DateTimeInterface::RFC7231 constants have been deprecated.',
133+
'The `DATE_RFC7231` and `DateTimeInterface::RFC7231` constants have been deprecated.',
134+
],
135+
[
136+
'The $context parameter of the finfo_buffer() function has been deprecated as it is ignored.',
137+
'The `$context` parameter of the `finfo_buffer()` function has been deprecated as it is ignored.',
138+
],
139+
[
140+
'The $key_length parameter for openssl_pkey_derive() has been deprecated.',
141+
'The `$key_length` parameter for `openssl_pkey_derive()` has been deprecated.',
142+
],
143+
[
144+
'ext/standard/tests/file/bug81145.phpt: unlink file before exit',
145+
'`ext/standard/tests/file/bug81145.phpt`: unlink file before exit',
146+
],
147+
[
148+
'ext/standard: unlink file before exit',
149+
'`ext/standard`: unlink file before exit',
150+
],
151+
[
152+
'Setting TEST_PHP_EXECUTABLE hasn\'t been necessary for ages',
153+
'Setting `TEST_PHP_EXECUTABLE` hasn\'t been necessary for ages',
154+
],
155+
[
156+
'Add an enum for HASH_KEY_IS_* constants',
157+
'Add an enum for `HASH_KEY_IS_*` constants',
158+
],
159+
[
160+
'Add an enum for HASH_KEY_IS_*f constants',
161+
'Add an enum for HASH_KEY_IS_*f constants',
162+
],
163+
[
164+
'Add an enum for HASH_KEY_IS_ constants',
165+
'Add an enum for `HASH_KEY_IS_` constants',
166+
],
167+
[
168+
'Add an enum for HASH_KEY_IS constants',
169+
'Add an enum for `HASH_KEY_IS` constants',
170+
],
77171
];
78172
}
79173

0 commit comments

Comments
 (0)