Skip to content

Commit 2b2182c

Browse files
committed
[Rector] Apply Full PHP 7.3 Rector Set List
1 parent 35fc1d0 commit 2b2182c

20 files changed

+85
-73
lines changed

rector.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
2222
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
2323
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
24-
use Rector\Php73\Rector\FuncCall\ArrayKeyFirstLastRector;
24+
use Rector\Set\ValueObject\SetList;
2525
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
2626
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
2727
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;
@@ -37,6 +37,10 @@
3737
__DIR__ . '/system/Test/bootstrap.php',
3838
]);
3939

40+
$parameters->set(Option::SETS, [
41+
SetList::PHP_73,
42+
]);
43+
4044
// is there a file you need to skip?
4145
$parameters->set(Option::SKIP, [
4246
__DIR__ . '/app/Views',
@@ -61,7 +65,6 @@
6165
$services->set(ForToForeachRector::class);
6266
$services->set(ChangeNestedForeachIfsToEarlyContinueRector::class);
6367
$services->set(ChangeIfElseValueAssignToEarlyReturnRector::class);
64-
$services->set(ArrayKeyFirstLastRector::class);
6568
$services->set(SimplifyStrposLowerRector::class);
6669
$services->set(CombineIfRector::class);
6770
$services->set(SimplifyIfReturnBoolRector::class);

system/API/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ protected function format($data = null)
401401
{
402402
// Recursively convert objects into associative arrays
403403
// Conversion not required for JSONFormatter
404-
$data = json_decode(json_encode($data), true);
404+
$data = json_decode(json_encode($data, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR);
405405
}
406406

407407
return $this->formatter->format($data);

system/Autoloader/Autoloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ protected function loadInNamespace(string $class)
259259
{
260260
$directory = rtrim($directory, '\\/');
261261

262-
if (strpos($class, $namespace) === 0)
262+
if (strpos($class, (string) $namespace) === 0)
263263
{
264264
$filePath = $directory . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace))) . '.php';
265265
$filename = $this->includeFile($filePath);

system/CLI/GeneratorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protected function qualifyClassName(): string
231231
$class = $matches[1] . ucfirst($matches[2]);
232232
}
233233

234-
if ($this->enabledSuffixing && $this->getOption('suffix') && ! strripos($class, $component))
234+
if ($this->enabledSuffixing && $this->getOption('suffix') && ! strripos($class, (string) $component))
235235
{
236236
$class .= ucfirst($component);
237237
}

system/Database/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function connect($group = null, bool $getShared = true)
5656
if (is_array($group))
5757
{
5858
$config = $group;
59-
$group = 'custom-' . md5(json_encode($config));
59+
$group = 'custom-' . md5(json_encode($config, JSON_THROW_ON_ERROR));
6060
}
6161

6262
$config = $config ?? config('Database');

system/Debug/Toolbar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function run(float $startTime, float $totalTime, RequestInterface $reques
165165
$response->CSP->addImageSrc('data:');
166166
}
167167

168-
return json_encode($data);
168+
return json_encode($data, JSON_THROW_ON_ERROR);
169169
}
170170

171171
//--------------------------------------------------------------------
@@ -431,7 +431,7 @@ public function respond()
431431
*/
432432
protected function format(string $data, string $format = 'html'): string
433433
{
434-
$data = json_decode($data, true);
434+
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
435435

436436
if ($this->config->maxHistory !== 0)
437437
{

system/Email/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ protected function getEncoding()
940940

941941
foreach ($this->baseCharsets as $charset)
942942
{
943-
if (strpos($this->charset, $charset) === 0)
943+
if (strpos($this->charset, (string) $charset) === 0)
944944
{
945945
$this->encoding = '7bit';
946946

system/HTTP/CURLRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
734734
if (isset($config['json']))
735735
{
736736
// Will be set as the body in `applyBody()`
737-
$json = json_encode($config['json']);
737+
$json = json_encode($config['json'], JSON_THROW_ON_ERROR);
738738
$this->setBody($json);
739739
$this->setHeader('Content-Type', 'application/json');
740740
$this->setHeader('Content-Length', (string) strlen($json));

system/HTTP/IncomingRequest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ public function getJsonVar(string $index, bool $assoc = false, ?int $filter = nu
362362

363363
if (! $assoc)
364364
{
365-
return json_decode(json_encode($data));
365+
// @phpstan-ignore-next-line
366+
return json_decode(json_encode($data, JSON_THROW_ON_ERROR), null, 512, JSON_THROW_ON_ERROR);
366367
}
367368

368369
return $data;
@@ -727,14 +728,14 @@ protected function parseRequestURI(): string
727728
if (isset($_SERVER['SCRIPT_NAME'][0]) && pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_EXTENSION) === 'php')
728729
{
729730
// strip the script name from the beginning of the URI
730-
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0 && strpos($uri, '/index.php') === 0)
731+
if (strpos($uri, (string) $_SERVER['SCRIPT_NAME']) === 0 && strpos($uri, '/index.php') === 0)
731732
{
732733
$uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME']));
733734
}
734735
// if the script is nested, strip the parent folder & script from the URI
735-
elseif (strpos($uri, $_SERVER['SCRIPT_NAME']) > 0)
736+
elseif (strpos($uri, (string) $_SERVER['SCRIPT_NAME']) > 0)
736737
{
737-
$uri = (string) substr($uri, strpos($uri, $_SERVER['SCRIPT_NAME']) + strlen($_SERVER['SCRIPT_NAME']));
738+
$uri = (string) substr($uri, strpos($uri, (string) $_SERVER['SCRIPT_NAME']) + strlen($_SERVER['SCRIPT_NAME']));
738739
}
739740
// or if index.php is implied
740741
elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)

system/HTTP/RequestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function getIPAddress(): string
115115
}
116116

117117
// If the proxy entry doesn't match the IP protocol - skip it
118-
if (strpos($proxyIP, $separator) === false)
118+
if (strpos($proxyIP, (string) $separator) === false)
119119
{
120120
continue;
121121
}

system/Log/Handlers/ChromeLoggerHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function sendLogs(ResponseInterface &$response = null)
177177
$response = Services::response(null, true);
178178
}
179179

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

182182
$response->setHeader($this->header, $data);
183183
}

system/Router/RouteCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ protected function fillRouteParams(string $from, array $params = null): string
13421342

13431343
// Ensure that the param we're inserting matches
13441344
// the expected param type.
1345-
$pos = strpos($from, $pattern);
1345+
$pos = strpos($from, (string) $pattern);
13461346
$from = substr_replace($from, $params[$index], $pos, strlen($pattern));
13471347
}
13481348

system/Security/Security.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public function verify(RequestInterface $request)
254254
{
255255
// We kill this since we're done and we don't want to pollute the JSON data.
256256
unset($json->{$this->tokenName});
257-
$request->setBody(json_encode($json));
257+
$request->setBody(json_encode($json, JSON_THROW_ON_ERROR));
258258
}
259259

260260
if ($this->regenerate)

system/Test/TestResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public function getJSON()
406406
*/
407407
public function assertJSONFragment(array $fragment, bool $strict = false)
408408
{
409-
$json = json_decode($this->getJSON(), true);
409+
$json = json_decode($this->getJSON(), true, 512, JSON_THROW_ON_ERROR);
410410
$patched = array_replace_recursive($json, $fragment);
411411

412412
if ($strict)

tests/system/EntityTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public function testCastAsJsonByFill()
543543

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

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

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

568568
// Check if unserialized
569569
$this->assertEquals([1, 2, 3], $entity->eleventh);
@@ -947,7 +947,7 @@ public function testJsonSerializableEntity()
947947
{
948948
$entity = $this->getEntity();
949949
$entity->setBar('foo');
950-
$this->assertEquals(json_encode($entity->toArray()), json_encode($entity));
950+
$this->assertEquals(json_encode($entity->toArray(), JSON_THROW_ON_ERROR), json_encode($entity, JSON_THROW_ON_ERROR));
951951
}
952952

953953
protected function getEntity() : Entity

tests/system/HTTP/CURLRequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ public function testJSONData()
923923

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

926-
$expected = json_encode($params);
926+
$expected = json_encode($params, JSON_THROW_ON_ERROR);
927927
$this->assertEquals($expected, $this->request->getBody());
928928
}
929929

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

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

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public function testCanGetAVariableFromJson()
308308
'fizz' => 'buzz',
309309
],
310310
];
311-
$json = json_encode($jsonObj);
311+
$json = json_encode($jsonObj, JSON_THROW_ON_ERROR);
312312

313313
$config = new App();
314314
$config->baseURL = 'http://example.com/';
@@ -330,7 +330,7 @@ public function testGetJsonVarAsArray()
330330
'foo' => 'bar',
331331
],
332332
];
333-
$json = json_encode($jsonObj);
333+
$json = json_encode($jsonObj, JSON_THROW_ON_ERROR);
334334

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

346346
public function testGetJsonVarCanFilter()
347347
{
348-
$json = json_encode(['foo' => 'bar']);
348+
$json = json_encode(['foo' => 'bar'], JSON_THROW_ON_ERROR);
349349

350350
$config = new App();
351351
$config->baseURL = 'http://example.com/';
@@ -361,7 +361,7 @@ public function testGetVarWorksWithJson()
361361
'foo' => 'bar',
362362
'fizz' => 'buzz',
363363
];
364-
$json = json_encode($jsonObj);
364+
$json = json_encode($jsonObj, JSON_THROW_ON_ERROR);
365365

366366
$config = new App();
367367
$config->baseURL = 'http://example.com/';

tests/system/Test/ControllerTestTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function testResponseOverriding()
205205
->controller(Popcorn::class)
206206
->execute('index3');
207207

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

tests/system/Test/FeatureTestTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public function testSetupRequestBodyWithParams()
353353

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

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

tests/system/Validation/ValidationTest.php

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public function testJsonInput()
467467
'role' => 'administrator',
468468
'usepass' => 0,
469469
];
470-
$json = json_encode($data);
470+
$json = json_encode($data, JSON_THROW_ON_ERROR);
471471

472472
$_SERVER['CONTENT_TYPE'] = 'application/json';
473473

@@ -955,8 +955,8 @@ public function testTranslatedLabelTagReplacement()
955955
* @see https://github.com/codeigniter4/CodeIgniter4/issues/4521
956956
*
957957
* @param boolean $expected
958-
* @param array $rules
959-
* @param array $data
958+
* @param array $rules
959+
* @param array $data
960960
*
961961
* @return void
962962
*/
@@ -969,55 +969,63 @@ public function testDotNotationOnIfExistRule(bool $expected, array $rules, array
969969
public function dotNotationForIfExistProvider()
970970
{
971971
yield 'dot-on-end-fail' => [
972-
false,
973-
['status.*' => 'if_exist|in_list[status_1,status_2]'],
974-
['status' => ['bad-status']],
975-
];
972+
false,
973+
['status.*' => 'if_exist|in_list[status_1,status_2]'],
974+
['status' => ['bad-status']],
975+
];
976976

977977
yield 'dot-on-end-pass' => [
978-
true,
979-
['status.*' => 'if_exist|in_list[status_1,status_2]'],
980-
['status' => ['status_1']],
981-
];
978+
true,
979+
['status.*' => 'if_exist|in_list[status_1,status_2]'],
980+
['status' => ['status_1']],
981+
];
982982

983983
yield 'dot-on-middle-fail' => [
984-
false,
985-
['fizz.*.baz' => 'if_exist|numeric'],
986-
['fizz' => [
987-
'bar' => ['baz' => 'yes'],
988-
]],
989-
];
984+
false,
985+
['fizz.*.baz' => 'if_exist|numeric'],
986+
[
987+
'fizz' => [
988+
'bar' => ['baz' => 'yes'],
989+
],
990+
],
991+
];
990992

991993
yield 'dot-on-middle-pass' => [
992-
true,
993-
['fizz.*.baz' => 'if_exist|numeric'],
994-
['fizz' => [
995-
'bar' => ['baz' => 30],
996-
]],
997-
];
994+
true,
995+
['fizz.*.baz' => 'if_exist|numeric'],
996+
[
997+
'fizz' => [
998+
'bar' => ['baz' => 30],
999+
],
1000+
],
1001+
];
9981002

9991003
yield 'dot-multiple-fail' => [
1000-
false,
1001-
['fizz.*.bar.*' => 'if_exist|numeric'],
1002-
['fizz' => [
1003-
'bos' => [
1004-
'bar' => [
1005-
'bub' => 'noo',
1006-
],
1007-
],
1008-
]],
1009-
];
1004+
false,
1005+
['fizz.*.bar.*' => 'if_exist|numeric'],
1006+
[
1007+
'fizz' => [
1008+
'bos' => [
1009+
'bar' => [
1010+
'bub' => 'noo',
1011+
],
1012+
],
1013+
],
1014+
],
1015+
];
10101016

10111017
yield 'dot-multiple-pass' => [
1012-
true,
1013-
['fizz.*.bar.*' => 'if_exist|numeric'],
1014-
['fizz' => [
1015-
'bos' => [
1016-
'bar' => [
1017-
'bub' => 5,
1018-
],
1019-
],
1020-
]],
1021-
];
1018+
true,
1019+
['fizz.*.bar.*' => 'if_exist|numeric'],
1020+
[
1021+
'fizz' => [
1022+
'bos' => [
1023+
'bar' => [
1024+
'bub' => 5,
1025+
],
1026+
],
1027+
],
1028+
],
1029+
];
10221030
}
10231031
}

0 commit comments

Comments
 (0)