Skip to content

Commit

Permalink
Merge pull request #9156 from samsonasik/refactor-enable-add-method-c…
Browse files Browse the repository at this point in the history
…all-based-param

refactor: enable AddMethodCallBasedStrictParamTypeRector
  • Loading branch information
samsonasik committed Aug 28, 2024
2 parents 2f78165 + 87eb71c commit 68d2fed
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 33 deletions.
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 @@ -11445,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 @@ -11479,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 @@ -16759,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 @@ -17185,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') {
$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 68d2fed

Please sign in to comment.