Skip to content

Commit 371e7c4

Browse files
author
Lucas Michot
authored
Always prefer typesafe string comparisons. (#36657)
1 parent 9981c77 commit 371e7c4

19 files changed

+44
-44
lines changed

src/Illuminate/Http/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function path()
142142
{
143143
$pattern = trim($this->getPathInfo(), '/');
144144

145-
return $pattern == '' ? '/' : $pattern;
145+
return $pattern === '' ? '/' : $pattern;
146146
}
147147

148148
/**

src/Illuminate/Queue/DatabaseQueue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ protected function getLockForPopping()
253253
$databaseEngine = $this->database->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
254254
$databaseVersion = $this->database->getConfig('version') ?? $this->database->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
255255

256-
if ($databaseEngine == 'mysql' && ! strpos($databaseVersion, 'MariaDB') && version_compare($databaseVersion, '8.0.1', '>=') ||
257-
$databaseEngine == 'pgsql' && version_compare($databaseVersion, '9.5', '>=')) {
256+
if ($databaseEngine === 'mysql' && ! strpos($databaseVersion, 'MariaDB') && version_compare($databaseVersion, '8.0.1', '>=') ||
257+
$databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>=')) {
258258
return 'FOR UPDATE SKIP LOCKED';
259259
}
260260

src/Illuminate/Routing/CompiledRouteCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ protected function newRoute(array $attributes)
297297
), '/');
298298
}
299299

300-
return $this->router->newRoute($attributes['methods'], $baseUri == '' ? '/' : $baseUri, $attributes['action'])
300+
return $this->router->newRoute($attributes['methods'], $baseUri === '' ? '/' : $baseUri, $attributes['action'])
301301
->setFallback($attributes['fallback'])
302302
->setDefaults($attributes['defaults'])
303303
->setWheres($attributes['wheres'])

src/Illuminate/Support/Str.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public static function replaceArray($search, array $replace, $subject)
522522
*/
523523
public static function replaceFirst($search, $replace, $subject)
524524
{
525-
if ($search == '') {
525+
if ($search === '') {
526526
return $subject;
527527
}
528528

src/Illuminate/Support/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function filled($value)
157157
*/
158158
function object_get($object, $key, $default = null)
159159
{
160-
if (is_null($key) || trim($key) == '') {
160+
if (is_null($key) || trim($key) === '') {
161161
return $object;
162162
}
163163

src/Illuminate/Testing/Concerns/TestDatabases.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function whenNotUsingInMemoryDatabase($callback)
133133
{
134134
$database = DB::getConfig('database');
135135

136-
if ($database != ':memory:') {
136+
if ($database !== ':memory:') {
137137
$callback($database);
138138
}
139139
}

src/Illuminate/Validation/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ protected function validateAttribute($attribute, $rule)
528528

529529
[$rule, $parameters] = ValidationRuleParser::parse($rule);
530530

531-
if ($rule == '') {
531+
if ($rule === '') {
532532
return;
533533
}
534534

tests/Auth/AuthAccessGateTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ public function testAfterCallbacksAreCalledWithResult()
262262
});
263263

264264
$gate->after(function ($user, $ability, $result) {
265-
if ($ability == 'foo') {
265+
if ($ability === 'foo') {
266266
$this->assertTrue($result, 'After callback on `foo` should receive true as result');
267-
} elseif ($ability == 'bar') {
267+
} elseif ($ability === 'bar') {
268268
$this->assertFalse($result, 'After callback on `bar` should receive false as result');
269269
} else {
270270
$this->assertNull($result, 'After callback on `missing` should receive null as result');
@@ -312,7 +312,7 @@ public function testAfterCallbacksDoNotOverrideEachOther()
312312
$gate = $this->getBasicGate();
313313

314314
$gate->after(function ($user, $ability, $result) {
315-
return $ability == 'allow';
315+
return $ability === 'allow';
316316
});
317317

318318
$gate->after(function ($user, $ability, $result) {

tests/Console/Scheduling/EventTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testBuildCommandInBackgroundUsingWindows()
6666

6767
public function testBuildCommandSendOutputTo()
6868
{
69-
$quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'";
69+
$quote = (DIRECTORY_SEPARATOR === '\\') ? '"' : "'";
7070

7171
$event = new Event(m::mock(EventMutex::class), 'php -i');
7272

@@ -81,7 +81,7 @@ public function testBuildCommandSendOutputTo()
8181

8282
public function testBuildCommandAppendOutput()
8383
{
84-
$quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'";
84+
$quote = (DIRECTORY_SEPARATOR === '\\') ? '"' : "'";
8585

8686
$event = new Event(m::mock(EventMutex::class), 'php -i');
8787

tests/Database/DatabaseEloquentFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function test_belongs_to_relationship()
243243
->create();
244244

245245
$this->assertCount(3, $posts->filter(function ($post) {
246-
return $post->user->name == 'Taylor Otwell';
246+
return $post->user->name === 'Taylor Otwell';
247247
}));
248248

249249
$this->assertCount(1, FactoryTestUser::all());
@@ -401,11 +401,11 @@ public function test_sequences()
401401
$this->assertCount(4, $user->roles);
402402

403403
$this->assertCount(2, $user->roles->filter(function ($role) {
404-
return $role->pivot->admin == 'Y';
404+
return $role->pivot->admin === 'Y';
405405
}));
406406

407407
$this->assertCount(2, $user->roles->filter(function ($role) {
408-
return $role->pivot->admin == 'N';
408+
return $role->pivot->admin === 'N';
409409
}));
410410
}
411411

0 commit comments

Comments
 (0)