Skip to content

refactor: fix variable.undefined (and other) errors #9513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 46 additions & 43 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
includes:
- utils/phpstan-baseline/loader.neon
- utils/phpstan-baseline/loader.neon

parameters:
phpVersion: 80100
tmpDir: build/phpstan
level: 6
bootstrapFiles:
- phpstan-bootstrap.php
paths:
- admin/starter/tests
- app
- system
- tests
excludePaths:
- app/Views/errors/cli/*
- app/Views/errors/html/*
- system/Commands/Generators/Views/*
- system/Debug/Toolbar/Views/toolbar.tpl.php
- system/Images/Handlers/GDHandler.php
- system/Test/Filters/CITestStreamFilter.php
- system/ThirdParty/*
- system/Validation/Views/single.php
- tests/system/View/Views/*
scanDirectories:
- system/Helpers
ignoreErrors:
-
identifier: missingType.generics
checkMissingCallableSignature: true
treatPhpDocTypesAsCertain: false
strictRules:
allRules: false
disallowedLooseComparison: true
booleansInConditions: true
disallowedBacktick: true
disallowedEmpty: true
disallowedImplicitArrayCreation: true
disallowedShortTernary: true
matchingInheritedMethodNames: true
codeigniter:
additionalServices:
- AfterAutoloadModule\Config\Services
checkArgumentTypeOfModel: false
shipmonkBaselinePerIdentifier:
directory: %currentWorkingDirectory%
phpVersion: 80100
tmpDir: build/phpstan
level: 6
bootstrapFiles:
- phpstan-bootstrap.php
paths:
- admin/starter/tests
- app
- system
- tests
excludePaths:
analyseAndScan:
- app/Views/errors/cli/*
- app/Views/errors/html/*
- system/Commands/Generators/Views/*
- system/Debug/Toolbar/Views/toolbar.tpl.php
- system/Images/Handlers/GDHandler.php
- system/Test/Filters/CITestStreamFilter.php
- system/ThirdParty/*
- system/Validation/Views/single.php
- tests/system/View/Views/*
analyse:
- tests/_support/*
scanDirectories:
- system/Helpers
ignoreErrors:
-
identifier: missingType.generics
checkMissingCallableSignature: true
treatPhpDocTypesAsCertain: false
strictRules:
allRules: false
disallowedLooseComparison: true
booleansInConditions: true
disallowedBacktick: true
disallowedEmpty: true
disallowedImplicitArrayCreation: true
disallowedShortTernary: true
matchingInheritedMethodNames: true
codeigniter:
additionalServices:
- AfterAutoloadModule\Config\Services
checkArgumentTypeOfModel: false
shipmonkBaselinePerIdentifier:
directory: %currentWorkingDirectory%
4 changes: 3 additions & 1 deletion system/Cache/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ protected function writeFile($path, $data, $mode = 'wb')

flock($fp, LOCK_EX);

for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) {
$result = 0;

for ($written = 0, $length = strlen($data); $written < $length; $written += $result) {
if (($result = fwrite($fp, substr($data, $written))) === false) {
break;
}
Expand Down
4 changes: 3 additions & 1 deletion system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ function write_file(string $path, string $data, string $mode = 'wb'): bool

flock($fp, LOCK_EX);

for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) {
$result = 0;

for ($written = 0, $length = strlen($data); $written < $length; $written += $result) {
if (($result = fwrite($fp, substr($data, $written))) === false) {
break;
}
Expand Down
4 changes: 3 additions & 1 deletion system/Session/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ public function write($id, $data): bool
if (($length = strlen($data)) > 0) {
$result = null;

for ($written = 0; $written < $length; $written += $result) {
$written = 0;

for (; $written < $length; $written += $result) {
if (($result = fwrite($this->fileHandle, substr($data, $written))) === false) {
break;
}
Expand Down
4 changes: 4 additions & 0 deletions system/Test/FilterTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ protected function getFilterCaller($filter, string $position): Closure

if ($position === 'before') {
return static function (?array $params = null) use ($filterInstances, $request) {
$result = null;

foreach ($filterInstances as $filter) {
$result = $filter->before($request, $params);

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

return static function (?array $params = null) use ($filterInstances, $request, $response) {
$result = null;

foreach ($filterInstances as $filter) {
$result = $filter->after($request, $response, $params);

Expand Down
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/argument.type.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 148 errors
# total 146 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -32,11 +32,6 @@ parameters:
count: 1
path: ../../system/Log/Handlers/ErrorlogHandler.php

-
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\.$#'
count: 2
path: ../../tests/_support/Database/Migrations/20160428212500_Create_test_tables.php

-
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\.$#'
count: 1
Expand Down
3 changes: 1 addition & 2 deletions utils/phpstan-baseline/loader.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 3760 errors
# total 3615 errors
includes:
- argument.type.neon
- assign.propertyType.neon
Expand Down Expand Up @@ -39,4 +39,3 @@ includes:
- staticMethod.notFound.neon
- ternary.shortNotAllowed.neon
- varTag.type.neon
- variable.undefined.neon
42 changes: 1 addition & 41 deletions utils/phpstan-baseline/method.childParameterType.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 17 errors
# total 9 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -46,43 +46,3 @@ parameters:
message: '#^Parameter \#1 \$level \(string\) of method CodeIgniter\\Log\\Logger\:\:log\(\) should be contravariant with parameter \$level \(mixed\) of method Psr\\Log\\LoggerInterface\:\:log\(\)$#'
count: 1
path: ../../system/Log/Logger.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastBase64.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastBase64.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastBase64.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastBase64.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastBinaryUUID.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastBinaryUUID.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastBinaryUUID.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastBinaryUUID.php
12 changes: 1 addition & 11 deletions utils/phpstan-baseline/method.childReturnType.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 40 errors
# total 38 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -186,13 +186,3 @@ parameters:
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\(\)$#'
count: 1
path: ../../system/Test/Mock/MockResult.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastPassParameters.php

-
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\(\)$#'
count: 1
path: ../../tests/_support/Entity/Cast/CastPassParameters.php
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/method.notFound.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 83 errors
# total 82 errors

parameters:
ignoreErrors:
Expand All @@ -17,11 +17,6 @@ parameters:
count: 2
path: ../../system/Debug/Toolbar/Collectors/Views.php

-
message: '#^Call to an undefined method CodeIgniter\\Database\\ConnectionInterface\:\:tableExists\(\)\.$#'
count: 1
path: ../../tests/_support/MigrationTestMigrations/Database/Migrations/2018-01-24-102302_Another_migration.php

-
message: '#^Call to an undefined method CodeIgniter\\HTTP\\ResponseInterface\:\:pretend\(\)\.$#'
count: 1
Expand Down
Loading
Loading