Skip to content

Commit 9e05a1f

Browse files
committed
CS
1 parent 3f2f535 commit 9e05a1f

File tree

11 files changed

+271
-192
lines changed

11 files changed

+271
-192
lines changed

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
}
1212
],
1313
"require": {
14-
"nette/neon": "^3.3",
14+
"nette/neon": "^3.4",
1515
"php": "^8.0",
1616
"squizlabs/php_codesniffer": "^3.8"
1717
},
1818
"require-dev": {
19-
"forrest79/phpcs": "^1.1",
20-
"phpstan/phpstan": "^1.10",
21-
"phpstan/phpstan-strict-rules": "^1.5"
19+
"forrest79/phpcs": "^2.0",
20+
"phpstan/phpstan": "^2.1",
21+
"phpstan/phpstan-strict-rules": "^2.0",
22+
"shipmonk/phpstan-rules": "^4.1"
2223
},
2324
"autoload": {
2425
"psr-4": {

phpcs.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?xml version="1.0"?>
22
<ruleset name="PhPgSql">
3-
<rule ref="./vendor/forrest79/phpcs/Forrest79CodingStandard/ruleset.xml"/>
3+
<rule ref="./vendor/forrest79/phpcs/Forrest79CodingStandard/ruleset.xml">
4+
<exclude name="SlevomatCodingStandard.TypeHints.ClassConstantTypeHint.MissingNativeTypeHint"/><!-- PHP 8.3+ -->
5+
</rule>
46

57
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
68
<properties>
7-
<property name="rootNamespaces" type="array" value="
8-
src=>Forrest79\PhpCsIgnores,
9-
tests=>Forrest79\PhpCsIgnores\Tests,
10-
"/>
9+
<property name="rootNamespaces" type="array">
10+
<element key="src" value="Forrest79\PhpCsIgnores"/>
11+
<element key="tests" value="Forrest79\PhpCsIgnores\Tests"/>
12+
</property>
1113
</properties>
1214
</rule>
1315

phpstan.neon

Lines changed: 99 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,234 @@
11
includes:
22
- %rootDir%/conf/bleedingEdge.neon
33
- %rootDir%/../phpstan-strict-rules/rules.neon
4+
- %rootDir%/../../shipmonk/phpstan-rules/rules.neon
45

56
parameters:
67
level: max
78
scanDirectories:
89
- %rootDir%/../../squizlabs/php_codesniffer/src
910
ignoreErrors:
11+
# Common for tests
12+
1013
-
11-
message: "#^Parameter \\#1 \\$errors of method Forrest79\\\\PhpCsIgnores\\\\File\\:\\:setErrors\\(\\) expects array\\<int, array\\<int, list\\<array\\<string, mixed\\>\\>\\>\\>, array\\<non\\-empty\\-array\\<int\\|string, non\\-empty\\-list\\<mixed\\>\\>\\> given\\.$#"
12-
count: 1
13-
path: src/File.php
14+
message: '#^Cannot access offset .+\.$#'
15+
count: 54
16+
path: tests/run-tests.php
17+
18+
# Baseline
1419

1520
-
16-
message: "#^Parameter \\#1 \\$warnings of method Forrest79\\\\PhpCsIgnores\\\\File\\:\\:setWarnings\\(\\) expects array\\<int, array\\<int, list\\<array\\<string, mixed\\>\\>\\>\\>, array\\<non\\-empty\\-array\\<int\\|string, list\\<mixed\\>\\>\\> given\\.$#"
21+
message: '#^Parameter \#1 \$errors of method Forrest79\\PhpCsIgnores\\File\:\:setErrors\(\) expects array\<int, array\<int, list\<array\<string, mixed\>\>\>\>, array\<non\-empty\-array\<non\-empty\-list\<non\-empty\-array\>\>\> given\.$#'
22+
identifier: argument.type
1723
count: 1
1824
path: src/File.php
1925

2026
-
21-
message: "#^Parameter \\#1 \\$warnings of method Forrest79\\\\PhpCsIgnores\\\\File\\:\\:setWarnings\\(\\) expects array\\<int, array\\<int, list\\<array\\<string, mixed\\>\\>\\>\\>, array\\{\\}\\|array\\{1\\: array\\{1\\: non\\-empty\\-array\\<array\\<string, mixed\\>\\>\\}\\} given\\.$#"
27+
message: '#^Parameter \#1 \$warnings of method Forrest79\\PhpCsIgnores\\File\:\:setWarnings\(\) expects array\<int, array\<int, list\<array\<string, mixed\>\>\>\>, array\<non\-empty\-array\<list\<non\-empty\-array\>\>\> given\.$#'
28+
identifier: argument.type
2229
count: 1
2330
path: src/File.php
2431

2532
-
26-
message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\<bool\\|float\\|int\\|string\\|null\\>, array given\\.$#"
33+
message: '#^Parameter \#2 \$values of function vsprintf expects array\<bool\|float\|int\|string\|null\>, array\<mixed\> given\.$#'
34+
identifier: argument.type
2735
count: 1
2836
path: src/File.php
2937

3038
-
31-
message: "#^Cannot access offset 0 on mixed\\.$#"
39+
message: '#^Cannot access offset 0 on mixed\.$#'
40+
identifier: offsetAccess.nonOffsetAccessible
3241
count: 1
3342
path: src/PhpCsInjections.php
3443

3544
-
36-
message: "#^Cannot access offset 1 on mixed\\.$#"
45+
message: '#^Cannot access offset 1 on mixed\.$#'
46+
identifier: offsetAccess.nonOffsetAccessible
3747
count: 1
3848
path: src/PhpCsInjections.php
3949

4050
-
41-
message: "#^Constant PHP_CODESNIFFER_VERBOSITY not found\\.$#"
51+
message: '#^Comparison mixed \> int contains non\-comparable type, only int\|float\|string\|DateTimeInterface or comparable tuple is allowed\.$#'
52+
identifier: shipmonk.comparingNonComparableTypes
4253
count: 2
4354
path: src/PhpCsInjections.php
4455

4556
-
46-
message: "#^Method Forrest79\\\\PhpCsIgnores\\\\PhpCsInjections\\:\\:mkdir\\(\\) should return bool but returns mixed\\.$#"
57+
message: '#^Constant PHP_CODESNIFFER_VERBOSITY not found\.$#'
58+
identifier: constant.notFound
59+
count: 2
60+
path: src/PhpCsInjections.php
61+
62+
-
63+
message: '#^Method Forrest79\\PhpCsIgnores\\PhpCsInjections\:\:mkdir\(\) should return bool but returns mixed\.$#'
64+
identifier: return.type
4765
count: 1
4866
path: src/PhpCsInjections.php
4967

5068
-
51-
message: "#^Method Forrest79\\\\PhpCsIgnores\\\\PhpCsInjections\\:\\:rename\\(\\) should return bool but returns mixed\\.$#"
69+
message: '#^Method Forrest79\\PhpCsIgnores\\PhpCsInjections\:\:rename\(\) should return bool but returns mixed\.$#'
70+
identifier: return.type
5271
count: 1
5372
path: src/PhpCsInjections.php
5473

5574
-
56-
message: "#^Method Forrest79\\\\PhpCsIgnores\\\\PhpCsInjections\\:\\:rmdir\\(\\) should return bool but returns mixed\\.$#"
75+
message: '#^Method Forrest79\\PhpCsIgnores\\PhpCsInjections\:\:rmdir\(\) should return bool but returns mixed\.$#'
76+
identifier: return.type
5777
count: 1
5878
path: src/PhpCsInjections.php
5979

6080
-
61-
message: "#^Method Forrest79\\\\PhpCsIgnores\\\\PhpCsInjections\\:\\:stream_metadata\\(\\) should return bool but returns mixed\\.$#"
81+
message: '#^Method Forrest79\\PhpCsIgnores\\PhpCsInjections\:\:stream_metadata\(\) should return bool but returns mixed\.$#'
82+
identifier: return.type
6283
count: 4
6384
path: src/PhpCsInjections.php
6485

6586
-
66-
message: "#^Method Forrest79\\\\PhpCsIgnores\\\\PhpCsInjections\\:\\:stream_tell\\(\\) should return int but returns int\\|false\\.$#"
87+
message: '#^Method Forrest79\\PhpCsIgnores\\PhpCsInjections\:\:stream_tell\(\) should return int but returns int\|(false|bool)\.$#'
88+
identifier: return.type
6789
count: 1
6890
path: src/PhpCsInjections.php
6991

7092
-
71-
message: "#^Method Forrest79\\\\PhpCsIgnores\\\\PhpCsInjections\\:\\:unlink\\(\\) should return bool but returns mixed\\.$#"
93+
message: '#^Method Forrest79\\PhpCsIgnores\\PhpCsInjections\:\:unlink\(\) should return bool but returns mixed\.$#'
94+
identifier: return.type
7295
count: 1
7396
path: src/PhpCsInjections.php
7497

7598
-
76-
message: "#^Only booleans are allowed in a ternary operator condition, int\\<0, 1\\> given\\.$#"
99+
message: '#^Missing native return typehint array\|(false|bool)$#'
100+
identifier: shipmonk.missingNativeReturnTypehint
77101
count: 1
78102
path: src/PhpCsInjections.php
79103

80104
-
81-
message: "#^Only booleans are allowed in a ternary operator condition, int\\<0, 2\\> given\\.$#"
105+
message: '#^Missing native return typehint int\|(false|bool)$#'
106+
identifier: shipmonk.missingNativeReturnTypehint
82107
count: 1
83108
path: src/PhpCsInjections.php
84109

85110
-
86-
message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|null given\\.$#"
111+
message: '#^Missing native return typehint mixed$#'
112+
identifier: shipmonk.missingNativeReturnTypehint
113+
count: 2
114+
path: src/PhpCsInjections.php
115+
116+
-
117+
message: '#^Missing native return typehint string\|(false|bool)#'
118+
identifier: shipmonk.missingNativeReturnTypehint
119+
count: 2
120+
path: src/PhpCsInjections.php
121+
122+
-
123+
message: '#^Only booleans are allowed in a ternary operator condition, int\<0, 1\> given\.$#'
124+
identifier: ternary.condNotBoolean
87125
count: 1
88126
path: src/PhpCsInjections.php
89127

90128
-
91-
message: "#^Parameter \\#1 \\$stream of function feof expects resource, resource\\|null given\\.$#"
129+
message: '#^Only booleans are allowed in a ternary operator condition, int\<0, 2\> given\.$#'
130+
identifier: ternary.condNotBoolean
92131
count: 1
93132
path: src/PhpCsInjections.php
94133

95134
-
96-
message: "#^Parameter \\#1 \\$stream of function fflush expects resource, resource\\|null given\\.$#"
135+
message: '#^Parameter \#1 \$stream of function fclose expects resource, resource\|null given\.$#'
136+
identifier: argument.type
97137
count: 1
98138
path: src/PhpCsInjections.php
99139

100140
-
101-
message: "#^Parameter \\#1 \\$stream of function flock expects resource, resource\\|null given\\.$#"
141+
message: '#^Parameter \#1 \$stream of function feof expects resource, resource\|null given\.$#'
142+
identifier: argument.type
102143
count: 1
103144
path: src/PhpCsInjections.php
104145

105146
-
106-
message: "#^Parameter \\#1 \\$stream of function fread expects resource, resource\\|null given\\.$#"
147+
message: '#^Parameter \#1 \$stream of function fflush expects resource, resource\|null given\.$#'
148+
identifier: argument.type
107149
count: 1
108150
path: src/PhpCsInjections.php
109151

110152
-
111-
message: "#^Parameter \\#1 \\$stream of function fseek expects resource, resource\\|null given\\.$#"
153+
message: '#^Parameter \#1 \$stream of function flock expects resource, resource\|null given\.$#'
154+
identifier: argument.type
112155
count: 1
113156
path: src/PhpCsInjections.php
114157

115158
-
116-
message: "#^Parameter \\#1 \\$stream of function fstat expects resource, resource\\|null given\\.$#"
159+
message: '#^Parameter \#1 \$stream of function fread expects resource, resource\|null given\.$#'
160+
identifier: argument.type
117161
count: 1
118162
path: src/PhpCsInjections.php
119163

120164
-
121-
message: "#^Parameter \\#1 \\$stream of function ftell expects resource, resource\\|null given\\.$#"
165+
message: '#^Parameter \#1 \$stream of function fseek expects resource, resource\|null given\.$#'
166+
identifier: argument.type
122167
count: 1
123168
path: src/PhpCsInjections.php
124169

125170
-
126-
message: "#^Parameter \\#1 \\$stream of function ftruncate expects resource, resource\\|null given\\.$#"
171+
message: '#^Parameter \#1 \$stream of function fstat expects resource, resource\|null given\.$#'
172+
identifier: argument.type
127173
count: 1
128174
path: src/PhpCsInjections.php
129175

130176
-
131-
message: "#^Parameter \\#1 \\$stream of function fwrite expects resource, resource\\|null given\\.$#"
177+
message: '#^Parameter \#1 \$stream of function ftell expects resource, resource\|null given\.$#'
178+
identifier: argument.type
132179
count: 1
133180
path: src/PhpCsInjections.php
134181

135182
-
136-
message: "#^Parameter \\#2 \\$code of callable callable\\(string, string\\)\\: string expects string, mixed given\\.$#"
183+
message: '#^Parameter \#1 \$stream of function ftruncate expects resource, resource\|null given\.$#'
184+
identifier: argument.type
137185
count: 1
138186
path: src/PhpCsInjections.php
139187

140188
-
141-
message: "#^Parameter \\#2 \\$length of function fread expects int\\<0, max\\>, int given\\.$#"
189+
message: '#^Parameter \#1 \$stream of function fwrite expects resource, resource\|null given\.$#'
190+
identifier: argument.type
142191
count: 1
143192
path: src/PhpCsInjections.php
144193

145194
-
146-
message: "#^Parameter \\#2 \\$size of function ftruncate expects int\\<0, max\\>, int given\\.$#"
195+
message: '#^Parameter \#2 \$code of callable callable\(string, string\)\: string expects string, mixed given\.$#'
196+
identifier: argument.type
147197
count: 1
148198
path: src/PhpCsInjections.php
149199

150200
-
151-
message: "#^Property Forrest79\\\\PhpCsIgnores\\\\PhpCsInjections\\:\\:\\$handle \\(resource\\|null\\) does not accept mixed\\.$#"
152-
count: 2
201+
message: '#^Parameter \#2 \$length of function fread expects int\<1, max\>, int given\.$#'
202+
identifier: argument.type
203+
count: 1
153204
path: src/PhpCsInjections.php
154205

155206
-
156-
message: "#^Property Forrest79\\\\PhpCsIgnores\\\\PhpCsInjections\\:\\:\\$handle \\(resource\\|null\\) does not accept resource\\|false\\.$#"
207+
message: '#^Parameter \#2 \$size of function ftruncate expects int\<0, max\>, int given\.$#'
208+
identifier: argument.type
157209
count: 1
158210
path: src/PhpCsInjections.php
159211

160212
-
161-
message: "#^Result of function rewinddir \\(void\\) is used\\.$#"
213+
message: '#^Property Forrest79\\PhpCsIgnores\\PhpCsInjections\:\:\$handle \(resource\|null\) does not accept mixed\.$#'
214+
identifier: assign.propertyType
215+
count: 2
216+
path: src/PhpCsInjections.php
217+
218+
-
219+
message: '#^Public property `context` not marked as readonly\.$#'
220+
identifier: shipmonk.publicPropertyNotReadonly
162221
count: 1
163222
path: src/PhpCsInjections.php
164223

165224
-
166-
message: "#^Trying to invoke string but it might not be a callable\\.$#"
225+
message: '#^Result of function rewinddir \(void\) is used\.$#'
226+
identifier: function.void
167227
count: 1
168228
path: src/PhpCsInjections.php
169229

170230
-
171-
message: '#^Cannot access offset .+\.$#'
172-
count: 54
173-
path: tests/run-tests.php
231+
message: '#^Trying to invoke string but it might not be a callable\.$#'
232+
identifier: callable.nonCallable
233+
count: 1
234+
path: src/PhpCsInjections.php

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ this object is instanced and via `PhpCsInjections.php` I'm updating this file -
108108

109109
This is the main magic. Injections work only for files that aren't yet loaded via PHP, so I want to enable it as soon as possible. For this I'm using
110110
bootstrap files. PHPCS includes this directly into main `PHP_CodeSniffer\Runner` at the beginning of the life cycle. This will register injections, load neon settings
111-
and set `config->recordErrors = TRUE` - we need always enabled `recordErrors` (it could be disabled via settings, and it's disabled by fixer), without this, error messages
111+
and set `config->recordErrors = true` - we need always enabled `recordErrors` (it could be disabled via settings, and it's disabled by fixer), without this, error messages
112112
are not generated and we can't check if there are ignored.
113113

114114
The last thing is to check errors in processed file, set ignored messages and add info about outdated once. For PHPCS this is done after `process()` method is done. This is
115115
because we want the cache to be fully write and this is done in the original `process()` method. So we check existing errors, remove ignored once, update counts and check what
116116
errors are outdated and add these as warnings.
117117

118-
For PHPCBF we need to check error right in the `addMessage()` method, because for ignored errors we need instantly return `FALSE` to not fix this ignores error.
118+
For PHPCBF we need to check error right in the `addMessage()` method, because for ignored errors we need instantly return `false` to not fix this ignores error.
119119
Fixing is run in a many loops and in the every loop we need to ignore the same errors so after each proccess are ignored error for fixer reset.
120120

121121
Checking outdated files is done by `OutdatedFiles` object, that is activated via `bootstrap-outdated.php`. There is nothing special to write about,

0 commit comments

Comments
 (0)