Skip to content

Commit 838900e

Browse files
authored
Merge pull request #8345 from kenjis/replace-empty
refactor: replace empty() Part 1
2 parents 54d188b + 269986e commit 838900e

26 files changed

+112
-235
lines changed

.github/workflows/test-phpcpd.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ jobs:
5656
--exclude system/Database/Postgre/Builder.php
5757
--exclude system/Debug/Exceptions.php
5858
--exclude system/HTTP/SiteURI.php
59+
--exclude system/Validation/Rules.php
5960
-- app/ public/ system/

app/Config/Kint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Kint extends BaseConfig
2727
*/
2828

2929
/**
30-
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>
30+
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>|null
3131
*/
3232
public $plugins;
3333

@@ -45,12 +45,12 @@ class Kint extends BaseConfig
4545
public int $richSort = AbstractRenderer::SORT_FULL;
4646

4747
/**
48-
* @var array<string, class-string<ValuePluginInterface>>
48+
* @var array<string, class-string<ValuePluginInterface>>|null
4949
*/
5050
public $richObjectPlugins;
5151

5252
/**
53-
* @var array<string, class-string<TabPluginInterface>>
53+
* @var array<string, class-string<TabPluginInterface>>|null
5454
*/
5555
public $richTabPlugins;
5656

phpstan-baseline.php

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
'count' => 1,
1717
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
1818
];
19-
$ignoreErrors[] = [
20-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
21-
'count' => 3,
22-
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
23-
];
2419
$ignoreErrors[] = [
2520
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\|string given\\.$#',
2621
'count' => 1,
@@ -31,11 +26,6 @@
3126
'count' => 6,
3227
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
3328
];
34-
$ignoreErrors[] = [
35-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
36-
'count' => 8,
37-
'path' => __DIR__ . '/system/BaseModel.php',
38-
];
3929
$ignoreErrors[] = [
4030
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#',
4131
'count' => 1,
@@ -161,11 +151,6 @@
161151
'count' => 1,
162152
'path' => __DIR__ . '/system/Cache/Handlers/PredisHandler.php',
163153
];
164-
$ignoreErrors[] = [
165-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
166-
'count' => 6,
167-
'path' => __DIR__ . '/system/CodeIgniter.php',
168-
];
169154
$ignoreErrors[] = [
170155
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
171156
'count' => 1,
@@ -1721,16 +1706,6 @@
17211706
'count' => 1,
17221707
'path' => __DIR__ . '/system/Debug/BaseExceptionHandler.php',
17231708
];
1724-
$ignoreErrors[] = [
1725-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
1726-
'count' => 1,
1727-
'path' => __DIR__ . '/system/Debug/ExceptionHandler.php',
1728-
];
1729-
$ignoreErrors[] = [
1730-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
1731-
'count' => 1,
1732-
'path' => __DIR__ . '/system/Debug/Exceptions.php',
1733-
];
17341709
$ignoreErrors[] = [
17351710
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
17361711
'count' => 5,
@@ -2466,11 +2441,6 @@
24662441
'count' => 1,
24672442
'path' => __DIR__ . '/system/Log/Logger.php',
24682443
];
2469-
$ignoreErrors[] = [
2470-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
2471-
'count' => 15,
2472-
'path' => __DIR__ . '/system/Model.php',
2473-
];
24742444
$ignoreErrors[] = [
24752445
'message' => '#^Method CodeIgniter\\\\Model\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#',
24762446
'count' => 1,
@@ -2546,11 +2516,6 @@
25462516
'count' => 1,
25472517
'path' => __DIR__ . '/system/RESTful/BaseResource.php',
25482518
];
2549-
$ignoreErrors[] = [
2550-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
2551-
'count' => 1,
2552-
'path' => __DIR__ . '/system/RESTful/ResourceController.php',
2553-
];
25542519
$ignoreErrors[] = [
25552520
'message' => '#^Only booleans are allowed in a ternary operator condition, string\\|null given\\.$#',
25562521
'count' => 1,
@@ -2886,11 +2851,6 @@
28862851
'count' => 2,
28872852
'path' => __DIR__ . '/system/Session/Session.php',
28882853
];
2889-
$ignoreErrors[] = [
2890-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
2891-
'count' => 9,
2892-
'path' => __DIR__ . '/system/Session/Session.php',
2893-
];
28942854
$ignoreErrors[] = [
28952855
'message' => '#^Method CodeIgniter\\\\Session\\\\Session\\:\\:configure\\(\\) has no return type specified\\.$#',
28962856
'count' => 1,
@@ -3041,11 +3001,6 @@
30413001
'count' => 1,
30423002
'path' => __DIR__ . '/system/Session/SessionInterface.php',
30433003
];
3044-
$ignoreErrors[] = [
3045-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3046-
'count' => 4,
3047-
'path' => __DIR__ . '/system/Test/CIDatabaseTestCase.php',
3048-
];
30493004
$ignoreErrors[] = [
30503005
'message' => '#^Method CodeIgniter\\\\Test\\\\CIDatabaseTestCase\\:\\:clearInsertCache\\(\\) has no return type specified\\.$#',
30513006
'count' => 1,
@@ -3171,26 +3126,6 @@
31713126
'count' => 1,
31723127
'path' => __DIR__ . '/system/Test/DOMParser.php',
31733128
];
3174-
$ignoreErrors[] = [
3175-
'message' => '#^Access to an undefined property object\\:\\:\\$createdField\\.$#',
3176-
'count' => 1,
3177-
'path' => __DIR__ . '/system/Test/Fabricator.php',
3178-
];
3179-
$ignoreErrors[] = [
3180-
'message' => '#^Access to an undefined property object\\:\\:\\$deletedField\\.$#',
3181-
'count' => 1,
3182-
'path' => __DIR__ . '/system/Test/Fabricator.php',
3183-
];
3184-
$ignoreErrors[] = [
3185-
'message' => '#^Access to an undefined property object\\:\\:\\$updatedField\\.$#',
3186-
'count' => 1,
3187-
'path' => __DIR__ . '/system/Test/Fabricator.php',
3188-
];
3189-
$ignoreErrors[] = [
3190-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3191-
'count' => 5,
3192-
'path' => __DIR__ . '/system/Test/Fabricator.php',
3193-
];
31943129
$ignoreErrors[] = [
31953130
'message' => '#^Method CodeIgniter\\\\Test\\\\Fabricator\\:\\:resetCounts\\(\\) has no return type specified\\.$#',
31963131
'count' => 1,
@@ -3211,11 +3146,6 @@
32113146
'count' => 1,
32123147
'path' => __DIR__ . '/system/Test/FeatureTestCase.php',
32133148
];
3214-
$ignoreErrors[] = [
3215-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3216-
'count' => 5,
3217-
'path' => __DIR__ . '/system/Test/FeatureTestCase.php',
3218-
];
32193149
$ignoreErrors[] = [
32203150
'message' => '#^Method CodeIgniter\\\\Test\\\\FeatureTestCase\\:\\:clearInsertCache\\(\\) has no return type specified\\.$#',
32213151
'count' => 1,
@@ -3341,11 +3271,6 @@
33413271
'count' => 1,
33423272
'path' => __DIR__ . '/system/Test/Mock/MockCURLRequest.php',
33433273
];
3344-
$ignoreErrors[] = [
3345-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3346-
'count' => 3,
3347-
'path' => __DIR__ . '/system/Test/Mock/MockCache.php',
3348-
];
33493274
$ignoreErrors[] = [
33503275
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockCache\\:\\:assertHas\\(\\) has no return type specified\\.$#',
33513276
'count' => 1,
@@ -3381,11 +3306,6 @@
33813306
'count' => 1,
33823307
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
33833308
];
3384-
$ignoreErrors[] = [
3385-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3386-
'count' => 2,
3387-
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
3388-
];
33893309
$ignoreErrors[] = [
33903310
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:_close\\(\\) should return mixed but return statement is missing\\.$#',
33913311
'count' => 1,
@@ -3496,11 +3416,6 @@
34963416
'count' => 1,
34973417
'path' => __DIR__ . '/system/Test/Mock/MockResourceController.php',
34983418
];
3499-
$ignoreErrors[] = [
3500-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3501-
'count' => 1,
3502-
'path' => __DIR__ . '/system/Test/Mock/MockResourcePresenter.php',
3503-
];
35043419
$ignoreErrors[] = [
35053420
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockResourcePresenter\\:\\:getFormat\\(\\) has no return type specified\\.$#',
35063421
'count' => 1,
@@ -3621,11 +3536,6 @@
36213536
'count' => 1,
36223537
'path' => __DIR__ . '/system/Test/TestLogger.php',
36233538
];
3624-
$ignoreErrors[] = [
3625-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3626-
'count' => 1,
3627-
'path' => __DIR__ . '/system/Test/TestResponse.php',
3628-
];
36293539
$ignoreErrors[] = [
36303540
'message' => '#^Method CodeIgniter\\\\Test\\\\TestResponse\\:\\:__call\\(\\) should return mixed but return statement is missing\\.$#',
36313541
'count' => 1,
@@ -3741,31 +3651,11 @@
37413651
'count' => 1,
37423652
'path' => __DIR__ . '/system/Throttle/Throttler.php',
37433653
];
3744-
$ignoreErrors[] = [
3745-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3746-
'count' => 1,
3747-
'path' => __DIR__ . '/system/Validation/CreditCardRules.php',
3748-
];
37493654
$ignoreErrors[] = [
37503655
'message' => '#^Only booleans are allowed in a negated boolean, array\\|null given\\.$#',
37513656
'count' => 6,
37523657
'path' => __DIR__ . '/system/Validation/FileRules.php',
37533658
];
3754-
$ignoreErrors[] = [
3755-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3756-
'count' => 8,
3757-
'path' => __DIR__ . '/system/Validation/Rules.php',
3758-
];
3759-
$ignoreErrors[] = [
3760-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3761-
'count' => 4,
3762-
'path' => __DIR__ . '/system/Validation/StrictRules/Rules.php',
3763-
];
3764-
$ignoreErrors[] = [
3765-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3766-
'count' => 3,
3767-
'path' => __DIR__ . '/system/Validation/Validation.php',
3768-
];
37693659
$ignoreErrors[] = [
37703660
'message' => '#^Method CodeIgniter\\\\Validation\\\\Validation\\:\\:isClosure\\(\\) has parameter \\$rule with no signature specified for Closure\\.$#',
37713661
'count' => 1,
@@ -3776,36 +3666,16 @@
37763666
'count' => 2,
37773667
'path' => __DIR__ . '/system/Validation/Validation.php',
37783668
];
3779-
$ignoreErrors[] = [
3780-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3781-
'count' => 1,
3782-
'path' => __DIR__ . '/system/Validation/Views/list.php',
3783-
];
37843669
$ignoreErrors[] = [
37853670
'message' => '#^Call to an undefined static method CodeIgniter\\\\Config\\\\Factories\\:\\:cells\\(\\)\\.$#',
37863671
'count' => 1,
37873672
'path' => __DIR__ . '/system/View/Cell.php',
37883673
];
3789-
$ignoreErrors[] = [
3790-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3791-
'count' => 1,
3792-
'path' => __DIR__ . '/system/View/Filters.php',
3793-
];
3794-
$ignoreErrors[] = [
3795-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3796-
'count' => 4,
3797-
'path' => __DIR__ . '/system/View/Parser.php',
3798-
];
37993674
$ignoreErrors[] = [
38003675
'message' => '#^Method CodeIgniter\\\\View\\\\Parser\\:\\:addPlugin\\(\\) has parameter \\$callback with no signature specified for callable\\.$#',
38013676
'count' => 1,
38023677
'path' => __DIR__ . '/system/View/Parser.php',
38033678
];
3804-
$ignoreErrors[] = [
3805-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3806-
'count' => 7,
3807-
'path' => __DIR__ . '/system/View/Table.php',
3808-
];
38093679
$ignoreErrors[] = [
38103680
'message' => '#^Only booleans are allowed in a ternary operator condition, float given\\.$#',
38113681
'count' => 1,
@@ -3821,11 +3691,6 @@
38213691
'count' => 1,
38223692
'path' => __DIR__ . '/system/View/Table.php',
38233693
];
3824-
$ignoreErrors[] = [
3825-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3826-
'count' => 3,
3827-
'path' => __DIR__ . '/system/View/View.php',
3828-
];
38293694
$ignoreErrors[] = [
38303695
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
38313696
'count' => 2,

system/API/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ protected function format($data = null)
318318

319319
// Determine correct response type through content negotiation if not explicitly declared
320320
if (
321-
(empty($this->format) || ! in_array($this->format, ['json', 'xml'], true))
321+
! in_array($this->format, ['json', 'xml'], true)
322322
&& $this->request instanceof IncomingRequest
323323
) {
324324
$mime = $this->request->negotiate(

system/Autoloader/FileLocator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
6767
$segments = explode('\\', $file);
6868

6969
// The first segment will be empty if a slash started the filename.
70-
if (empty($segments[0])) {
70+
if ($segments[0] === '') {
7171
unset($segments[0]);
7272
}
7373

@@ -89,7 +89,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
8989
}
9090

9191
// if no namespaces matched then quit
92-
if (empty($paths)) {
92+
if ($paths === []) {
9393
return false;
9494
}
9595

@@ -272,7 +272,7 @@ public function findQualifiedNameFromPath(string $path)
272272
foreach ($this->getNamespaces() as $namespace) {
273273
$namespace['path'] = realpath($namespace['path']) ?: $namespace['path'];
274274

275-
if (empty($namespace['path'])) {
275+
if ($namespace['path'] === '') {
276276
continue;
277277
}
278278

0 commit comments

Comments
 (0)