Skip to content

Commit

Permalink
Add typehint (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Feb 3, 2021
1 parent cad72fb commit 35aad95
Show file tree
Hide file tree
Showing 35 changed files with 77 additions and 506 deletions.
2 changes: 1 addition & 1 deletion src/Admin/FieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function isIdentifier(): bool
return $this->fieldMapping['id'] ?? false;
}

public function getValue($object)
public function getValue(object $object)
{
foreach ($this->parentAssociationMappings as $parentAssociationMapping) {
$object = $this->getFieldValue($object, $parentAssociationMapping['fieldName']);
Expand Down
3 changes: 2 additions & 1 deletion src/Datagrid/OrderByToSelectWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sonata\DoctrineORMAdminBundle\Datagrid;

use Doctrine\ORM\Query\AST\Functions\IdentityFunction;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\AST\OrderByClause;
use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\AST\SelectExpression;
Expand Down Expand Up @@ -90,7 +91,7 @@ public function walkSelectStatement(SelectStatement $AST): void
*
* @return IdentityFunction|PathExpression
*/
private function createSelectExpressionItem(PathExpression $pathExpression)
private function createSelectExpressionItem(PathExpression $pathExpression): Node
{
if (PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION === $pathExpression->type) {
$identity = new IdentityFunction('identity');
Expand Down
9 changes: 3 additions & 6 deletions src/Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,19 @@ class ProxyQuery implements ProxyQueryInterface
*/
private $hints = [];

/**
* @param QueryBuilder $queryBuilder
*/
public function __construct($queryBuilder)
public function __construct(QueryBuilder $queryBuilder)
{
$this->queryBuilder = $queryBuilder;
$this->uniqueParameterId = 0;
$this->entityJoinAliases = [];
}

public function __call($name, $args)
public function __call(string $name, array $args)
{
return $this->queryBuilder->$name(...$args);
}

public function __get($name)
public function __get(string $name)
{
return $this->queryBuilder->$name;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Datagrid/ProxyQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@

interface ProxyQueryInterface extends BaseProxyQueryInterface
{
/**
* @return QueryBuilder
*/
public function getQueryBuilder();
public function getQueryBuilder(): QueryBuilder;
}
5 changes: 2 additions & 3 deletions src/DependencyInjection/Compiler/AddTemplatesCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ public function process(ContainerBuilder $container): void
}

/**
* @param string $name
* @param mixed $value
* @param mixed $value
*/
public function mergeMethodCall(Definition $definition, $name, $value): void
public function mergeMethodCall(Definition $definition, string $name, $value): void
{
$methodCalls = $definition->getMethodCalls();

Expand Down
4 changes: 1 addition & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class Configuration implements ConfigurationInterface
{
/**
* Generates the configuration tree.
*
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sonata_doctrine_orm_admin');

Expand Down
16 changes: 2 additions & 14 deletions src/Filter/AbstractDateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Sonata\DoctrineORMAdminBundle\Filter;

use Sonata\AdminBundle\Datagrid\ProxyQueryInterface as BaseProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\DateRangeType;
use Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType;
use Sonata\AdminBundle\Form\Type\Filter\DateTimeType;
Expand Down Expand Up @@ -46,21 +45,10 @@ abstract class AbstractDateFilter extends Filter
*/
protected $time = false;

public function filter(BaseProxyQueryInterface $query, $alias, $field, $data): void
public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void
{
/* NEXT_MAJOR: Remove this deprecation and update the typehint */
if (!$query instanceof ProxyQueryInterface) {
@trigger_error(sprintf(
'Passing %s as argument 1 to %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.27'
.' and will throw a \TypeError error in version 4.0. You MUST pass an instance of %s instead.',
\get_class($query),
__METHOD__,
ProxyQueryInterface::class
));
}

// check data sanity
if (!$data || !\is_array($data) || !\array_key_exists('value', $data)) {
if (!\array_key_exists('value', $data)) {
return;
}

Expand Down
16 changes: 2 additions & 14 deletions src/Filter/BooleanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Sonata\DoctrineORMAdminBundle\Filter;

use Sonata\AdminBundle\Datagrid\ProxyQueryInterface as BaseProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\Form\Type\BooleanType;
Expand All @@ -24,20 +23,9 @@
*/
class BooleanFilter extends Filter
{
public function filter(BaseProxyQueryInterface $query, $alias, $field, $data): void
public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void
{
/* NEXT_MAJOR: Remove this deprecation and update the typehint */
if (!$query instanceof ProxyQueryInterface) {
@trigger_error(sprintf(
'Passing %s as argument 1 to %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.27'
.' and will throw a \TypeError error in version 4.0. You MUST pass an instance of %s instead.',
\get_class($query),
__METHOD__,
ProxyQueryInterface::class
));
}

if (!$data || !\is_array($data) || !\array_key_exists('type', $data) || !\array_key_exists('value', $data)) {
if (!\array_key_exists('type', $data) || !\array_key_exists('value', $data)) {
return;
}

Expand Down
30 changes: 2 additions & 28 deletions src/Filter/CallbackFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Sonata\DoctrineORMAdminBundle\Filter;

use Sonata\AdminBundle\Datagrid\ProxyQueryInterface as BaseProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
Expand All @@ -24,19 +23,8 @@
*/
class CallbackFilter extends Filter
{
public function filter(BaseProxyQueryInterface $query, $alias, $field, $data): void
public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void
{
/* NEXT_MAJOR: Remove this deprecation and update the typehint */
if (!$query instanceof ProxyQueryInterface) {
@trigger_error(sprintf(
'Passing %s as argument 1 to %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.27'
.' and will throw a \TypeError error in version 4.0. You MUST pass an instance of %s instead.',
\get_class($query),
__METHOD__,
ProxyQueryInterface::class
));
}

if (!\is_callable($this->getOption('callback'))) {
throw new \RuntimeException(sprintf('Please provide a valid callback option "filter" for field "%s"', $this->getName()));
}
Expand Down Expand Up @@ -80,22 +68,8 @@ public function getRenderSettings(): array
]];
}

/**
* @param mixed[] $data
*/
protected function association(BaseProxyQueryInterface $query, array $data): array
protected function association(ProxyQueryInterface $query, array $data): array
{
/* NEXT_MAJOR: Remove this deprecation and update the typehint */
if (!$query instanceof ProxyQueryInterface) {
@trigger_error(sprintf(
'Passing %s as argument 1 to %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.27'
.' and will throw a \TypeError error in version 4.0. You MUST pass an instance of %s instead.',
\get_class($query),
__METHOD__,
ProxyQueryInterface::class
));
}

$alias = $query->entityJoin($this->getParentAssociationMappings());

return [$this->getOption('alias', $alias), $this->getFieldName()];
Expand Down
26 changes: 4 additions & 22 deletions src/Filter/ChoiceFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Sonata\DoctrineORMAdminBundle\Filter;

use Sonata\AdminBundle\Datagrid\ProxyQueryInterface as BaseProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;
use Sonata\AdminBundle\Form\Type\Operator\EqualOperatorType;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;
Expand All @@ -23,20 +22,9 @@
*/
class ChoiceFilter extends Filter
{
public function filter(BaseProxyQueryInterface $query, $alias, $field, $data): void
public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void
{
/* NEXT_MAJOR: Remove this deprecation and update the typehint */
if (!$query instanceof ProxyQueryInterface) {
@trigger_error(sprintf(
'Passing %s as argument 1 to %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.27'
.' and will throw a \TypeError error in version 4.0. You MUST pass an instance of %s instead.',
\get_class($query),
__METHOD__,
ProxyQueryInterface::class
));
}

if (!$data || !\is_array($data) || !\array_key_exists('type', $data) || !\array_key_exists('value', $data)) {
if (!\array_key_exists('type', $data) || !\array_key_exists('value', $data)) {
return;
}

Expand Down Expand Up @@ -66,10 +54,7 @@ public function getRenderSettings(): array
]];
}

/**
* NEXT_MAJOR: Change the typehint to ProxyQueryInterface.
*/
private function filterWithMultipleValues(BaseProxyQueryInterface $query, string $alias, string $field, array $data = []): void
private function filterWithMultipleValues(ProxyQueryInterface $query, string $alias, string $field, array $data = []): void
{
if (0 === \count($data['value'])) {
return;
Expand Down Expand Up @@ -100,10 +85,7 @@ private function filterWithMultipleValues(BaseProxyQueryInterface $query, string
}
}

/**
* NEXT_MAJOR: Change the typehint to ProxyQueryInterface.
*/
private function filterWithSingleValue(BaseProxyQueryInterface $query, string $alias, string $field, array $data = []): void
private function filterWithSingleValue(ProxyQueryInterface $query, string $alias, string $field, array $data = []): void
{
if ('' === $data['value'] || false === $data['value']) {
return;
Expand Down
16 changes: 2 additions & 14 deletions src/Filter/ClassFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Sonata\DoctrineORMAdminBundle\Filter;

use Sonata\AdminBundle\Datagrid\ProxyQueryInterface as BaseProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;
use Sonata\AdminBundle\Form\Type\Operator\EqualOperatorType;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;
Expand All @@ -29,20 +28,9 @@ class ClassFilter extends Filter
EqualOperatorType::TYPE_NOT_EQUAL => 'NOT INSTANCE OF',
];

public function filter(BaseProxyQueryInterface $query, $alias, $field, $data): void
public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void
{
/* NEXT_MAJOR: Remove this deprecation and update the typehint */
if (!$query instanceof ProxyQueryInterface) {
@trigger_error(sprintf(
'Passing %s as argument 1 to %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.27'
.' and will throw a \TypeError error in version 4.0. You MUST pass an instance of %s instead.',
\get_class($query),
__METHOD__,
ProxyQueryInterface::class
));
}

if (!$data || !\is_array($data) || !\array_key_exists('value', $data)) {
if (!\array_key_exists('value', $data)) {
return;
}

Expand Down
31 changes: 0 additions & 31 deletions src/Filter/EmptyFilter.php

This file was deleted.

Loading

0 comments on commit 35aad95

Please sign in to comment.