Find a Rector rule
Find the best Rector rule to solve your problem. Searching through 1083 rules.
Found 7 rules, grouped by set: Clear
Change CompositeExpression ->addMultiple($parts) to ->with(...$parts)
use Doctrine\ORM\EntityRepository;
use Doctrine\DBAL\Query\Expression\CompositeExpression;
class SomeRepository extends EntityRepository
{
public function getSomething($parts)
{
$compositeExpression = CompositeExpression::and('', ...$parts);
- $compositeExpression->addMultiple($parts);
+ $compositeExpression->with(...$parts);
}
}
Change executeQuery() with parameters to bindValue() with explicit values
use Doctrine\DBAL\Statement;
class SomeClass
{
public function run(Statement $statement, array $params): void
{
- $result = $statement->executeQuery($params);
+ foreach ($params as $key => $parameter) {
+ $statement->bindValue(is_int($key) ? $key + 1 : $key, $parameter);
+ }
+
+ $result = $statement->executeQuery();
}
}
Change QueryBuilder::resetQueryPart() to $queryBuilder->reset*()
class SomeRepository
{
public function resetQueryPart(\Doctrine\DBAL\Query\QueryBuilder $queryBuilder)
{
- $queryBuilder->resetQueryPart('distinct');
- $queryBuilder->resetQueryPart('where');
- $queryBuilder->resetQueryPart('groupBy');
- $queryBuilder->resetQueryPart('having');
- $queryBuilder->resetQueryPart('orderBy');
+ $queryBuilder->distinct(false);
+ $queryBuilder->resetWhere();
+ $queryBuilder->resetGroupBy();
+ $queryBuilder->resetHaving();
+ $queryBuilder->resetOrderBy();
}
}
Change $platform->getName() === "postgresql" to $platform instanceof PostgreSQLPlatform, following the DBAL 3.2 deprecation of AbstractPlatform::getName(), see https://github.com/doctrine/dbal/pull/4755
-if ('postgresql' === $this->platform->getName()) {}
+if ($this->platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform) {}
Replace QueryBuilder::execute() with executeQuery() or executeStatement() based on the query type
$queryBuilder
->select('u.id')
->from('user', 'u')
- ->execute();
+ ->executeQuery();
Extract array arg on QueryBuilder select, addSelect, groupBy, addGroupBy
function query(\Doctrine\DBAL\Query\QueryBuilder $queryBuilder)
{
- $query = $queryBuilder->select(['u.id', 'p.id']);
+ $query = $queryBuilder->select('u.id', 'p.id');
}
Change Doctrine\DBAL\Connection and Doctrine\DBAL\Driver\ResultStatement ->fetchAll() to ->fetchAllAssociative() and other replacements
use Doctrine\DBAL\Connection;
class SomeClass
{
public function run(Connection $connection)
{
- return $connection->fetchAll();
+ return $connection->fetchAllAssociative();
}
}