Skip to content

Commit

Permalink
refactor: enable AddMethodCallBasedStrictParamTypeRector
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Aug 28, 2024
1 parent 655bd1d commit 6b1f135
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 32 deletions.
26 changes: 1 addition & 25 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -11451,7 +11451,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 +11485,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 +16753,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 +17173,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') {

Check failure on line 3181 in system/Database/BaseBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Offset 4 on array{string, string, string, string, string, string} in isset() always exists and is not nullable.
$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

0 comments on commit 6b1f135

Please sign in to comment.