Skip to content
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

make remaining classes final #1301

Merged
merged 1 commit into from
Feb 10, 2021
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
22 changes: 10 additions & 12 deletions src/Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
/**
* This class try to unify the query usage with Doctrine.
*
* @final since sonata-project/doctrine-orm-admin-bundle 3.x
*
* @method Query\Expr expr()
* @method QueryBuilder setCacheable($cacheable)
* @method bool isCacheable()
Expand Down Expand Up @@ -75,32 +73,32 @@
* @method QueryBuilder resetDQLParts($parts = null)
* @method QueryBuilder resetDQLPart($part)
*/
class ProxyQuery implements ProxyQueryInterface
final class ProxyQuery implements ProxyQueryInterface
{
/**
* @var QueryBuilder
*/
protected $queryBuilder;
private $queryBuilder;

/**
* @var string|null
*/
protected $sortBy;
private $sortBy;

/**
* @var string|null
*/
protected $sortOrder;
private $sortOrder;

/**
* @var int
*/
protected $uniqueParameterId;
private $uniqueParameterId;

/**
* @var string[]
*/
protected $entityJoinAliases;
private $entityJoinAliases;

/**
* For BC reasons, this property is true by default.
Expand Down Expand Up @@ -142,7 +140,7 @@ public function __clone()
* Optimize queries with a lot of rows.
* It is not recommended to use "false" with left joins.
*/
final public function setDistinct(bool $distinct): ProxyQueryInterface
public function setDistinct(bool $distinct): ProxyQueryInterface
{
if (!\is_bool($distinct)) {
throw new \InvalidArgumentException('$distinct is not a boolean');
Expand All @@ -153,7 +151,7 @@ final public function setDistinct(bool $distinct): ProxyQueryInterface
return $this;
}

final public function isDistinct(): bool
public function isDistinct(): bool
{
return $this->distinct;
}
Expand Down Expand Up @@ -336,7 +334,7 @@ public function entityJoin(array $associationMappings): string
* @see \Doctrine\ORM\Query::setHint
* @see \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER
*/
final public function setHint(string $name, $value): ProxyQueryInterface
public function setHint(string $name, $value): ProxyQueryInterface
{
$this->hints[$name] = $value;

Expand All @@ -347,7 +345,7 @@ final public function setHint(string $name, $value): ProxyQueryInterface
* This method alters the query to return a clean set of object with a working
* set of Object.
*/
protected function getFixedQueryBuilder(QueryBuilder $queryBuilder): QueryBuilder
private function getFixedQueryBuilder(QueryBuilder $queryBuilder): QueryBuilder
{
$queryBuilderId = clone $queryBuilder;
$rootAlias = current($queryBuilderId->getRootAliases());
Expand Down
5 changes: 1 addition & 4 deletions src/Exporter/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
use Sonata\Exporter\Source\DoctrineORMQuerySourceIterator;
use Sonata\Exporter\Source\SourceIteratorInterface;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.29
*/
class DataSource implements DataSourceInterface
final class DataSource implements DataSourceInterface
{
public function createIterator(ProxyQueryInterface $query, array $fields): SourceIteratorInterface
{
Expand Down
5 changes: 1 addition & 4 deletions src/Filter/DateTimeRangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

use Sonata\Form\Type\DateTimeRangeType;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
class DateTimeRangeFilter extends AbstractDateFilter
final class DateTimeRangeFilter extends AbstractDateFilter
{
/**
* This Filter allows filtering by time.
Expand Down
5 changes: 1 addition & 4 deletions src/Filter/ModelAutocompleteFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
use Sonata\AdminBundle\Form\Type\Operator\EqualOperatorType;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
class ModelAutocompleteFilter extends Filter
final class ModelAutocompleteFilter extends Filter
{
public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void
{
Expand Down
5 changes: 1 addition & 4 deletions src/Filter/ModelFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
class ModelFilter extends Filter
final class ModelFilter extends Filter
{
public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void
{
Expand Down
5 changes: 1 addition & 4 deletions src/Filter/NumberFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;
use Symfony\Component\Form\Extension\Core\Type\NumberType as FormNumberType;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
class NumberFilter extends Filter
final class NumberFilter extends Filter
{
public const CHOICES = [
NumberOperatorType::TYPE_EQUAL => '=',
Expand Down
5 changes: 1 addition & 4 deletions src/Filter/StringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
use Sonata\AdminBundle\Form\Type\Operator\StringOperatorType;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
class StringFilter extends Filter
final class StringFilter extends Filter
{
public const TRIM_NONE = 0;
public const TRIM_LEFT = 1;
Expand Down
5 changes: 1 addition & 4 deletions src/Filter/TimeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

use Symfony\Component\Form\Extension\Core\Type\TimeType;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
class TimeFilter extends AbstractDateFilter
final class TimeFilter extends AbstractDateFilter
{
/**
* This filter has no range.
Expand Down
5 changes: 1 addition & 4 deletions src/Guesser/FilterTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
use Symfony\Component\Form\Guess\Guess;
use Symfony\Component\Form\Guess\TypeGuess;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
class FilterTypeGuesser extends AbstractTypeGuesser
final class FilterTypeGuesser extends AbstractTypeGuesser
{
public function guessType(string $class, string $property, ModelManagerInterface $modelManager): ?TypeGuess
{
Expand Down
5 changes: 1 addition & 4 deletions src/Guesser/TypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
use Symfony\Component\Form\Guess\Guess;
use Symfony\Component\Form\Guess\TypeGuess;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
class TypeGuesser extends AbstractTypeGuesser
final class TypeGuesser extends AbstractTypeGuesser
{
public function guessType(string $class, string $property, ModelManagerInterface $modelManager): ?TypeGuess
{
Expand Down
7 changes: 2 additions & 5 deletions src/Model/AuditReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
use SimpleThings\EntityAudit\AuditReader as SimpleThingsAuditReader;
use Sonata\AdminBundle\Model\AuditReaderInterface;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
class AuditReader implements AuditReaderInterface
final class AuditReader implements AuditReaderInterface
{
/**
* @var SimpleThingsAuditReader
*/
protected $auditReader;
private $auditReader;

public function __construct(SimpleThingsAuditReader $auditReader)
{
Expand Down
47 changes: 0 additions & 47 deletions src/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Persistence\ManagerRegistry;
Expand All @@ -33,16 +32,10 @@
use Sonata\AdminBundle\Model\LockInterface;
use Sonata\AdminBundle\Model\ModelManagerInterface;
use Sonata\DoctrineORMAdminBundle\Admin\FieldDescription;
use Sonata\DoctrineORMAdminBundle\Datagrid\OrderByToSelectWalker;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
use Sonata\Exporter\Source\DoctrineORMQuerySourceIterator;
use Sonata\Exporter\Source\SourceIteratorInterface;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*/
final class ModelManager implements ModelManagerInterface, LockInterface
{
public const ID_SEPARATOR = '~';
Expand Down Expand Up @@ -505,46 +498,6 @@ public function batchDelete(string $class, ProxyQueryInterface $query): void
}
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-admin/doctrine-orm-admin-bundle 3.27 and will be removed in 4.0.
*
* @return DoctrineORMQuerySourceIterator
*/
public function getDataSourceIterator(
DatagridInterface $datagrid,
array $fields,
?int $firstResult = null,
?int $maxResult = null
): SourceIteratorInterface {
@trigger_error(sprintf(
'Method %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.27 and will be removed in 4.0.',
__METHOD__
), \E_USER_DEPRECATED);

$datagrid->buildPager();
$query = $datagrid->getQuery();

$query->select('DISTINCT '.current($query->getRootAliases()));
$query->setFirstResult($firstResult);
$query->setMaxResults($maxResult);

if ($query instanceof ProxyQueryInterface) {
$sortBy = $query->getSortBy();

if (!empty($sortBy)) {
$query->addOrderBy($sortBy, $query->getSortOrder());
$query = $query->getQuery();
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [OrderByToSelectWalker::class]);
} else {
$query = $query->getQuery();
}
}

return new DoctrineORMQuerySourceIterator($query, $fields);
}

public function getExportFields(string $class): array
{
$metadata = $this->getEntityManager($class)->getClassMetadata($class);
Expand Down
6 changes: 1 addition & 5 deletions tests/Datagrid/ProxyQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,7 @@ public function testGetFixedQueryBuilder($class, $alias, $id, $expectedId, $valu
->method('getRootAliases')
->willReturn([$alias]);

$pq = $this->getMockBuilder(ProxyQuery::class)
->setConstructorArgs([$qb])
->setMethods(['a'])
->getMock();

$pq = new ProxyQuery($qb);
$pq->setDistinct($distinct);

/* Work */
Expand Down
18 changes: 8 additions & 10 deletions tests/Exporter/DataSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,21 @@ public function testSortableInDataSourceIterator(
$em = $this->createStub(EntityManager::class);
$em->method('getConfiguration')->willReturn($configuration);

$queryBuilder = $this->getMockBuilder(QueryBuilder::class)
->setConstructorArgs([$em])
->getMock();
$queryBuilder = $this->createMock(QueryBuilder::class);

$queryBuilder->expects($isAddOrderBy ? $this->atLeastOnce() : $this->never())->method('addOrderBy');
$queryBuilder->method('getRootAliases')->willReturn(['a']);

$query = new Query($em);
$queryBuilder->method('getQuery')->willReturn($query);

$proxyQuery = $this->getMockBuilder(ProxyQuery::class)
->setConstructorArgs([$queryBuilder])
->onlyMethods(['getSortBy', 'getSortOrder'])
->getMock();

$proxyQuery->method('getSortOrder')->willReturn($sortOrder);
$proxyQuery->method('getSortBy')->willReturn($sortBy);
$proxyQuery = new ProxyQuery($queryBuilder);
if (null !== $sortBy) {
$proxyQuery->setSortBy([], ['fieldName' => $sortBy]);
}
if (null !== $sortOrder) {
$proxyQuery->setSortOrder($sortOrder);
}

$this->dataSource->createIterator($proxyQuery, []);

Expand Down
Loading