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

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Dec 18, 2023

Needs #8344

Description

  • replace empty()

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis marked this pull request as draft December 18, 2023 07:13
@kenjis kenjis force-pushed the replace-empty branch 4 times, most recently from 102b20c to c666bf7 Compare December 19, 2023 03:04
@github-actions github-actions bot added the stale Pull requests with conflicts label Dec 21, 2023
Copy link

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@kenjis kenjis added refactor Pull requests that refactor code and removed stale Pull requests with conflicts labels Dec 21, 2023
@kenjis kenjis changed the title refactor: replace empty() refactor: replace empty() Part 1 Dec 22, 2023
@kenjis kenjis marked this pull request as ready for review December 22, 2023 10:58
@github-actions github-actions bot added the stale Pull requests with conflicts label Dec 25, 2023
Copy link

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@kenjis kenjis removed the stale Pull requests with conflicts label Dec 25, 2023
@@ -257,13 +257,13 @@ protected function doFirst()

if ($this->tempUseSoftDeletes) {
$builder->where($this->table . '.' . $this->deletedField, null);
} elseif ($this->useSoftDeletes && empty($builder->QBGroupBy) && $this->primaryKey) {
} elseif ($this->useSoftDeletes && ($builder->QBGroupBy === []) && $this->primaryKey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is () around $builder->QBGroupBy === [] is forced by our tooling? Seems unnecessary.

$builder->groupBy($this->table . '.' . $this->primaryKey);
}

// Some databases, like PostgreSQL, need order
// information to consistently return correct results.
if ($builder->QBGroupBy && empty($builder->QBOrderBy) && $this->primaryKey) {
if ($builder->QBGroupBy && ($builder->QBOrderBy === []) && $this->primaryKey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@@ -186,7 +186,7 @@ public function call(string $method, string $path, ?array $params = null)
->run($routes, true);

$output = \ob_get_contents();
if (empty($response->getBody()) && ! ($output === '' || $output === false)) {
if (($response->getBody() === null) && ! ($output === '' || $output === false)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably unnecessary () around $response->getBody() === null.

@@ -918,7 +918,7 @@ protected function getErrorMessage(
$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']),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need () around ! isset($this->rules[$param]['label'])?

@@ -103,7 +103,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
}

$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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here... is it supposed to increase readability? For me, it's the opposite.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, yes.

@@ -589,7 +589,7 @@ protected function applyFilters(string $replace, array $filters): string
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With only one check, I see no added value in using ().

@@ -178,7 +178,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n

$fileExt = pathinfo($view, PATHINFO_EXTENSION);
// allow Views as .html, .tpl, etc (from CI3)
$this->renderVars['view'] = empty($fileExt) ? $view . '.php' : $view;
$this->renderVars['view'] = ($fileExt === '') ? $view . '.php' : $view;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -207,12 +207,12 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
$this->renderVars['file'] = $this->loader->locateFile(
$this->renderVars['view'],
'Views',
empty($fileExt) ? 'php' : $fileExt
($fileExt === '') ? 'php' : $fileExt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments, but it may be only my preference.

@kenjis
Copy link
Member Author

kenjis commented Dec 28, 2023

There are some unnecessary (), but I merge this for now.

@kenjis kenjis merged commit 838900e into codeigniter4:develop Dec 28, 2023
61 checks passed
@kenjis kenjis deleted the replace-empty branch December 28, 2023 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Pull requests that refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants