8000 Modernize `strpos()` calls by derrabus · Pull Request #9480 · doctrine/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Modernize strpos() calls #9480

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

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"psr/cache": "^1 || ^2 || ^3",
"symfony/console": "^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/polyfill-php72": "^1.23",
"symfony/polyfill-php80": "^1.15"
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"doctrine/annotations": "^1.13",
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use function array_slice;
use function lcfirst;
use function sprintf;
use function strpos;
use function str_starts_with;
use function substr;

/**
Expand Down Expand Up @@ -246,15 +246,15 @@ public function count(array $criteria)
*/
public function __call($method, $arguments)
{
if (strpos($method, 'findBy') === 0) {
if (str_starts_with($method, 'findBy')) {
return $this->resolveMagicCall('findBy', substr($method, 6), $arguments);
}

if (strpos($method, 'findOneBy') === 0) {
if (str_starts_with($method, 'findOneBy')) {
return $this->resolveMagicCall('findOneBy', substr($method, 9), $arguments);
}

if (strpos($method, 'countBy') === 0) {
if (str_starts_with($method, 'countBy')) {
return $this->resolveMagicCall('count', substr($method, 7), $arguments);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
use function explode;
use function in_array;
use function is_subclass_of;
use function str_contains;
use function strlen;
use function strpos;
use function strtolower;
use function substr;

Expand Down Expand Up @@ -338,7 +338,7 @@ private function addDefaultDiscriminatorMap(ClassMetadata $class): void
*/
private function getShortName(string $className): string
{
if (strpos($className, '\\') === false) {
if (! str_contains($className, '\\')) {
return strtolower($className);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
use function ltrim;
use function method_exists;
use function spl_object_id;
use function str_contains;
use function str_replace;
use function strpos;
use function strtolower;
use function trait_exists;
use function trim;
Expand Down Expand Up @@ -2671,7 +2671,7 @@ public function setPrimaryTable(array $table)
{
if (isset($table['name'])) {
// Split schema and table name from a table name like "myschema.mytable"
if (strpos($table['name'], '.') !== false) {
if (str_contains($table['name'], '.')) {
[$this->table['schema'], $table['name']] = explode('.', $table['name'], 2);
}

Expand Down Expand Up @@ -2917,7 +2917,7 @@ public function addSqlResultSetMapping(array $resultMapping)

if (! isset($field['column'])) {
$fieldName = $field['name'];
if (strpos($fieldName, '.')) {
if (str_contains($fieldName, '.')) {
[, $fieldName] = explode('.', $fieldName);
}

Expand Down Expand Up @@ -3701,7 +3701,7 @@ public function fullyQualifiedClassName($className)
return $className;
}

if (strpos($className, '\\') === false && $this->namespace) {
if (! str_contains($className, '\\') && $this->namespace) {
return $this->namespace . '\\' . $className;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\ORM\Mapping;

use function strpos;
use function str_contains;
use function strrpos;
use function strtolower;
use function substr;
Expand All @@ -21,7 +21,7 @@ class DefaultNamingStrategy implements NamingStrategy
*/
public function classToTableName($className)
{
if (strpos($className, '\\') !== false) {
if (str_contains($className, '\\')) {
return substr($className, strrpos($className, '\\') + 1);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Doctrine\Deprecations\Deprecation;

use function preg_replace;
use function strpos;
use function str_contains;
use function strrpos;
use function strtolower;
use function strtoupper;
Expand Down Expand Up @@ -79,7 +79,7 @@ public function setCase($case)
*/
public function classToTableName($className)
{
if (strpos($className, '\\') !== false) {
if (str_contains($className, '\\')) {
$className = substr($className, strrpos($className, '\\') + 1);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
use function reset;
use function spl_object_id;
use function sprintf;
use function strpos;
use function str_contains;
use function strtoupper;
use function trim;

Expand Down Expand Up @@ -1733,7 +1733,7 @@ private function getSelectConditionStatementColumnSQL(
return $columns;
}

if ($assoc !== null && strpos($field, ' ') === false && strpos($field, '(') === false) {
if ($assoc !== null && ! str_contains($field, ' ') && ! str_contains($field, '(')) {
// very careless developers could potentially open up this normally hidden api for userland attacks,
// therefore checking for spaces and function calls which are not allowed.

Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Query/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
use function ctype_alpha;
use function defined;
use function is_numeric;
use function str_contains;
use function str_replace;
use function stripos;
use function strlen;
use function strpos;
use function strtoupper;
use function substr;

Expand Down Expand Up @@ -149,7 +149,7 @@ protected function getType(&$value)
switch (true) {
// Recognize numeric values
case is_numeric($value):
if (strpos($value, '.') !== false || stripos($value, 'e') !== false) {
if (str_contains($value, '.') || stripos($value, 'e') !== false) {
return self::T_FLOAT;
}

Expand All @@ -173,11 +173,11 @@ protected function getType(&$value)
}
}

if (strpos($value, ':') !== false) {
if (str_contains($value, ':')) {
return self::T_ALIASED_NAME;
}

if (strpos($value, '\\') !== false) {
if (str_contains($value, '\\')) {
return self::T_FULLY_QUALIFIED_NAME;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Query/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
use function interface_exists;
use function is_string;
use function sprintf;
use function str_contains;
use function strlen;
use function strpos;
use function strrpos;
Expand Down Expand Up @@ -670,7 +671,7 @@ private function processDeferredNewObjectExpressions(SelectStatement $AST): void
$fromClassName = $AST->fromClause->identificationVariableDeclarations[0]->rangeVariableDeclaration->abstractSchemaName ?? null;

// If the namespace is not given then assumes the first FROM entity namespace
if (strpos($className, '\\') === false && ! class_exists($className) && strpos($fromClassName, '\\') !== false) {
if (! str_contains($className, '\\') && ! class_exists($className) && str_contains($fromClassName, '\\')) {
$namespace = substr($fromClassName, 0, strrpos($fromClassName, '\\'));
$fqcn = $namespace . '\\' . $className;

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Query/QueryExpressionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use function count;
use function str_replace;
use function strpos;
use function str_starts_with;

/**
* Converts Collection expressions to Query expressions.
Expand Down Expand Up @@ -114,7 +114,7 @@ public function walkComparison(Comparison $comparison)
$field = $this->queryAliases[0] . '.' . $comparison->getField();

foreach ($this->queryAliases as $alias) {
if (strpos($comparison->getField() . '.', $alias . '.') === 0) {
if (str_starts_with($comparison->getField() . '.', $alias . '.')) {
$field = $comparison->getField();
break;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use function explode;
use function in_array;
use function sprintf;
use function strpos;
use function str_contains;
use function strtolower;

/**
Expand Down Expand Up @@ -381,7 +381,7 @@ public function addNamedNativeQueryEntityResultMapping(ClassMetadataInfo $classM
$fieldName = $field['name'];
$relation = null;

if (strpos($fieldName, '.') !== false) {
if (str_contains($fieldName, '.')) {
[$relation, $fieldName] = explode('.', $fieldName);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use function key;
use function reset;
use function sprintf;
use function str_starts_with;
use function strpos;
use function strrpos;
use function substr;
Expand Down Expand Up @@ -1334,7 +1335,7 @@ public function addCriteria(Criteria $criteria)
foreach ($criteria->getOrderings() as $sort => $order) {
$hasValidAlias = false;
foreach ($allAliases as $alias) {
if (strpos($sort . '.', $alias . '.') === 0) {
if (str_starts_with($sort . '.', $alias . '.')) {
$hasValidAlias = true;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
use function max;
use function mkdir;
use function sprintf;
use function str_contains;
use function str_repeat;
use function str_replace;
use function strlen;
use function strpos;
use function strrpos;
use function strtolower;
use function substr;
Expand Down Expand Up @@ -960,7 +960,7 @@ protected function getTraits(ClassMetadataInfo $metadata)
*/
protected function hasNamespace(ClassMetadataInfo $metadata)
{
return (bool) strpos($metadata->name, '\\');
return str_contains($metadata->name, '\\');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Tests\DbalExtensions\Connection;
use Doctrine\Tests\Models\OrnementalOrphanRemoval\Person;
use Doctrine\Tests\Models\OrnementalOrphanRemoval\PhoneNumber;
use Doctrine\Tests\OrmFunctionalTestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Doctrine\Tests\OrmFunctionalTestCase;

use function array_filter;
use function strpos;
use function str_contains;

class DBAL483Test extends OrmFunctionalTestCase
{
Expand All @@ -37,7 +37,7 @@ public function testDefaultValueIsComparedCorrectly(): void
$updateSql = $this->schemaTool->getUpdateSchemaSql([$class]);

$updateSql = array_filter($updateSql, static function ($sql) {
return strpos($sql, 'DBAL483') !== false;
return str_contains($sql, 'DBAL483');
});

self::assertCount(0, $updateSql);
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use function array_filter;
use function implode;
use function method_exists;
use function strpos;
use function str_contains;

use const PHP_EOL;

Expand Down Expand Up @@ -106,7 +106,7 @@ public function assertCreatedSchemaNeedsNoUpdates($classes): void

$sql = $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform());
$sql = array_filter($sql, static function ($sql) {
return strpos($sql, 'DROP') === false;
return ! str_contains($sql, 'DROP');
});

self::assertCount(0, $sql, 'SQL: ' . implode(PHP_EOL, $sql));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use function array_filter;
use function array_shift;
use function implode;
use function strpos;
use function str_starts_with;

class PostgreSqlSchemaToolTest extends OrmFunctionalTestCase
{
Expand Down Expand Up @@ -120,7 +120,7 @@ public function testGetDropSchemaSql(): void
$dropSequenceSQLs = 0;

foreach ($sql as $stmt) {
if (strpos($stmt, 'DROP SEQUENCE') === 0) {
if (str_starts_with($stmt, 'DROP SEQUENCE')) {
$dropSequenceSQLs++;
}
}
Expand All @@ -143,7 +143,7 @@ public function testUpdateSchemaWithPostgreSQLSchema(): void

$sql = $tool->getUpdateSchemaSql($classes);
$sql = array_filter($sql, static function ($sql) {
return strpos($sql, 'DROP SEQUENCE stonewood.') === 0;
return str_starts_with($sql, 'DROP SEQUENCE stonewood.');
});

self::assertCount(0, $sql, implode("\n", $sql));
Expand Down
9 changes: 5 additions & 4 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH7875Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
use function current;
use function method_exists;
use function sprintf;
use function strpos;
use function str_contains;
use function str_starts_with;

/** @group GH7875 */
final class GH7875Test extends OrmFunctionalTestCase
Expand Down Expand Up @@ -46,7 +47,7 @@ public function cleanUpSchema(): void
private function filterCreateTable(array $sqls, string $tableName): array
{
return array_filter($sqls, static function (string $sql) use ($tableName): bool {
return strpos($sql, sprintf('CREATE TABLE %s (', $tableName)) === 0;
return str_starts_with($sql, sprintf('CREATE TABLE %s (', $tableName));
});
}

Expand All @@ -62,7 +63,7 @@ public function testUpdateSchemaSql(): void
$this->_em->getConnection()->executeStatement(current($sqls));

$sqls = array_filter($tool->getUpdateSchemaSql($classes), static function (string $sql): bool {
return strpos($sql, ' gh7875_my_entity ') !== false;
return str_contains($sql, ' gh7875_my_entity ');
});

self::assertSame([], $sqls);
Expand Down Expand Up @@ -114,7 +115,7 @@ public function testUpdateSchemaSqlWithSchemaAssetFilter(?string $filterRegex, ?

$sqls = $tool->getUpdateSchemaSql($classes);
$sqls = array_filter($sqls, static function (string $sql): bool {
return strpos($sql, ' gh7875_my_entity ') !== false;
return str_contains($sql, ' gh7875_my_entity ');
});

self::assertCount(0, $sqls);
Expand Down
Loading
0