Repository navigation
Expand file tree
/
Copy pathphpstan.neon.dist
More file actions
302 lines (273 loc) · 12.8 KB
/
Copy pathphpstan.neon.dist
File metadata and controls
302 lines (273 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# PHPStan configuration for Gutenberg
#
# To override this configuration, create a phpstan.neon which includes this file and adjusts its parameters as
# needed, rather than copying it, so that the copy does not go stale. See docs/contributors/code/coding-guidelines.md
# for examples.
#
# https://phpstan.org/config-reference
includes:
# The base configuration file for using PHPStan with the Gutenberg codebase.
- tools/phpstan/base.neon
# Preexisting errors that should be ignored. Regenerate with `composer phpstan:baselines`, or remove the entries
# for fixed errors with `composer phpstan:fix`.
# https://phpstan.org/user-guide/baseline
- tools/phpstan/baseline.neon
# Rules from phpstan-strict-rules which Gutenberg already complies with. The others are not enabled until the code
# complies with them, but they can be enabled in a local phpstan.neon to work toward that. See
# docs/contributors/code/coding-guidelines.md.
#
# These are registered individually, rather than by including phpstan-strict-rules' rules.neon with only these
# enabled, because that file also makes several PHPStan parameters stricter even when its rules are disabled. That is
# also why composer.json tells phpstan/extension-installer to ignore the package, since it would otherwise include
# rules.neon automatically.
# https://github.com/phpstan/phpstan-strict-rules
rules:
# strictRules.disallowedLooseComparison is registered under `services` below, since it takes an argument.
# strictRules.numericOperandsInArithmeticOperators is registered under `services` below, since its rules need a helper.
# strictRules.disallowedBacktick
- PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule
# strictRules.disallowedImplicitArrayCreation
- PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule
# strictRules.disallowedShortTernary
- PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule
# strictRules.closureUsesThis
- PHPStan\Rules\Functions\ClosureUsesThisRule
# strictRules.matchingInheritedMethodNames
- PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule
# strictRules.switchConditionsMatchingType
- PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule
# strictRules.strictFunctionCalls, which for in_array(), array_search(), and array_keys() is also enforced by the
# WordPress.PHP.StrictInArray sniff.
- PHPStan\Rules\StrictCalls\StrictFunctionCallsRule
# strictRules.illegalConstructorMethodCall
- PHPStan\Rules\Methods\IllegalConstructorMethodCallRule
- PHPStan\Rules\Methods\IllegalConstructorStaticCallRule
# strictRules.dynamicCallOnStaticMethod
- PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule
- PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule
services:
# Ignores strictRules.dynamicCallOnStaticMethod errors for $this->assert*() calls in tests, since PHPUnit's
# assertions are static but conventionally called on $this, as in WordPress core's tests. The phpstan-phpunit
# extension registers this only with bleedingEdge. It matters only to a local phpstan.neon analyzing phpunit/.
-
class: PHPStan\Type\PHPUnit\DynamicCallToAssertionIgnoreExtension
autowired: false
tags:
- phpstan.ignoreErrorExtension
# strictRules.disallowedLooseComparison, with the argument rules.neon passes it.
-
class: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule
arguments:
includeOperandTypesInErrorMessage: %featureToggles.bleedingEdge%
tags:
- phpstan.rules.rule
# strictRules.numericOperandsInArithmeticOperators
# Its rules need an OperatorRuleHelper service. The helper is registered with autowired: false and passed explicitly
# to the twelve rules so that a local phpstan.neon including rules.neon, which also registers one, does not fail with
# "Multiple services of type PHPStan\Rules\Operators\OperatorRuleHelper found". The unary minus and plus rules are
# registered too, although rules.neon enables them only with bleedingEdge, since the code complies with them.
operatorRuleHelper:
class: PHPStan\Rules\Operators\OperatorRuleHelper
autowired: false
-
class: PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandInArithmeticUnaryMinusRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandInArithmeticUnaryPlusRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandsInArithmeticModuloRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
-
class: PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule
arguments:
helper: @operatorRuleHelper
tags:
- phpstan.rules.rule
parameters:
# https://phpstan.org/user-guide/rule-levels
level: 5
reportUnmatchedIgnoredErrors: true
# Errors that are intentionally ignored, as opposed to the baseline, which records errors still to be fixed.
#
# Each entry names the file its error occurs in with `path`, unless it is a rule for every file, which is marked
# `reportUnmatched: false` instead, so that it is not reported when no file breaks it. An entry
# that names no file applies to every file, so phpstan-strict.neon.dist, which analyzes only some of them, would
# report it as unmatched when its error occurs only in the others. An error occurring in several files gets an entry
# for each, since PHPStan reports an entry naming several files with `paths` as unmatched even when it analyzes none
# of them.
ignoreErrors:
# Level 0:
# Return values from action callbacks are discarded by do_action(), but returning one is harmless and lets
# callers and tests know whether the callback did anything. Core has many such callbacks, like _wp_cron() and
# wp_set_up_cross_origin_isolation().
-
message: '#^Action callback returns .+ but should not return anything\.$#'
identifier: return.void
reportUnmatched: false
# wp_get_color_classes_and_styles() is new in WordPress Core: https://github.com/WordPress/wordpress-develop/pull/14094
# Remove this entry once the WordPress stubs are generated from a Core revision that includes it.
-
message: '#^Function wp_get_color_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/calendar/index.php
# wp_get_shadow_classes_and_styles() is new in WordPress Core: https://github.com/WordPress/wordpress-develop/pull/14094
# Remove this entry once the WordPress stubs are generated from a Core revision that includes it.
-
message: '#^Function wp_get_shadow_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/navigation-submenu/index.php
-
message: '#^Function wp_get_shadow_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/post-featured-image/index.php
-
message: '#^Function wp_get_shadow_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/search/index.php
# wp_get_spacing_classes_and_styles() is new in WordPress Core: https://github.com/WordPress/wordpress-develop/pull/14094
# Remove this entry once the WordPress stubs are generated from a Core revision that includes it.
-
message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/comment-author-avatar/index.php
-
message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/icon/index.php
-
message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/post-navigation-link/index.php
# wp_get_background_classes_and_styles() is new in WordPress Core: https://github.com/WordPress/wordpress-develop/pull/14094
# Remove this entry once the WordPress stubs are generated from a Core revision that includes it.
-
message: '#^Function wp_get_background_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/button/index.php
-
message: '#^Function wp_get_background_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/icon/index.php
-
message: '#^Function wp_get_background_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/search/index.php
# wp_get_border_classes_and_styles() is new in WordPress Core: https://github.com/WordPress/wordpress-develop/pull/14094
# Remove this entry once the WordPress stubs are generated from a Core revision that includes it.
-
message: '#^Function wp_get_border_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/avatar/index.php
-
message: '#^Function wp_get_border_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/icon/index.php
-
message: '#^Function wp_get_border_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/post-featured-image/index.php
-
message: '#^Function wp_get_border_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/site-logo/index.php
# wp_get_block_supports_classes_and_styles() is new in WordPress Core: https://github.com/WordPress/wordpress-develop/pull/15485
# Remove this entry once the WordPress stubs are generated from a Core revision that includes it.
-
message: '#^Function wp_get_block_supports_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/avatar/index.php
-
message: '#^Function wp_get_block_supports_classes_and_styles not found\.$#'
identifier: function.notFound
path: packages/block-library/src/post-navigation-link/index.php
# Level 3:
# WP_REST_Request implements ArrayAccess, and the WordPress stubs declare its offsetSet() with a method-level
# template (`@template TOffset of key-of<T>`, `@param T[TOffset] $value`). PHPStan does not resolve that
# template for an offset write like `$request['context'] = 'edit'`, so every such write is rejected, valid
# ones included, while the equivalent `$request->set_param( 'context', 'edit' )` call is accepted.
#
# This is a false positive which should be fixed in PHPStan: https://github.com/phpstan/phpstan-src/pull/6903
# Once a PHPStan release with that fix is required, remove these entries.
-
message: '#^Cannot assign offset .+ to WP_REST_Request(?:<.+>)?\.$#'
identifier: offsetAssign.dimType
reportUnmatched: false
-
message: '#^WP_REST_Request(?:<.+>)? does not accept .+\.$#'
identifier: offsetAssign.valueType
reportUnmatched: false
# Level 4:
# The Navigation block checks for WP_Theme_JSON_Gutenberg::get_viewport_media_queries() before falling back to
# WP_Theme_JSON. PHPStan sees the Gutenberg class as always defined, but the block library also runs in
# WordPress Core, where it is not, so the check is needed there.
-
message: '#^Call to function method_exists\(\) with ''WP_Theme_JSON…'' and ''get_viewport_media…'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
path: packages/block-library/src/navigation/index.php
# strictRules.dynamicCallOnStaticMethod:
# PHPUnit's markTestSkipped() is static, but like its assertions, which DynamicCallToAssertionIgnoreExtension
# covers above, it is conventionally called on $this, as in WordPress core's tests. The tests are analyzed only
# by a local phpstan.neon, so this entry goes unmatched otherwise.
-
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert::markTestSkipped\(\)\.$#'
identifier: staticMethod.dynamicCall
path: phpunit/*
reportUnmatched: false