Skip to content
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

refactor: replace empty() Part 1 #8345

Merged
merged 10 commits into from
Dec 28, 2023
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/test-phpcpd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ jobs:
--exclude system/Database/Postgre/Builder.php
--exclude system/Debug/Exceptions.php
--exclude system/HTTP/SiteURI.php
--exclude system/Validation/Rules.php
-- app/ public/ system/
6 changes: 3 additions & 3 deletions app/Config/Kint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Kint extends BaseConfig
*/

/**
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>|null
*/
public $plugins;

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

/**
* @var array<string, class-string<ValuePluginInterface>>
* @var array<string, class-string<ValuePluginInterface>>|null
*/
public $richObjectPlugins;

/**
* @var array<string, class-string<TabPluginInterface>>
* @var array<string, class-string<TabPluginInterface>>|null
*/
public $richTabPlugins;

Expand Down
135 changes: 0 additions & 135 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, int\\|string given\\.$#',
'count' => 1,
Expand All @@ -31,11 +26,6 @@
'count' => 6,
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 8,
'path' => __DIR__ . '/system/BaseModel.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#',
'count' => 1,
Expand Down Expand Up @@ -161,11 +151,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Cache/Handlers/PredisHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 6,
'path' => __DIR__ . '/system/CodeIgniter.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
Expand Down Expand Up @@ -1721,16 +1706,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Debug/BaseExceptionHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Debug/ExceptionHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Debug/Exceptions.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 5,
Expand Down Expand Up @@ -2466,11 +2441,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Log/Logger.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 15,
'path' => __DIR__ . '/system/Model.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Model\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#',
'count' => 1,
Expand Down Expand Up @@ -2546,11 +2516,6 @@
'count' => 1,
'path' => __DIR__ . '/system/RESTful/BaseResource.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/RESTful/ResourceController.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, string\\|null given\\.$#',
'count' => 1,
Expand Down Expand Up @@ -2886,11 +2851,6 @@
'count' => 2,
'path' => __DIR__ . '/system/Session/Session.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 9,
'path' => __DIR__ . '/system/Session/Session.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Session\\\\Session\\:\\:configure\\(\\) has no return type specified\\.$#',
'count' => 1,
Expand Down Expand Up @@ -3041,11 +3001,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Session/SessionInterface.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 4,
'path' => __DIR__ . '/system/Test/CIDatabaseTestCase.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Test\\\\CIDatabaseTestCase\\:\\:clearInsertCache\\(\\) has no return type specified\\.$#',
'count' => 1,
Expand Down Expand Up @@ -3171,26 +3126,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/DOMParser.php',
];
$ignoreErrors[] = [
'message' => '#^Access to an undefined property object\\:\\:\\$createdField\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/Fabricator.php',
];
$ignoreErrors[] = [
'message' => '#^Access to an undefined property object\\:\\:\\$deletedField\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/Fabricator.php',
];
$ignoreErrors[] = [
'message' => '#^Access to an undefined property object\\:\\:\\$updatedField\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/Fabricator.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 5,
'path' => __DIR__ . '/system/Test/Fabricator.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Test\\\\Fabricator\\:\\:resetCounts\\(\\) has no return type specified\\.$#',
'count' => 1,
Expand All @@ -3211,11 +3146,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/FeatureTestCase.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 5,
'path' => __DIR__ . '/system/Test/FeatureTestCase.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Test\\\\FeatureTestCase\\:\\:clearInsertCache\\(\\) has no return type specified\\.$#',
'count' => 1,
Expand Down Expand Up @@ -3341,11 +3271,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/Mock/MockCURLRequest.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'path' => __DIR__ . '/system/Test/Mock/MockCache.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockCache\\:\\:assertHas\\(\\) has no return type specified\\.$#',
'count' => 1,
Expand Down Expand Up @@ -3381,11 +3306,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:_close\\(\\) should return mixed but return statement is missing\\.$#',
'count' => 1,
Expand Down Expand Up @@ -3496,11 +3416,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/Mock/MockResourceController.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/Mock/MockResourcePresenter.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockResourcePresenter\\:\\:getFormat\\(\\) has no return type specified\\.$#',
'count' => 1,
Expand Down Expand Up @@ -3621,11 +3536,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/TestLogger.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/TestResponse.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Test\\\\TestResponse\\:\\:__call\\(\\) should return mixed but return statement is missing\\.$#',
'count' => 1,
Expand Down Expand Up @@ -3741,31 +3651,11 @@
'count' => 1,
'path' => __DIR__ . '/system/Throttle/Throttler.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Validation/CreditCardRules.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, array\\|null given\\.$#',
'count' => 6,
'path' => __DIR__ . '/system/Validation/FileRules.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 8,
'path' => __DIR__ . '/system/Validation/Rules.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 4,
'path' => __DIR__ . '/system/Validation/StrictRules/Rules.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'path' => __DIR__ . '/system/Validation/Validation.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Validation\\\\Validation\\:\\:isClosure\\(\\) has parameter \\$rule with no signature specified for Closure\\.$#',
'count' => 1,
Expand All @@ -3776,36 +3666,16 @@
'count' => 2,
'path' => __DIR__ . '/system/Validation/Validation.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Validation/Views/list.php',
];
$ignoreErrors[] = [
'message' => '#^Call to an undefined static method CodeIgniter\\\\Config\\\\Factories\\:\\:cells\\(\\)\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/View/Cell.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/View/Filters.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 4,
'path' => __DIR__ . '/system/View/Parser.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\View\\\\Parser\\:\\:addPlugin\\(\\) has parameter \\$callback with no signature specified for callable\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/View/Parser.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 7,
'path' => __DIR__ . '/system/View/Table.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a ternary operator condition, float given\\.$#',
'count' => 1,
Expand All @@ -3821,11 +3691,6 @@
'count' => 1,
'path' => __DIR__ . '/system/View/Table.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'path' => __DIR__ . '/system/View/View.php',
];
$ignoreErrors[] = [
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
'count' => 2,
Expand Down
2 changes: 1 addition & 1 deletion system/API/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ protected function format($data = null)

// Determine correct response type through content negotiation if not explicitly declared
if (
(empty($this->format) || ! in_array($this->format, ['json', 'xml'], true))
! in_array($this->format, ['json', 'xml'], true)
&& $this->request instanceof IncomingRequest
) {
$mime = $this->request->negotiate(
Expand Down
6 changes: 3 additions & 3 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
$segments = explode('\\', $file);

// The first segment will be empty if a slash started the filename.
if (empty($segments[0])) {
if ($segments[0] === '') {
unset($segments[0]);
}

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

// if no namespaces matched then quit
if (empty($paths)) {
if ($paths === []) {
return false;
}

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

if (empty($namespace['path'])) {
if ($namespace['path'] === '') {
continue;
}

Expand Down
Loading
Loading