mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
refactor: replace empty()
This commit is contained in:
parent
d7587744c0
commit
31c5c141b9
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php if (! empty($errors)) : ?>
|
||||
<?php if (isset($errors) && $errors !== []) : ?>
|
||||
<div class="errors" role="alert">
|
||||
<ul>
|
||||
<?php foreach ($errors as $error) : ?>
|
||||
|
@ -66,7 +66,7 @@ class Filters
|
||||
*/
|
||||
public static function default($value, string $default): string
|
||||
{
|
||||
return empty($value)
|
||||
return empty($value) // @phpstan-ignore-line
|
||||
? $default
|
||||
: $value;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ class Parser extends View
|
||||
}
|
||||
|
||||
$fileExt = pathinfo($view, PATHINFO_EXTENSION);
|
||||
$view = empty($fileExt) ? $view . '.php' : $view; // allow Views as .html, .tpl, etc (from CI3)
|
||||
$view = ($fileExt === '') ? $view . '.php' : $view; // allow Views as .html, .tpl, etc (from CI3)
|
||||
|
||||
$cacheName = $options['cache_name'] ?? str_replace('.php', '', $view);
|
||||
|
||||
@ -120,8 +120,8 @@ class Parser extends View
|
||||
$fileOrig = $file;
|
||||
$file = $this->loader->locateFile($view, 'Views');
|
||||
|
||||
// locateFile will return an empty string if the file cannot be found.
|
||||
if (empty($file)) {
|
||||
// locateFile() will return false if the file cannot be found.
|
||||
if ($file === false) {
|
||||
throw ViewException::forInvalidFile($fileOrig);
|
||||
}
|
||||
}
|
||||
@ -534,7 +534,7 @@ class Parser extends View
|
||||
|
||||
// Our regex earlier will leave all chained values on a single line
|
||||
// so we need to break them apart so we can apply them all.
|
||||
$filters = ! empty($matches[1]) ? explode('|', $matches[1]) : [];
|
||||
$filters = (isset($matches[1]) && $matches[1] !== '') ? explode('|', $matches[1]) : [];
|
||||
|
||||
if ($escape && $filters === [] && ($context = $this->shouldAddEscaping($orig))) {
|
||||
$filters[] = "esc({$context})";
|
||||
@ -589,7 +589,7 @@ class Parser extends View
|
||||
preg_match('/\([\w<>=\/\\\,:.\-\s\+]+\)/u', $filter, $param);
|
||||
|
||||
// Remove the () and spaces to we have just the parameter left
|
||||
$param = ! empty($param) ? trim($param[0], '() ') : null;
|
||||
$param = ($param !== []) ? trim($param[0], '() ') : null;
|
||||
|
||||
// Params can be separated by commas to allow multiple parameters for the filter
|
||||
if ($param !== null && $param !== '') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user