Skip to content

Commit aa00085

Browse files
authored
chore: analyse the PHP samples of the user guide with PHPStan (#10779)
1 parent 5ac1923 commit aa00085

70 files changed

Lines changed: 1093 additions & 270 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/test-phpstan.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
- composer.json
1616
- phpstan.dist.neon
1717
- phpstan-baseline.php
18+
- 'docs/**'
19+
- 'admin/lint-docs-samples.php'
20+
- 'admin/docs-phpstan-baseline.php'
1821
- '.github/workflows/test-phpstan.yml'
1922

2023
push:
@@ -29,6 +32,9 @@ on:
2932
- composer.json
3033
- phpstan.dist.neon
3134
- phpstan-baseline.php
35+
- 'docs/**'
36+
- 'admin/lint-docs-samples.php'
37+
- 'admin/docs-phpstan-baseline.php'
3238
- '.github/workflows/test-phpstan.yml'
3339

3440
concurrency:
@@ -89,3 +95,8 @@ jobs:
8995

9096
- name: Run static analysis
9197
run: composer phpstan:check
98+
99+
- name: Check that the baseline of the user guide samples is up to date
100+
run: |
101+
composer phpstan:docs-baseline
102+
git diff --exit-code admin/docs-phpstan-baseline.php

‎admin/docs-phpstan-baseline.php‎

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
/**
15+
* PHPStan exceptions for the PHP samples of the user guide.
16+
*
17+
* An entry is a page relative to the project root, for all of its samples, or `page:line`, for the sample
18+
* whose opening ```php fence is on that line.
19+
*
20+
* - `ignoreErrors`: an error identifier, optionally narrowed by a `message` pattern, ignored in the samples of the
21+
* listed `paths` or, without them, in all samples. This list is written by hand.
22+
* - `baseline`: the samples that are skipped, for errors that PHPStan does not allow to be ignored, and the errors
23+
* that are ignored in a sample. It is written by `php admin/lint-docs-samples.php --phpstan --generate-baseline`.
24+
*
25+
* @return array{
26+
* ignoreErrors: list<array{identifier: string, message?: string, paths?: list<string>}>,
27+
* baseline: array{
28+
* excludePaths: list<string>,
29+
* ignoreErrors: list<array{identifier: string, paths: list<string>}>
30+
* }
31+
* }
32+
*/
33+
return [
34+
'ignoreErrors' => [
35+
// Samples are fragments: they leave out code, and the classes and functions that they refer to.
36+
['identifier' => 'class.notFound'],
37+
['identifier' => 'codeigniter.configArgumentInstanceof'],
38+
['identifier' => 'codeigniter.configArgumentType'],
39+
['identifier' => 'codeigniter.modelArgumentType'],
40+
['identifier' => 'codeigniter.unknownServiceMethod'],
41+
['identifier' => 'expr.resultUnused'],
42+
['identifier' => 'function.notFound'],
43+
['identifier' => 'method.unused'],
44+
['identifier' => 'variable.undefined'],
45+
46+
// A class that a sample declares, and that several samples declare differently, is resolved to one of them.
47+
[
48+
'identifier' => 'method.notFound',
49+
'message' => '#^Call to an undefined method (App\\\\|Tests\\\\|SampleCommand::|MyRules::|MyTestClass::)#',
50+
],
51+
[
52+
'identifier' => 'property.notFound',
53+
'message' => '#^Access to an undefined property (App\\\\|Config\\\\|SampleCommand::)#',
54+
],
55+
],
56+
57+
// Everything below is @autogenerated by --generate-baseline.
58+
'baseline' => [
59+
'excludePaths' => [
60+
'docs/cli/cli_signals.md:201',
61+
'docs/cli/cli_signals.md:417',
62+
'docs/concepts/services.md:147',
63+
'docs/dbmgmt/migration.md:78',
64+
'docs/extending/core_classes.md:64',
65+
'docs/guides/api/controller.md:21',
66+
'docs/guides/first-app/static_pages.md:55',
67+
'docs/incoming/filters.md:59',
68+
'docs/installation/upgrade_412.md:37',
69+
'docs/models/model.md:75',
70+
],
71+
'ignoreErrors' => [
72+
[
73+
'identifier' => 'argument.type',
74+
'paths' => [
75+
'docs/cli/cli_commands.md:78',
76+
'docs/cli/cli_library.md:240',
77+
'docs/extending/events.md:25',
78+
'docs/extending/events.md:51',
79+
'docs/extending/events.md:92',
80+
'docs/outgoing/api_responses.md:512',
81+
'docs/outgoing/api_transformers.md:118',
82+
'docs/outgoing/api_transformers.md:415',
83+
],
84+
],
85+
86+
[
87+
'identifier' => 'catch.neverThrown',
88+
'paths' => [
89+
'docs/cli/cli_commands.md:145',
90+
'docs/general/logging.md:125',
91+
],
92+
],
93+
94+
[
95+
'identifier' => 'deadCode.unreachable',
96+
'paths' => [
97+
'docs/installation/upgrade_localization.md:61',
98+
'docs/outgoing/localization.md:271',
99+
'docs/outgoing/localization.md:310',
100+
'docs/outgoing/localization.md:377',
101+
'docs/outgoing/response.md:31',
102+
'docs/outgoing/view_parser.md:275',
103+
],
104+
],
105+
106+
[
107+
'identifier' => 'if.alwaysFalse',
108+
'paths' => [
109+
'docs/cli/cli_signals.md:531',
110+
],
111+
],
112+
113+
[
114+
'identifier' => 'method.nonObject',
115+
'paths' => [
116+
'docs/outgoing/api_transformers.md:235',
117+
'docs/outgoing/api_transformers.md:309',
118+
'docs/outgoing/api_transformers.md:684',
119+
'docs/outgoing/view_cells.md:324',
120+
'docs/outgoing/view_cells.md:347',
121+
],
122+
],
123+
124+
[
125+
'identifier' => 'new.noConstructor',
126+
'paths' => [
127+
'docs/concepts/services.md:162',
128+
'docs/concepts/services.md:221',
129+
'docs/extending/core_classes.md:81',
130+
'docs/testing/fabricator.md:50',
131+
],
132+
],
133+
134+
[
135+
'identifier' => 'outOfClass.self',
136+
'paths' => [
137+
'docs/testing/overview.md:293',
138+
],
139+
],
140+
141+
[
142+
'identifier' => 'paramOut.type',
143+
'paths' => [
144+
'docs/libraries/validation.md:1045',
145+
],
146+
],
147+
148+
[
149+
'identifier' => 'property.defaultValue',
150+
'paths' => [
151+
'docs/outgoing/view_parser.md:520',
152+
'docs/testing/database.md:73',
153+
],
154+
],
155+
156+
[
157+
'identifier' => 'property.nonObject',
158+
'paths' => [
159+
'docs/testing/fabricator.md:87',
160+
],
161+
],
162+
163+
[
164+
'identifier' => 'property.notFound',
165+
'paths' => [
166+
'docs/installation/upgrade_sessions.md:39',
167+
],
168+
],
169+
170+
[
171+
'identifier' => 'property.onlyWritten',
172+
'paths' => [
173+
'docs/installation/deployment.md:78',
174+
],
175+
],
176+
177+
[
178+
'identifier' => 'property.protected',
179+
'paths' => [
180+
'docs/libraries/time.md:417',
181+
],
182+
],
183+
184+
[
185+
'identifier' => 'return.missing',
186+
'paths' => [
187+
'docs/incoming/filters.md:18',
188+
'docs/testing/fabricator.md:9',
189+
],
190+
],
191+
192+
[
193+
'identifier' => 'return.type',
194+
'paths' => [
195+
'docs/concepts/services.md:162',
196+
'docs/concepts/services.md:221',
197+
'docs/extending/core_classes.md:81',
198+
],
199+
],
200+
201+
[
202+
'identifier' => 'variable.implicitArray',
203+
'paths' => [
204+
'docs/incoming/routing.md:625',
205+
'docs/installation/upgrade_localization.md:45',
206+
],
207+
],
208+
],
209+
],
210+
];

0 commit comments

Comments
 (0)