Skip to content

Commit 3d336c5

Browse files
authored
Replace strpos with str_contains and str_starts_with (#40353)
1 parent b52ced2 commit 3d336c5

File tree

20 files changed

+24
-24
lines changed

20 files changed

+24
-24
lines changed

src/Illuminate/Auth/Access/Gate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ protected function callPolicyMethod($policy, $method, $user, array $arguments)
808808
*/
809809
protected function formatAbilityToMethod($ability)
810810
{
811-
return strpos($ability, '-') !== false ? Str::camel($ability) : $ability;
811+
return str_contains($ability, '-') ? Str::camel($ability) : $ability;
812812
}
813813

814814
/**

src/Illuminate/Collections/Arr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public static function get($array, $key, $default = null)
314314
return $array[$key];
315315
}
316316

317-
if (strpos($key, '.') === false) {
317+
if (! str_contains($key, '.')) {
318318
return $array[$key] ?? value($default);
319319
}
320320

src/Illuminate/Cookie/CookieValuePrefix.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function remove($cookieValue)
3737
*/
3838
public static function validate($cookieName, $cookieValue, $key)
3939
{
40-
$hasValidPrefix = strpos($cookieValue, static::create($cookieName, $key)) === 0;
40+
$hasValidPrefix = str_starts_with($cookieValue, static::create($cookieName, $key));
4141

4242
return $hasValidPrefix ? static::remove($cookieValue) : null;
4343
}

src/Illuminate/Database/Console/Seeds/SeedCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function getSeeder()
9393
{
9494
$class = $this->input->getArgument('class') ?? $this->input->getOption('class');
9595

96-
if (strpos($class, '\\') === false) {
96+
if (! str_contains($class, '\\')) {
9797
$class = 'Database\\Seeders\\'.$class;
9898
}
9999

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ public function eagerLoadRelations(array $models)
638638
// For nested eager loads we'll skip loading them here and they will be set as an
639639
// eager load on the query to retrieve the relation so that they will be eager
640640
// loaded on that query, because that is where they get hydrated as models.
641-
if (strpos($name, '.') === false) {
641+
if (! str_contains($name, '.')) {
642642
$models = $this->eagerLoadRelation($models, $name, $constraints);
643643
}
644644
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function isFillable($key)
187187
}
188188

189189
return empty($this->getFillable()) &&
190-
strpos($key, '.') === false &&
190+
! str_contains($key, '.') &&
191191
! Str::startsWith($key, '_');
192192
}
193193

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ protected function resolveCasterClass($key)
15541554

15551555
$arguments = [];
15561556

1557-
if (is_string($castType) && strpos($castType, ':') !== false) {
1557+
if (is_string($castType) && str_contains($castType, ':')) {
15581558
$segments = explode(':', $castType, 2);
15591559

15601560
$castType = $segments[0];
@@ -1580,7 +1580,7 @@ protected function resolveCasterClass($key)
15801580
*/
15811581
protected function parseCasterClass($class)
15821582
{
1583-
return strpos($class, ':') === false
1583+
return ! str_contains($class, ':')
15841584
? $class
15851585
: explode(':', $class, 2)[0];
15861586
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait QueriesRelationships
3030
public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null)
3131
{
3232
if (is_string($relation)) {
33-
if (strpos($relation, '.') !== false) {
33+
if (str_contains($relation, '.')) {
3434
return $this->hasNested($relation, $operator, $count, $boolean, $callback);
3535
}
3636

src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ protected function migratePivotAttributes(Model $model)
10591059
// To get the pivots attributes we will just take any of the attributes which
10601060
// begin with "pivot_" and add those to this arrays, as well as unsetting
10611061
// them from the parent's models since they exist in a different table.
1062-
if (strpos($key, 'pivot_') === 0) {
1062+
if (str_starts_with($key, 'pivot_')) {
10631063
$values[substr($key, 6)] = $value;
10641064

10651065
unset($model->$key);

src/Illuminate/Database/MySqlConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MySqlConnection extends Connection
2020
*/
2121
public function isMaria()
2222
{
23-
return strpos($this->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), 'MariaDB') !== false;
23+
return str_contains($this->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), 'MariaDB');
2424
}
2525

2626
/**

0 commit comments

Comments
 (0)