-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: fix phpstan
only boolean allowed
#9302
base: develop
Are you sure you want to change the base?
Changes from all commits
9622469
40c1821
a98b86a
e70ba25
0b85e5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,7 +289,7 @@ function csrf_hash(): string | |
*/ | ||
function csrf_field(?string $id = null): string | ||
{ | ||
return '<input type="hidden"' . ($id !== null ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_token() . '" value="' . csrf_hash() . '"' . _solidus() . '>'; | ||
return '<input type="hidden"' . ((string) $id !== '' ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_token() . '" value="' . csrf_hash() . '"' . _solidus() . '>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we changing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because an empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How often we will set an empty string as a parameter here? Probably never. It's already not very readable and with added typing it becomes even less. The world will not end if we escape the empty string. I admit that this may just be my preference, but using typing everywhere makes the code less clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why I've spoken out about rejecting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, you can skip the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "problem" is that an empty string is an edge case, not something we will experience regularly. But casting to string will be made much more often + readability issues.
I don't get what you're referring to here. And no, Does PHPStan or Rector have anything against checking that the value is not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to allow breaking changes? |
||
} | ||
} | ||
|
||
|
@@ -301,7 +301,7 @@ function csrf_field(?string $id = null): string | |
*/ | ||
function csrf_meta(?string $id = null): string | ||
{ | ||
return '<meta' . ($id !== null ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_header() . '" content="' . csrf_hash() . '"' . _solidus() . '>'; | ||
return '<meta' . ((string) $id !== '' ? ' id="' . esc($id, 'attr') . '"' : '') . ' name="' . csrf_header() . '" content="' . csrf_hash() . '"' . _solidus() . '>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we changing this? |
||
} | ||
} | ||
|
||
|
@@ -441,7 +441,7 @@ function esc($data, string $context = 'html', ?string $encoding = null) | |
$escaper = new Escaper($encoding); | ||
} | ||
|
||
if ($encoding && $escaper->getEncoding() !== $encoding) { | ||
if ((string) $encoding !== '' && $escaper->getEncoding() !== $encoding) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not |
||
$escaper = new Escaper($encoding); | ||
} | ||
|
||
|
@@ -739,13 +739,13 @@ function lang(string $line, array $args = [], ?string $locale = null) | |
// Get active locale | ||
$activeLocale = $language->getLocale(); | ||
|
||
if ($locale && $locale !== $activeLocale) { | ||
if ((string) $locale !== '' && $locale !== $activeLocale) { | ||
$language->setLocale($locale); | ||
} | ||
|
||
$lines = $language->getLine($line, $args); | ||
|
||
if ($locale && $locale !== $activeLocale) { | ||
if ((string) $locale !== '' && $locale !== $activeLocale) { | ||
// Reset to active locale | ||
$language->setLocale($activeLocale); | ||
} | ||
|
@@ -849,7 +849,7 @@ function redirect(?string $route = null): RedirectResponse | |
{ | ||
$response = service('redirectresponse'); | ||
|
||
if ($route !== null) { | ||
if ((string) $route !== '') { | ||
return $response->route($route); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,7 +161,7 @@ public function latest(?string $group = null) | |
|
||
$this->ensureTable(); | ||
|
||
if ($group !== null) { | ||
if ((string) $group !== '') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is wrong with |
||
$this->groupFilter = $group; | ||
$this->setGroup($group); | ||
} | ||
|
@@ -326,7 +326,7 @@ public function force(string $path, string $namespace, ?string $group = null) | |
|
||
$this->ensureTable(); | ||
|
||
if ($group !== null) { | ||
if ((string) $group !== '') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is wrong with |
||
$this->groupFilter = $group; | ||
$this->setGroup($group); | ||
} | ||
|
@@ -389,7 +389,7 @@ public function force(string $path, string $namespace, ?string $group = null) | |
*/ | ||
public function findMigrations(): array | ||
{ | ||
$namespaces = $this->namespace ? [$this->namespace] : array_keys(service('autoloader')->getNamespace()); | ||
$namespaces = $this->namespace !== null ? [$this->namespace] : array_keys(service('autoloader')->getNamespace()); | ||
$migrations = []; | ||
|
||
foreach ($namespaces as $namespace) { | ||
|
@@ -524,7 +524,7 @@ protected function getMigrationNumber(string $migration): string | |
{ | ||
preg_match($this->regex, $migration, $matches); | ||
|
||
return count($matches) ? $matches[1] : '0'; | ||
return $matches !== [] ? $matches[1] : '0'; | ||
} | ||
|
||
/** | ||
|
@@ -539,7 +539,7 @@ protected function getMigrationName(string $migration): string | |
{ | ||
preg_match($this->regex, $migration, $matches); | ||
|
||
return count($matches) ? $matches[2] : ''; | ||
return $matches !== [] ? $matches[2] : ''; | ||
} | ||
|
||
/** | ||
|
@@ -645,7 +645,7 @@ public function getHistory(string $group = 'default'): array | |
} | ||
|
||
// If a namespace was specified then use it | ||
if ($this->namespace) { | ||
if ($this->namespace !== null) { | ||
$builder->where('namespace', $this->namespace); | ||
} | ||
|
||
|
@@ -700,7 +700,7 @@ public function getLastBatch(): int | |
->get() | ||
->getResultObject(); | ||
|
||
$batch = is_array($batch) && count($batch) | ||
$batch = is_array($batch) && $batch !== [] | ||
? end($batch)->batch | ||
: 0; | ||
|
||
|
@@ -725,7 +725,7 @@ public function getBatchStart(int $batch): string | |
->get() | ||
->getResultObject(); | ||
|
||
return count($migration) ? $migration[0]->version : '0'; | ||
return $migration !== [] ? $migration[0]->version : '0'; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not check
!== null
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip the
explode()
function with an empty stringThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, but how many times do we set validation rules without specifying the rules? An empty string will be handled correctly with
explode()
.Using typing makes the code less clear. I would like to avoid it if we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost the same answer #9302 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An empty string as an edge case, I would not worry about it that much. For me, the readability of the code is more important.