Skip to content

[Rector] Apply Full PHP 7.3 Rector Set List #4600

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

Closed
Closed
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
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ parameters:
- '#Return type \(bool\) of method CodeIgniter\\Log\\Logger::(emergency|alert|critical|error|warning|notice|info|debug|log)\(\) should be compatible with return type \(null\) of method Psr\\Log\\LoggerInterface::(emergency|alert|critical|error|warning|notice|info|debug|log)\(\)#'
- '#Return type \(bool\) of method CodeIgniter\\HTTP\\Files\\UploadedFile::move\(\) should be compatible with return type \(CodeIgniter\\Files\\File\) of method CodeIgniter\\Files\\File::move\(\)#'
- '#Return type \(bool\) of method CodeIgniter\\Test\\TestLogger::log\(\) should be compatible with return type \(null\) of method Psr\\Log\\LoggerInterface::log\(\)#'
- '#Parameter \#2 \$assoc of function json_decode expects bool, null given#'
reportUnmatchedIgnoredErrors: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be set as true so that we can remove errors no longer applicable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it currently shows notice in php < 8

parallel:
processTimeout: 300.0
scanDirectories:
Expand Down
7 changes: 5 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
use Rector\Php73\Rector\FuncCall\ArrayKeyFirstLastRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;
Expand All @@ -37,6 +37,10 @@
__DIR__ . '/system/Test/bootstrap.php',
]);

$parameters->set(Option::SETS, [
SetList::PHP_73,
]);

// is there a file you need to skip?
$parameters->set(Option::SKIP, [
__DIR__ . '/app/Views',
Expand All @@ -61,7 +65,6 @@
$services->set(ForToForeachRector::class);
$services->set(ChangeNestedForeachIfsToEarlyContinueRector::class);
$services->set(ChangeIfElseValueAssignToEarlyReturnRector::class);
$services->set(ArrayKeyFirstLastRector::class);
$services->set(SimplifyStrposLowerRector::class);
$services->set(CombineIfRector::class);
$services->set(SimplifyIfReturnBoolRector::class);
Expand Down
2 changes: 1 addition & 1 deletion system/API/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected function format($data = null)
{
// Recursively convert objects into associative arrays
// Conversion not required for JSONFormatter
$data = json_decode(json_encode($data), true);
$data = json_decode(json_encode($data, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR);
}

return $this->formatter->format($data);
Expand Down
2 changes: 1 addition & 1 deletion system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ protected function loadInNamespace(string $class)
{
$directory = rtrim($directory, '\\/');

if (strpos($class, $namespace) === 0)
if (strpos($class, (string) $namespace) === 0)
{
$filePath = $directory . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace))) . '.php';
$filename = $this->includeFile($filePath);
Expand Down
2 changes: 1 addition & 1 deletion system/CLI/GeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected function qualifyClassName(): string
$class = $matches[1] . ucfirst($matches[2]);
}

if ($this->enabledSuffixing && $this->getOption('suffix') && ! strripos($class, $component))
if ($this->enabledSuffixing && $this->getOption('suffix') && ! strripos($class, (string) $component))
{
$class .= ucfirst($component);
}
Expand Down
2 changes: 1 addition & 1 deletion system/Database/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function connect($group = null, bool $getShared = true)
if (is_array($group))
{
$config = $group;
$group = 'custom-' . md5(json_encode($config));
$group = 'custom-' . md5(json_encode($config, JSON_THROW_ON_ERROR));
}

$config = $config ?? config('Database');
Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function run(float $startTime, float $totalTime, RequestInterface $reques
$response->CSP->addImageSrc('data:');
}

return json_encode($data);
return json_encode($data, JSON_THROW_ON_ERROR);
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -431,7 +431,7 @@ public function respond()
*/
protected function format(string $data, string $format = 'html'): string
{
$data = json_decode($data, true);
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);

if ($this->config->maxHistory !== 0)
{
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ protected function getEncoding()

foreach ($this->baseCharsets as $charset)
{
if (strpos($this->charset, $charset) === 0)
if (strpos($this->charset, (string) $charset) === 0)
{
$this->encoding = '7bit';

Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
if (isset($config['json']))
{
// Will be set as the body in `applyBody()`
$json = json_encode($config['json']);
$json = json_encode($config['json'], JSON_THROW_ON_ERROR);
$this->setBody($json);
$this->setHeader('Content-Type', 'application/json');
$this->setHeader('Content-Length', (string) strlen($json));
Expand Down
8 changes: 4 additions & 4 deletions system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function getJsonVar(string $index, bool $assoc = false, ?int $filter = nu

if (! $assoc)
{
return json_decode(json_encode($data));
return json_decode(json_encode($data, JSON_THROW_ON_ERROR), null, 512, JSON_THROW_ON_ERROR);
}

return $data;
Expand Down Expand Up @@ -727,14 +727,14 @@ protected function parseRequestURI(): string
if (isset($_SERVER['SCRIPT_NAME'][0]) && pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_EXTENSION) === 'php')
{
// strip the script name from the beginning of the URI
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0 && strpos($uri, '/index.php') === 0)
if (strpos($uri, (string) $_SERVER['SCRIPT_NAME']) === 0 && strpos($uri, '/index.php') === 0)
{
$uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME']));
}
// if the script is nested, strip the parent folder & script from the URI
elseif (strpos($uri, $_SERVER['SCRIPT_NAME']) > 0)
elseif (strpos($uri, (string) $_SERVER['SCRIPT_NAME']) > 0)
{
$uri = (string) substr($uri, strpos($uri, $_SERVER['SCRIPT_NAME']) + strlen($_SERVER['SCRIPT_NAME']));
$uri = (string) substr($uri, strpos($uri, (string) $_SERVER['SCRIPT_NAME']) + strlen($_SERVER['SCRIPT_NAME']));
}
// or if index.php is implied
elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getIPAddress(): string
}

// If the proxy entry doesn't match the IP protocol - skip it
if (strpos($proxyIP, $separator) === false)
if (strpos($proxyIP, (string) $separator) === false)
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Log/Handlers/ChromeLoggerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function sendLogs(ResponseInterface &$response = null)
$response = Services::response(null, true);
}

$data = base64_encode(utf8_encode(json_encode($this->json)));
$data = base64_encode(utf8_encode(json_encode($this->json, JSON_THROW_ON_ERROR)));

$response->setHeader($this->header, $data);
}
Expand Down
2 changes: 1 addition & 1 deletion system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ protected function fillRouteParams(string $from, array $params = null): string

// Ensure that the param we're inserting matches
// the expected param type.
$pos = strpos($from, $pattern);
$pos = strpos($from, (string) $pattern);
$from = substr_replace($from, $params[$index], $pos, strlen($pattern));
}

Expand Down
2 changes: 1 addition & 1 deletion system/Security/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function verify(RequestInterface $request)
{
// We kill this since we're done and we don't want to pollute the JSON data.
unset($json->{$this->tokenName});
$request->setBody(json_encode($json));
$request->setBody(json_encode($json, JSON_THROW_ON_ERROR));
}

if ($this->regenerate)
Expand Down
2 changes: 1 addition & 1 deletion system/Test/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public function getJSON()
*/
public function assertJSONFragment(array $fragment, bool $strict = false)
{
$json = json_decode($this->getJSON(), true);
$json = json_decode($this->getJSON(), true, 512, JSON_THROW_ON_ERROR);
$patched = array_replace_recursive($json, $fragment);

if ($strict)
Expand Down
6 changes: 3 additions & 3 deletions tests/system/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public function testCastAsJsonByFill()

// Check if serialiazed
$check = $this->getPrivateProperty($entity, 'attributes')['eleventh'];
$this->assertEquals(json_encode([1, 2, 3]), $check);
$this->assertEquals(json_encode([1, 2, 3], JSON_THROW_ON_ERROR), $check);

// Check if unserialized
$this->assertEquals([1, 2, 3], $entity->eleventh);
Expand All @@ -563,7 +563,7 @@ public function testCastAsJsonByConstructor()

// Check if serialiazed
$check = $this->getPrivateProperty($entity, 'attributes')['eleventh'];
$this->assertEquals(json_encode([1, 2, 3]), $check);
$this->assertEquals(json_encode([1, 2, 3], JSON_THROW_ON_ERROR), $check);

// Check if unserialized
$this->assertEquals([1, 2, 3], $entity->eleventh);
Expand Down Expand Up @@ -947,7 +947,7 @@ public function testJsonSerializableEntity()
{
$entity = $this->getEntity();
$entity->setBar('foo');
$this->assertEquals(json_encode($entity->toArray()), json_encode($entity));
$this->assertEquals(json_encode($entity->toArray(), JSON_THROW_ON_ERROR), json_encode($entity, JSON_THROW_ON_ERROR));
}

protected function getEntity() : Entity
Expand Down
4 changes: 2 additions & 2 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ public function testJSONData()

$this->assertEquals('post', $this->request->getMethod());

$expected = json_encode($params);
$expected = json_encode($params, JSON_THROW_ON_ERROR);
$this->assertEquals($expected, $this->request->getBody());
}

Expand All @@ -940,7 +940,7 @@ public function testSetJSON()
];
$this->request->setJSON($params)->post('/post');

$this->assertEquals(json_encode($params), $this->request->getBody());
$this->assertEquals(json_encode($params, JSON_THROW_ON_ERROR), $this->request->getBody());
$this->assertEquals('application/json', $this->request->getHeaderLine('Content-Type'));
}

Expand Down
8 changes: 4 additions & 4 deletions tests/system/HTTP/IncomingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function testCanGetAVariableFromJson()
'fizz' => 'buzz',
],
];
$json = json_encode($jsonObj);
$json = json_encode($jsonObj, JSON_THROW_ON_ERROR);

$config = new App();
$config->baseURL = 'http://example.com/';
Expand All @@ -330,7 +330,7 @@ public function testGetJsonVarAsArray()
'foo' => 'bar',
],
];
$json = json_encode($jsonObj);
$json = json_encode($jsonObj, JSON_THROW_ON_ERROR);

$config = new App();
$config->baseURL = 'http://example.com/';
Expand All @@ -345,7 +345,7 @@ public function testGetJsonVarAsArray()

public function testGetJsonVarCanFilter()
{
$json = json_encode(['foo' => 'bar']);
$json = json_encode(['foo' => 'bar'], JSON_THROW_ON_ERROR);

$config = new App();
$config->baseURL = 'http://example.com/';
Expand All @@ -361,7 +361,7 @@ public function testGetVarWorksWithJson()
'foo' => 'bar',
'fizz' => 'buzz',
];
$json = json_encode($jsonObj);
$json = json_encode($jsonObj, JSON_THROW_ON_ERROR);

$config = new App();
$config->baseURL = 'http://example.com/';
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Test/ControllerTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function testResponseOverriding()
->controller(Popcorn::class)
->execute('index3');

$response = json_decode($result->response()->getBody());
$response = json_decode($result->response()->getBody(), null, 512, JSON_THROW_ON_ERROR);
$this->assertEquals('en', $response->lang);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/system/Test/FeatureTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public function testSetupRequestBodyWithParams()

$request = $this->withBodyFormat('json')->setRequestBody($request, ['foo1' => 'bar1']);

$this->assertJsonStringEqualsJsonString(json_encode(['foo1' => 'bar1']), $request->getBody());
$this->assertJsonStringEqualsJsonString(json_encode(['foo1' => 'bar1'], JSON_THROW_ON_ERROR), $request->getBody());
$this->assertTrue('application/json' === $request->header('Content-Type')->getValue());
}

Expand Down
Loading