From 31c5c141b97e0ac1c744f9675f0648ba4324684f Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 18 Dec 2023 17:32:15 +0900 Subject: [PATCH] refactor: replace empty() --- system/CodeIgniter.php | 9 ++++----- system/Validation/StrictRules/Rules.php | 6 ++++-- system/Validation/Validation.php | 6 +++--- system/Validation/Views/list.php | 2 +- system/View/Filters.php | 2 +- system/View/Parser.php | 10 +++++----- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 1dcf55d2fb..39a3029f39 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -848,11 +848,10 @@ class CodeIgniter */ protected function determinePath() { - if (isset($this->path)) { - return $this->path; - } - - return method_exists($this->request, 'getPath') ? $this->request->getPath() : $this->request->getUri()->getPath(); + return $this->path ?? + (method_exists($this->request, 'getPath') + ? $this->request->getPath() + : $this->request->getUri()->getPath()); } /** diff --git a/system/Validation/StrictRules/Rules.php b/system/Validation/StrictRules/Rules.php index 70d081975a..3086ca5a1d 100644 --- a/system/Validation/StrictRules/Rules.php +++ b/system/Validation/StrictRules/Rules.php @@ -157,7 +157,8 @@ class Rules ->limit(1); if ( - ! empty($whereField) && ! empty($whereValue) + $whereField !== null && $whereField !== '' + && $whereValue !== null && $whereValue !== '' && ! preg_match('/^\{(\w+)\}$/', $whereValue) ) { $row = $row->where($whereField, $whereValue); @@ -216,7 +217,8 @@ class Rules ->limit(1); if ( - ! empty($ignoreField) && ! empty($ignoreValue) + $ignoreField !== null && $ignoreField !== '' + && $ignoreValue !== null && $ignoreValue !== '' && ! preg_match('/^\{(\w+)\}$/', $ignoreValue) ) { $row = $row->where("{$ignoreField} !=", $ignoreValue); diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index 6e71aadb23..83bb361e70 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -148,7 +148,7 @@ class Validation implements ValidationInterface // If no rules exist, we return false to ensure // the developer didn't forget to set the rules. - if (empty($this->rules)) { + if ($this->rules === []) { return false; } @@ -707,7 +707,7 @@ class Validation implements ValidationInterface */ protected function loadRuleSets() { - if (empty($this->ruleSetFiles)) { + if ($this->ruleSetFiles === [] || $this->ruleSetFiles === null) { throw ValidationException::forNoRuleSets(); } @@ -918,7 +918,7 @@ class Validation implements ValidationInterface $message = str_replace('{field}', ($label === null || $label === '') ? $field : lang($label), $message); $message = str_replace( '{param}', - empty($this->rules[$param]['label']) ? $param : lang($this->rules[$param]['label']), + (! isset($this->rules[$param]['label'])) ? $param : lang($this->rules[$param]['label']), $message ); diff --git a/system/Validation/Views/list.php b/system/Validation/Views/list.php index cc95156cd5..3669f038e8 100644 --- a/system/Validation/Views/list.php +++ b/system/Validation/Views/list.php @@ -1,4 +1,4 @@ - +