Skip to content

refactor: enable AddMethodCallBasedStrictParamTypeRector #9156

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
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
34 changes: 8 additions & 26 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@
$ignoreErrors[] = [
// identifier: empty.notAllowed
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 30,
'count' => 29,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
Expand Down Expand Up @@ -1933,6 +1933,12 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: isset.offset
'message' => '#^Offset 4 on array\\{string, string, string, string, string, string\\} in isset\\(\\) always exists and is not nullable\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: booleanNot.exprNotBoolean
'message' => '#^Only booleans are allowed in a negated boolean, TWhenNot given\\.$#',
Expand Down Expand Up @@ -11451,7 +11457,7 @@
];
$ignoreErrors[] = [
// identifier: codeigniter.superglobalAccessAssign
'message' => '#^Assigning mixed directly on offset \'CONTENT_TYPE\' of \\$_SERVER is discouraged\\.$#',
'message' => '#^Assigning string directly on offset \'CONTENT_TYPE\' of \\$_SERVER is discouraged\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
];
Expand Down Expand Up @@ -11485,18 +11491,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.parameter
'message' => '#^Method CodeIgniter\\\\API\\\\ResponseTraitTest\\:\\:tryValidContentType\\(\\) has parameter \\$contentType with no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.parameter
'message' => '#^Method CodeIgniter\\\\API\\\\ResponseTraitTest\\:\\:tryValidContentType\\(\\) has parameter \\$mimeType with no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.parameter
'message' => '#^Method class@anonymous/tests/system/API/ResponseTraitTest\\.php\\:116\\:\\:__construct\\(\\) has parameter \\$formatter with no type specified\\.$#',
Expand Down Expand Up @@ -16765,12 +16759,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/RESTful/ResourcePresenterTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.parameter
'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouterImprovedTest\\:\\:createNewAutoRouter\\(\\) has parameter \\$namespace with no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Router/AutoRouterImprovedTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouterImprovedTest\\:\\:provideRejectTranslateUriToCamelCase\\(\\) return type has no value type specified in iterable type iterable\\.$#',
Expand Down Expand Up @@ -17191,12 +17179,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Test/BootstrapFCPATHTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.parameter
'message' => '#^Method CodeIgniter\\\\Test\\\\BootstrapFCPATHTest\\:\\:readOutput\\(\\) has parameter \\$file with no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Test/BootstrapFCPATHTest.php',
];
$ignoreErrors[] = [
// identifier: method.notFound
'message' => '#^Call to an undefined method CodeIgniter\\\\Test\\\\TestResponse\\:\\:ohno\\(\\)\\.$#',
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
Expand Down Expand Up @@ -213,6 +214,7 @@
ExplicitBoolCompareRector::class,
AddClosureVoidReturnTypeWhereNoReturnRector::class,
AddFunctionVoidReturnTypeWhereNoReturnRector::class,
AddMethodCallBasedStrictParamTypeRector::class,
])
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
// keep '\\' prefix string on string '\Foo\Bar'
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3178,7 +3178,7 @@ protected function compileWhereHaving(string $qbKey): string
// 5 => ')' /* optional */
// );

if (! empty($matches[4])) {
if (isset($matches[4]) && $matches[4] !== '' && $matches[4] !== '0') {
$protectIdentifiers = false;
if (str_contains($matches[4], '.')) {
$protectIdentifiers = true;
Expand Down
4 changes: 1 addition & 3 deletions system/Database/Postgre/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,8 @@ static function ($key, $value) use ($table, $alias, $that) {
* Returns cast expression.
*
* @TODO move this to BaseBuilder in 4.5.0
*
* @param float|int|string $expression
*/
private function cast($expression, ?string $type): string
private function cast(string $expression, ?string $type): string
{
return ($type === null) ? $expression : 'CAST(' . $expression . ' AS ' . strtoupper($type) . ')';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/system/API/ResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public function testValidContentTypes(): void
}
}

private function tryValidContentType($mimeType, $contentType): void
private function tryValidContentType(string $mimeType, string $contentType): void
{
$original = $_SERVER;
$_SERVER['CONTENT_TYPE'] = $mimeType;
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Router/AutoRouterImprovedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function setUp(): void
$this->collection = new RouteCollection(Services::locator(), $moduleConfig, new Routing());
}

private function createNewAutoRouter($namespace = 'CodeIgniter\Router\Controllers'): AutoRouterImproved
private function createNewAutoRouter(string $namespace = 'CodeIgniter\Router\Controllers'): AutoRouterImproved
{
return new AutoRouterImproved(
[],
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Test/BootstrapFCPATHTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function fileContents()
return $fileContents . ('echo FCPATH;' . PHP_EOL);
}

private function readOutput($file)
private function readOutput(string $file)
{
ob_start();
system('php -f ' . $file);
Expand Down
Loading