Skip to content

Commit 7cd4d32

Browse files
authored
Fix variable.undefined (and other) errors (#9513)
1 parent bd60f50 commit 7cd4d32

17 files changed

+70
-751
lines changed

phpstan.neon.dist

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
11
includes:
2-
- utils/phpstan-baseline/loader.neon
2+
- utils/phpstan-baseline/loader.neon
33

44
parameters:
5-
phpVersion: 80100
6-
tmpDir: build/phpstan
7-
level: 6
8-
bootstrapFiles:
9-
- phpstan-bootstrap.php
10-
paths:
11-
- admin/starter/tests
12-
- app
13-
- system
14-
- tests
15-
excludePaths:
16-
- app/Views/errors/cli/*
17-
- app/Views/errors/html/*
18-
- system/Commands/Generators/Views/*
19-
- system/Debug/Toolbar/Views/toolbar.tpl.php
20-
- system/Images/Handlers/GDHandler.php
21-
- system/Test/Filters/CITestStreamFilter.php
22-
- system/ThirdParty/*
23-
- system/Validation/Views/single.php
24-
- tests/system/View/Views/*
25-
scanDirectories:
26-
- system/Helpers
27-
ignoreErrors:
28-
-
29-
identifier: missingType.generics
30-
checkMissingCallableSignature: true
31-
treatPhpDocTypesAsCertain: false
32-
strictRules:
33-
allRules: false
34-
disallowedLooseComparison: true
35-
booleansInConditions: true
36-
disallowedBacktick: true
37-
disallowedEmpty: true
38-
disallowedImplicitArrayCreation: true
39-
disallowedShortTernary: true
40-
matchingInheritedMethodNames: true
41-
codeigniter:
42-
additionalServices:
43-
- AfterAutoloadModule\Config\Services
44-
checkArgumentTypeOfModel: false
45-
shipmonkBaselinePerIdentifier:
46-
directory: %currentWorkingDirectory%
5+
phpVersion: 80100
6+
tmpDir: build/phpstan
7+
level: 6
8+
bootstrapFiles:
9+
- phpstan-bootstrap.php
10+
paths:
11+
- admin/starter/tests
12+
- app
13+
- system
14+
- tests
15+
excludePaths:
16+
analyseAndScan:
17+
- app/Views/errors/cli/*
18+
- app/Views/errors/html/*
19+
- system/Commands/Generators/Views/*
20+
- system/Debug/Toolbar/Views/toolbar.tpl.php
21+
- system/Images/Handlers/GDHandler.php
22+
- system/Test/Filters/CITestStreamFilter.php
23+
- system/ThirdParty/*
24+
- system/Validation/Views/single.php
25+
- tests/system/View/Views/*
26+
analyse:
27+
- tests/_support/*
28+
scanDirectories:
29+
- system/Helpers
30+
ignoreErrors:
31+
-
32+
identifier: missingType.generics
33+
checkMissingCallableSignature: true
34+
treatPhpDocTypesAsCertain: false
35+
strictRules:
36+
allRules: false
37+
disallowedLooseComparison: true
38+
booleansInConditions: true
39+
disallowedBacktick: true
40+
disallowedEmpty: true
41+
disallowedImplicitArrayCreation: true
42+
disallowedShortTernary: true
43+
matchingInheritedMethodNames: true
44+
codeigniter:
45+
additionalServices:
46+
- AfterAutoloadModule\Config\Services
47+
checkArgumentTypeOfModel: false
48+
shipmonkBaselinePerIdentifier:
49+
directory: %currentWorkingDirectory%

system/Cache/Handlers/FileHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ protected function writeFile($path, $data, $mode = 'wb')
269269

270270
flock($fp, LOCK_EX);
271271

272-
for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) {
272+
$result = 0;
273+
274+
for ($written = 0, $length = strlen($data); $written < $length; $written += $result) {
273275
if (($result = fwrite($fp, substr($data, $written))) === false) {
274276
break;
275277
}

system/Helpers/filesystem_helper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ function write_file(string $path, string $data, string $mode = 'wb'): bool
123123

124124
flock($fp, LOCK_EX);
125125

126-
for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) {
126+
$result = 0;
127+
128+
for ($written = 0, $length = strlen($data); $written < $length; $written += $result) {
127129
if (($result = fwrite($fp, substr($data, $written))) === false) {
128130
break;
129131
}

system/Session/Handlers/FileHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ public function write($id, $data): bool
201201
if (($length = strlen($data)) > 0) {
202202
$result = null;
203203

204-
for ($written = 0; $written < $length; $written += $result) {
204+
$written = 0;
205+
206+
for (; $written < $length; $written += $result) {
205207
if (($result = fwrite($this->fileHandle, substr($data, $written))) === false) {
206208
break;
207209
}

system/Test/FilterTestTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ protected function getFilterCaller($filter, string $position): Closure
163163

164164
if ($position === 'before') {
165165
return static function (?array $params = null) use ($filterInstances, $request) {
166+
$result = null;
167+
166168
foreach ($filterInstances as $filter) {
167169
$result = $filter->before($request, $params);
168170

@@ -188,6 +190,8 @@ protected function getFilterCaller($filter, string $position): Closure
188190
$response = clone $this->response;
189191

190192
return static function (?array $params = null) use ($filterInstances, $request, $response) {
193+
$result = null;
194+
191195
foreach ($filterInstances as $filter) {
192196
$result = $filter->after($request, $response, $params);
193197

utils/phpstan-baseline/argument.type.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 148 errors
1+
# total 146 errors
22

33
parameters:
44
ignoreErrors:
@@ -32,11 +32,6 @@ parameters:
3232
count: 1
3333
path: ../../system/Log/Handlers/ErrorlogHandler.php
3434

35-
-
36-
message: '#^Parameter \#1 \$fields of method CodeIgniter\\Database\\Forge\:\:addField\(\) expects array\<string, array\|string\>\|string, array\<int\|string, array\<string, bool\|int\|string\>\|string\> given\.$#'
37-
count: 2
38-
path: ../../tests/_support/Database/Migrations/20160428212500_Create_test_tables.php
39-
4035
-
4136
message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: \(CodeIgniter\\HTTP\\DownloadResponse\|null\) given\.$#'
4237
count: 1

utils/phpstan-baseline/loader.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 3760 errors
1+
# total 3615 errors
22
includes:
33
- argument.type.neon
44
- assign.propertyType.neon
@@ -39,4 +39,3 @@ includes:
3939
- staticMethod.notFound.neon
4040
- ternary.shortNotAllowed.neon
4141
- varTag.type.neon
42-
- variable.undefined.neon
Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 17 errors
1+
# total 9 errors
22

33
parameters:
44
ignoreErrors:
@@ -46,43 +46,3 @@ parameters:
4646
message: '#^Parameter \#1 \$level \(string\) of method CodeIgniter\\Log\\Logger\:\:log\(\) should be contravariant with parameter \$level \(mixed\) of method Psr\\Log\\LoggerInterface\:\:log\(\)$#'
4747
count: 1
4848
path: ../../system/Log/Logger.php
49-
50-
-
51-
message: '#^Parameter \#1 \$value \(string\) of method Tests\\Support\\Entity\\Cast\\CastBase64\:\:get\(\) should be contravariant with parameter \$value \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\BaseCast\:\:get\(\)$#'
52-
count: 1
53-
path: ../../tests/_support/Entity/Cast/CastBase64.php
54-
55-
-
56-
message: '#^Parameter \#1 \$value \(string\) of method Tests\\Support\\Entity\\Cast\\CastBase64\:\:get\(\) should be contravariant with parameter \$value \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\CastInterface\:\:get\(\)$#'
57-
count: 1
58-
path: ../../tests/_support/Entity/Cast/CastBase64.php
59-
60-
-
61-
message: '#^Parameter \#1 \$value \(string\) of method Tests\\Support\\Entity\\Cast\\CastBase64\:\:set\(\) should be contravariant with parameter \$value \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\BaseCast\:\:set\(\)$#'
62-
count: 1
63-
path: ../../tests/_support/Entity/Cast/CastBase64.php
64-
65-
-
66-
message: '#^Parameter \#1 \$value \(string\) of method Tests\\Support\\Entity\\Cast\\CastBase64\:\:set\(\) should be contravariant with parameter \$value \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\CastInterface\:\:set\(\)$#'
67-
count: 1
68-
path: ../../tests/_support/Entity/Cast/CastBase64.php
69-
70-
-
71-
message: '#^Parameter \#1 \$binary \(string\) of method Tests\\Support\\Entity\\Cast\\CastBinaryUUID\:\:get\(\) should be contravariant with parameter \$value \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\BaseCast\:\:get\(\)$#'
72-
count: 1
73-
path: ../../tests/_support/Entity/Cast/CastBinaryUUID.php
74-
75-
-
76-
message: '#^Parameter \#1 \$binary \(string\) of method Tests\\Support\\Entity\\Cast\\CastBinaryUUID\:\:get\(\) should be contravariant with parameter \$value \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\CastInterface\:\:get\(\)$#'
77-
count: 1
78-
path: ../../tests/_support/Entity/Cast/CastBinaryUUID.php
79-
80-
-
81-
message: '#^Parameter \#1 \$string \(string\) of method Tests\\Support\\Entity\\Cast\\CastBinaryUUID\:\:set\(\) should be contravariant with parameter \$value \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\BaseCast\:\:set\(\)$#'
82-
count: 1
83-
path: ../../tests/_support/Entity/Cast/CastBinaryUUID.php
84-
85-
-
86-
message: '#^Parameter \#1 \$string \(string\) of method Tests\\Support\\Entity\\Cast\\CastBinaryUUID\:\:set\(\) should be contravariant with parameter \$value \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\CastInterface\:\:set\(\)$#'
87-
count: 1
88-
path: ../../tests/_support/Entity/Cast/CastBinaryUUID.php

utils/phpstan-baseline/method.childReturnType.neon

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 40 errors
1+
# total 38 errors
22

33
parameters:
44
ignoreErrors:
@@ -186,13 +186,3 @@ parameters:
186186
message: '#^Return type \(mixed\) of method CodeIgniter\\Test\\Mock\\MockResult\:\:fetchAssoc\(\) should be covariant with return type \(array\|false\|null\) of method CodeIgniter\\Database\\BaseResult\<object\|resource,object\|resource\>\:\:fetchAssoc\(\)$#'
187187
count: 1
188188
path: ../../system/Test/Mock/MockResult.php
189-
190-
-
191-
message: '#^Return type \(mixed\) of method Tests\\Support\\Entity\\Cast\\CastPassParameters\:\:set\(\) should be covariant with return type \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\BaseCast\:\:set\(\)$#'
192-
count: 1
193-
path: ../../tests/_support/Entity/Cast/CastPassParameters.php
194-
195-
-
196-
message: '#^Return type \(mixed\) of method Tests\\Support\\Entity\\Cast\\CastPassParameters\:\:set\(\) should be covariant with return type \(array\|bool\|float\|int\|object\|string\|null\) of method CodeIgniter\\Entity\\Cast\\CastInterface\:\:set\(\)$#'
197-
count: 1
198-
path: ../../tests/_support/Entity/Cast/CastPassParameters.php

utils/phpstan-baseline/method.notFound.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 83 errors
1+
# total 82 errors
22

33
parameters:
44
ignoreErrors:
@@ -17,11 +17,6 @@ parameters:
1717
count: 2
1818
path: ../../system/Debug/Toolbar/Collectors/Views.php
1919

20-
-
21-
message: '#^Call to an undefined method CodeIgniter\\Database\\ConnectionInterface\:\:tableExists\(\)\.$#'
22-
count: 1
23-
path: ../../tests/_support/MigrationTestMigrations/Database/Migrations/2018-01-24-102302_Another_migration.php
24-
2520
-
2621
message: '#^Call to an undefined method CodeIgniter\\HTTP\\ResponseInterface\:\:pretend\(\)\.$#'
2722
count: 1

0 commit comments

Comments
 (0)