Skip to content

Commit 4a76cb3

Browse files
committed
refactor: replace empty()
1 parent 69d67b1 commit 4a76cb3

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

system/CodeIgniter.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,10 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
848848
*/
849849
protected function determinePath()
850850
{
851-
if (isset($this->path)) {
852-
return $this->path;
853-
}
854-
855-
return method_exists($this->request, 'getPath') ? $this->request->getPath() : $this->request->getUri()->getPath();
851+
return $this->path ??
852+
(method_exists($this->request, 'getPath')
853+
? $this->request->getPath()
854+
: $this->request->getUri()->getPath());
856855
}
857856

858857
/**

system/Validation/StrictRules/Rules.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ public function is_not_unique($str, string $field, array $data): bool
157157
->limit(1);
158158

159159
if (
160-
! empty($whereField) && ! empty($whereValue)
160+
$whereField !== null && $whereField !== ''
161+
&& $whereValue !== null && $whereValue !== ''
161162
&& ! preg_match('/^\{(\w+)\}$/', $whereValue)
162163
) {
163164
$row = $row->where($whereField, $whereValue);
@@ -216,7 +217,8 @@ public function is_unique($str, string $field, array $data): bool
216217
->limit(1);
217218

218219
if (
219-
! empty($ignoreField) && ! empty($ignoreValue)
220+
$ignoreField !== null && $ignoreField !== ''
221+
&& $ignoreValue !== null && $ignoreValue !== ''
220222
&& ! preg_match('/^\{(\w+)\}$/', $ignoreValue)
221223
) {
222224
$row = $row->where("{$ignoreField} !=", $ignoreValue);

system/Validation/Validation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup
148148

149149
// If no rules exist, we return false to ensure
150150
// the developer didn't forget to set the rules.
151-
if (empty($this->rules)) {
151+
if ($this->rules === []) {
152152
return false;
153153
}
154154

@@ -707,7 +707,7 @@ public function showError(string $field, string $template = 'single'): string
707707
*/
708708
protected function loadRuleSets()
709709
{
710-
if (empty($this->ruleSetFiles)) {
710+
if ($this->ruleSetFiles === [] || $this->ruleSetFiles === null) {
711711
throw ValidationException::forNoRuleSets();
712712
}
713713

@@ -918,7 +918,7 @@ protected function getErrorMessage(
918918
$message = str_replace('{field}', ($label === null || $label === '') ? $field : lang($label), $message);
919919
$message = str_replace(
920920
'{param}',
921-
empty($this->rules[$param]['label']) ? $param : lang($this->rules[$param]['label']),
921+
(! isset($this->rules[$param]['label'])) ? $param : lang($this->rules[$param]['label']),
922922
$message
923923
);
924924

system/Validation/Views/list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php if (! empty($errors)) : ?>
1+
<?php if (isset($errors) && $errors !== []) : ?>
22
<div class="errors" role="alert">
33
<ul>
44
<?php foreach ($errors as $error) : ?>

system/View/Filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function date_modify($value, string $adjustment)
6666
*/
6767
public static function default($value, string $default): string
6868
{
69-
return empty($value)
69+
return empty($value) // @phpstan-ignore-line
7070
? $default
7171
: $value;
7272
}

system/View/Parser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
103103
}
104104

105105
$fileExt = pathinfo($view, PATHINFO_EXTENSION);
106-
$view = empty($fileExt) ? $view . '.php' : $view; // allow Views as .html, .tpl, etc (from CI3)
106+
$view = ($fileExt === '') ? $view . '.php' : $view; // allow Views as .html, .tpl, etc (from CI3)
107107

108108
$cacheName = $options['cache_name'] ?? str_replace('.php', '', $view);
109109

@@ -120,8 +120,8 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
120120
$fileOrig = $file;
121121
$file = $this->loader->locateFile($view, 'Views');
122122

123-
// locateFile will return an empty string if the file cannot be found.
124-
if (empty($file)) {
123+
// locateFile() will return false if the file cannot be found.
124+
if ($file === false) {
125125
throw ViewException::forInvalidFile($fileOrig);
126126
}
127127
}
@@ -534,7 +534,7 @@ protected function prepareReplacement(array $matches, string $replace, bool $esc
534534

535535
// Our regex earlier will leave all chained values on a single line
536536
// so we need to break them apart so we can apply them all.
537-
$filters = ! empty($matches[1]) ? explode('|', $matches[1]) : [];
537+
$filters = (isset($matches[1]) && $matches[1] !== '') ? explode('|', $matches[1]) : [];
538538

539539
if ($escape && $filters === [] && ($context = $this->shouldAddEscaping($orig))) {
540540
$filters[] = "esc({$context})";
@@ -589,7 +589,7 @@ protected function applyFilters(string $replace, array $filters): string
589589
preg_match('/\([\w<>=\/\\\,:.\-\s\+]+\)/u', $filter, $param);
590590

591591
// Remove the () and spaces to we have just the parameter left
592-
$param = ! empty($param) ? trim($param[0], '() ') : null;
592+
$param = ($param !== []) ? trim($param[0], '() ') : null;
593593

594594
// Params can be separated by commas to allow multiple parameters for the filter
595595
if ($param !== null && $param !== '') {

0 commit comments

Comments
 (0)