Skip to content

Commit 3eda20c

Browse files
lucasmichotLucas Michot
andauthored
Changes strlen comparison to 0 to direct empty string compare (#59686)
Co-authored-by: Lucas Michot <lucas@zaiple.com>
1 parent a88b4f2 commit 3eda20c

11 files changed

Lines changed: 17 additions & 13 deletions

File tree

rector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use Rector\CodeQuality\Rector\Identical\StrlenZeroToIdenticalEmptyStringRector;
56
use Rector\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector;
67
use Rector\CodingStyle\Rector\Closure\ClosureDelegatingCallToFirstClassCallableRector;
78
use Rector\CodingStyle\Rector\FuncCall\ClosureFromCallableToFirstClassCallableRector;
@@ -81,6 +82,9 @@
8182
ThisCallOnStaticMethodToStaticCallRector::class,
8283
'tests/Foundation/fixtures/bad-syntax-strategy.php',
8384
])
85+
->withRules([
86+
StrlenZeroToIdenticalEmptyStringRector::class,
87+
])
8488
->withPreparedSets(
8589
deadCode: false,
8690
codeQuality: false,

src/Illuminate/Console/Concerns/ConfiguresPrompts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function promptUntilValid($prompt, $required, $validate)
141141

142142
$error = is_callable($validate) ? $validate($result) : $this->validatePrompt($result, $validate);
143143

144-
if (is_string($error) && strlen($error) > 0) {
144+
if (is_string($error) && $error !== '') {
145145
$this->components->error($error);
146146

147147
if ($this->laravel->runningUnitTests()) {

src/Illuminate/Database/Eloquent/Concerns/TransformsToResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static function guessResourceName(): array
7171
$potentialResource = sprintf(
7272
'%s\\Http\\Resources\\%s%s',
7373
Str::before($modelClass, '\\Models'),
74-
strlen($relativeNamespace) > 0 ? $relativeNamespace.'\\' : '',
74+
(string) $relativeNamespace !== '' ? $relativeNamespace.'\\' : '',
7575
class_basename($modelClass)
7676
);
7777

src/Illuminate/Database/Schema/SqliteSchemaState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function appendMigrationData(string $path)
4646
]));
4747

4848
$migrations = (new Collection(preg_split("/\r\n|\n|\r/", $process->getOutput())))
49-
->filter(fn ($line) => preg_match('/^\s*(--|INSERT\s)/iu', $line) === 1 && strlen($line) > 0)
49+
->filter(fn ($line) => preg_match('/^\s*(--|INSERT\s)/iu', $line) === 1 && $line !== '')
5050
->all();
5151

5252
$this->files->append($path, implode(PHP_EOL, $migrations).PHP_EOL);

src/Illuminate/Hashing/AbstractHasher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function info($hashedValue)
2525
*/
2626
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
2727
{
28-
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
28+
if (is_null($hashedValue) || (string) $hashedValue === '') {
2929
return false;
3030
}
3131

src/Illuminate/Hashing/Argon2IdHasher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Argon2IdHasher extends ArgonHasher
1818
*/
1919
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
2020
{
21-
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
21+
if (is_null($hashedValue) || (string) $hashedValue === '') {
2222
return false;
2323
}
2424

src/Illuminate/Hashing/ArgonHasher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function algorithm()
9595
*/
9696
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
9797
{
98-
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
98+
if (is_null($hashedValue) || (string) $hashedValue === '') {
9999
return false;
100100
}
101101

src/Illuminate/Hashing/BcryptHasher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function make(#[\SensitiveParameter] $value, array $options = [])
8181
*/
8282
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
8383
{
84-
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
84+
if (is_null($hashedValue) || (string) $hashedValue === '') {
8585
return false;
8686
}
8787

src/Illuminate/Process/FakeProcessDescription.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function replaceOutput(string $output)
9999
->values()
100100
->all();
101101

102-
if (strlen($output) > 0) {
102+
if ($output !== '') {
103103
$this->output[] = [
104104
'type' => 'out',
105105
'buffer' => rtrim($output, "\n")."\n",
@@ -122,7 +122,7 @@ public function replaceErrorOutput(string $output)
122122
->values()
123123
->all();
124124

125-
if (strlen($output) > 0) {
125+
if ($output !== '') {
126126
$this->output[] = [
127127
'type' => 'err',
128128
'buffer' => rtrim($output, "\n")."\n",

src/Illuminate/Routing/RouteParameterBinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function matchToKeys(array $matches)
8989
$parameters = array_intersect_key($matches, array_flip($parameterNames));
9090

9191
return array_filter($parameters, function ($value) {
92-
return is_string($value) && strlen($value) > 0;
92+
return is_string($value) && $value !== '';
9393
});
9494
}
9595

0 commit comments

Comments
 (0)