From 1862ad5d9a99aaa83c51c7b7a57714461ff356b1 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Fri, 27 Jan 2023 15:44:09 -0500 Subject: [PATCH 01/38] Update to work with new getSQLResultCasing trait --- src/Grid/Source/Entity.php | 77 ++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/src/Grid/Source/Entity.php b/src/Grid/Source/Entity.php index 2f2bfc7..1efbb1a 100644 --- a/src/Grid/Source/Entity.php +++ b/src/Grid/Source/Entity.php @@ -17,6 +17,7 @@ use APY\DataGridBundle\Grid\Column\JoinColumn; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Rows; +use Doctrine\ORM\Internal\SQLResultCasing; use Doctrine\ORM\NoResultException; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; @@ -28,9 +29,11 @@ class Entity extends Source { + use SQLResultCasing; + public const HINT_QUERY_HAS_FETCH_JOIN = 'grid.hasFetchJoin'; - const DOT_DQL_ALIAS_PH = '__dot__'; + const DOT_DQL_ALIAS_PH = '__dot__'; const COLON_DQL_ALIAS_PH = '__col__'; /** @@ -130,11 +133,11 @@ class Entity extends Source */ public function __construct($entityName, $group = 'default', $managerName = null) { - $this->entityName = $entityName; + $this->entityName = $entityName; $this->managerName = $managerName; - $this->joins = []; - $this->group = $group; - $this->hints = []; + $this->joins = []; + $this->group = $group; + $this->hints = []; $this->setTableAlias(self::TABLE_ALIAS); } @@ -142,7 +145,7 @@ public function initialise($container) { $doctrine = $container->get('doctrine'); - $this->manager = version_compare(Kernel::VERSION, '2.1.0', '>=') ? $doctrine->getManager($this->managerName) : $doctrine->getEntityManager($this->managerName); + $this->manager = version_compare(Kernel::VERSION, '2.1.0', '>=') ? $doctrine->getManager($this->managerName) : $doctrine->getEntityManager($this->managerName); $this->ormMetadata = $this->manager->getClassMetadata($this->entityName); $this->class = $this->ormMetadata->getReflectionClass()->name; @@ -181,12 +184,12 @@ protected function getTranslationFieldNameWithParents($column) } elseif (strpos($name, ':') !== false) { $previousParent = $this->getTableAlias(); } else { - return $this->getTableAlias().'.'.$name; + return $this->getTableAlias() . '.' . $name; } - $matches = array(); + $matches = []; if ($column->hasDQLFunction($matches)) { - return $previousParent.'.'.$matches['field']; + return $previousParent . '.' . $matches['field']; } return $column->getField(); @@ -194,6 +197,7 @@ protected function getTranslationFieldNameWithParents($column) /** * @param \APY\DataGridBundle\Grid\Column\Column $column + * * @return string */ protected function getFieldName($column, $withAlias = false) @@ -210,8 +214,8 @@ protected function getFieldName($column, $withAlias = false) $elements = explode('.', $name); while ($element = array_shift($elements)) { if (count($elements) > 0) { - $parent = ($previousParent == '') ? $this->getTableAlias() : $previousParent; - $previousParent .= '_' . $element; + $parent = ($previousParent == '') ? $this->getTableAlias() : $previousParent; + $previousParent .= '_' . $element; $this->joins[$previousParent] = ['field' => $parent . '.' . $element, 'type' => $column->getJoinType()]; } else { $name = $previousParent . '.' . $element; @@ -221,7 +225,7 @@ protected function getFieldName($column, $withAlias = false) $alias = $this->fromColIdToAlias($column->getId()); } elseif (strpos($name, ':') !== false) { $previousParent = $this->getTableAlias(); - $alias = $name; + $alias = $name; } else { return $this->getTableAlias() . '.' . $name; } @@ -389,12 +393,12 @@ protected function getQueryBuilder() */ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION) { - $this->query = $this->getQueryBuilder(); + $this->query = $this->getQueryBuilder(); $this->querySelectfromSource = clone $this->query; - $bindIndex = 123; + $bindIndex = 123; $serializeColumns = []; - $where = $gridDataJunction === Column::DATA_CONJUNCTION ? $this->query->expr()->andx() : $this->query->expr()->orx(); + $where = $gridDataJunction === Column::DATA_CONJUNCTION ? $this->query->expr()->andx() : $this->query->expr()->orx(); $columnsById = []; foreach ($columns as $column) { @@ -426,9 +430,9 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr $isDisjunction = $column->getDataJunction() === Column::DATA_DISJUNCTION; - $dqlMatches = []; + $dqlMatches = []; $hasHavingClause = $column->hasDQLFunction($dqlMatches) || $column->getIsAggregate() || $column->getUseHaving(); - if(isset($dqlMatches['function']) && $dqlMatches['function'] == 'translation_agg'){ + if (isset($dqlMatches['function']) && $dqlMatches['function'] == 'translation_agg') { $hasHavingClause = false; } @@ -439,17 +443,17 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr $columnForFilter = (!$column instanceof JoinColumn) ? $column : $columnsById[$filter->getColumnName()]; - $fieldName = $this->getFieldName($columnForFilter, false); + $fieldName = $this->getFieldName($columnForFilter, false); $bindIndexPlaceholder = "?$bindIndex"; - if( in_array($filter->getOperator(), array(Column::OPERATOR_LIKE,Column::OPERATOR_RLIKE,Column::OPERATOR_LLIKE,Column::OPERATOR_NLIKE,))){ - if(isset($dqlMatches['function']) && $dqlMatches['function'] == 'translation_agg'){ + if (in_array($filter->getOperator(), [Column::OPERATOR_LIKE, Column::OPERATOR_RLIKE, Column::OPERATOR_LLIKE, Column::OPERATOR_NLIKE,])) { + if (isset($dqlMatches['function']) && $dqlMatches['function'] == 'translation_agg') { $translationFieldName = $this->getTranslationFieldNameWithParents($columnForFilter); - $fieldName = "LOWER(".$translationFieldName.")"; - }elseif(isset($dqlMatches['function']) && $dqlMatches['function'] == 'role_agg'){ + $fieldName = "LOWER(" . $translationFieldName . ")"; + } elseif (isset($dqlMatches['function']) && $dqlMatches['function'] == 'role_agg') { $translationFieldName = $this->getTranslationFieldNameWithParents($columnForFilter); - $fieldName = "LOWER(".$translationFieldName.")"; - }else{ + $fieldName = "LOWER(" . $translationFieldName . ")"; + } else { $fieldName = "LOWER($fieldName)"; } $bindIndexPlaceholder = "LOWER($bindIndexPlaceholder)"; @@ -611,7 +615,7 @@ public function getTotalCount($maxResults = null) $platform = $countQuery->getEntityManager()->getConnection()->getDatabasePlatform(); // law of demeter win $rsm = new ResultSetMapping(); - $rsm->addScalarResult($platform->getSQLResultCasing('dctrn_count'), 'count'); + $rsm->addScalarResult($this->getSQLResultCasing($platform, 'dctrn_count'), 'count'); $countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker'); $countQuery->setResultSetMapping($rsm); @@ -629,8 +633,8 @@ public function getTotalCount($maxResults = null) $countQuery->setFirstResult(null)->setMaxResults($maxResults); try { - $data = $countQuery->getScalarResult(); - $data = array_map('current', $data); + $data = $countQuery->getScalarResult(); + $data = array_map('current', $data); $count = array_sum($data); } catch (NoResultException $e) { $count = 0; @@ -644,11 +648,11 @@ public function getFieldsMetadata($class, $group = 'default') $result = []; foreach ($this->ormMetadata->getFieldNames() as $name) { $mapping = $this->ormMetadata->getFieldMapping($name); - $values = ['title' => $name, 'source' => true]; + $values = ['title' => $name, 'source' => true]; if (isset($mapping['fieldName'])) { $values['field'] = $mapping['fieldName']; - $values['id'] = $mapping['fieldName']; + $values['id'] = $mapping['fieldName']; } if (isset($mapping['id']) && $mapping['id'] == 'id') { @@ -713,11 +717,11 @@ public function populateSelectFilters($columns, $loop = false) $query = ($selectFrom === 'source') ? clone $this->querySelectfromSource : clone $this->query; $query = $query->select($this->getFieldName($column, true)) - ->distinct() - ->orderBy($this->getFieldName($column), 'asc') - ->setFirstResult(null) - ->setMaxResults(null) - ->getQuery(); + ->distinct() + ->orderBy($this->getFieldName($column), 'asc') + ->setFirstResult(null) + ->setMaxResults(null) + ->getQuery(); if ($selectFrom === 'query') { foreach ($this->hints as $hintKey => $hintValue) { $query->setHint($hintKey, $hintValue); @@ -754,7 +758,7 @@ public function populateSelectFilters($columns, $loop = false) case 'datetime': case 'date': case 'time': - $displayedValue = $column->getDisplayedValue($value); + $displayedValue = $column->getDisplayedValue($value); $values[$displayedValue] = $displayedValue; break; default: @@ -840,7 +844,7 @@ public function clearHints() /** * Set groupby column. * - * @param string $groupBy GroupBy column + * @param string $groupBy GroupBy column */ public function setGroupBy($groupBy) { @@ -870,6 +874,7 @@ public function getTableAlias() /** * @param QueryBuilder $qb + * * @return boolean */ protected function checkIfQueryHasFetchJoin(QueryBuilder $qb) From e14d1ded47975da3d65138d148663c22d6e1c223 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Fri, 27 Jan 2023 15:56:40 -0500 Subject: [PATCH 02/38] Update required versions --- .travis.yml | 44 ++++++++++++++++++++++++++++++++++++++++++++ composer.json | 24 ++++++++++++------------ 2 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f913487 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,44 @@ +language: php + +php: + - 8.0 + - 8.1 + - 8.2 + +matrix: + include: + - php: 8.0 + env: SYMFONY_VERSION=^5.2 + - php: 8.1 + env: SYMFONY_VERSION=^5.2 + - php: 8.2 + env: SYMFONY_VERSION=^5.2 + +before_install: + - echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - | + if [ "${SYMFONY_VERSION}" != "" ]; then + packages="form dependency-injection config http-foundation http-kernel options-resolver security-guard serializer" + devpackages="framework-bundle browser-kit templating expression-language" + for package in $packages + do + composer require --no-update symfony/"$package"=${SYMFONY_VERSION}; + done + for package in $devpackages + do + composer require --dev --no-update symfony/"$package"=${SYMFONY_VERSION}; + done + fi; + +install: + - travis_retry composer self-update + - COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update ${COMPOSER_FLAGS} --no-interaction + - curl -s http://getcomposer.org/installer | php + - php composer.phar install --dev --no-interaction + +script: + - mkdir -p build/logs + - php vendor/bin/phpunit -c phpunit.xml.dist + +after_success: + - php vendor/bin/php-coveralls diff --git a/composer.json b/composer.json index bd490fa..5a23615 100644 --- a/composer.json +++ b/composer.json @@ -6,24 +6,24 @@ "type": "symfony-bundle", "license": "MIT", "require": { - "php": ">=7.4", - "symfony/form": "^4.4|^5.2", - "symfony/dependency-injection": "^4.4|^5.2", - "symfony/config": "^4.4|^5.2", - "symfony/http-foundation": "^4.4|^5.2", - "symfony/http-kernel": "^4.4|^5.2", - "symfony/options-resolver": "^4.4|^5.2", - "symfony/security-core": "^4.4|^5.2", - "symfony/serializer": "^4.4|^5.2", + "php": ">=8.0", + "symfony/form": "^5.2|^6.2", + "symfony/dependency-injection": "^5.2|^6.2", + "symfony/config": "^5.2|^6.2", + "symfony/http-foundation": "^5.2|^6.2", + "symfony/http-kernel": "^5.2|^6.2", + "symfony/options-resolver": "^5.2|^6.2", + "symfony/security-core": "^5.2|^6.2", + "symfony/serializer": "^5.2|^6.2", "twig/twig": "^2.4|^3.0" }, "require-dev": { "ext-intl": "*", "ext-mongodb": "*", "dg/bypass-finals": "^1.2", - "symfony/framework-bundle": "^4.4|^5.2", - "symfony/expression-language": "^4.4|^5.2", - "symfony/phpunit-bridge": "^4.4|^5.2", + "symfony/framework-bundle": "^5.2|^6.2", + "symfony/expression-language": "^5.2|^6.2", + "symfony/phpunit-bridge": "^5.2|^6.2", "phpunit/phpunit": "^8.5", "doctrine/orm": "~2.4,>=2.4.5", "doctrine/mongodb-odm": "^2.3" From 98690b83685593e06da7e4319950d6925c7eae57 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Mon, 30 Jan 2023 11:14:00 -0500 Subject: [PATCH 03/38] Update required versions --- composer.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 5a23615..bbd33e8 100644 --- a/composer.json +++ b/composer.json @@ -7,23 +7,23 @@ "license": "MIT", "require": { "php": ">=8.0", - "symfony/form": "^5.2|^6.2", - "symfony/dependency-injection": "^5.2|^6.2", - "symfony/config": "^5.2|^6.2", - "symfony/http-foundation": "^5.2|^6.2", - "symfony/http-kernel": "^5.2|^6.2", - "symfony/options-resolver": "^5.2|^6.2", - "symfony/security-core": "^5.2|^6.2", - "symfony/serializer": "^5.2|^6.2", + "symfony/form": "^5.2|^6.0", + "symfony/dependency-injection": "^5.2|^6.0", + "symfony/config": "^5.2|^6.0", + "symfony/http-foundation": "^5.2|^6.0", + "symfony/http-kernel": "^5.2|^6.0", + "symfony/options-resolver": "^5.2|^6.0", + "symfony/security-core": "^5.2|^6.0", + "symfony/serializer": "^5.2|^6.0", "twig/twig": "^2.4|^3.0" }, "require-dev": { "ext-intl": "*", "ext-mongodb": "*", "dg/bypass-finals": "^1.2", - "symfony/framework-bundle": "^5.2|^6.2", - "symfony/expression-language": "^5.2|^6.2", - "symfony/phpunit-bridge": "^5.2|^6.2", + "symfony/framework-bundle": "^5.2|^6.0", + "symfony/expression-language": "^5.2|^6.0", + "symfony/phpunit-bridge": "^5.2|^6.0", "phpunit/phpunit": "^8.5", "doctrine/orm": "~2.4,>=2.4.5", "doctrine/mongodb-odm": "^2.3" From c58b38477100780e458a477ac974405f660c2f37 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Mon, 30 Jan 2023 10:43:52 -0500 Subject: [PATCH 04/38] WIP: Remove injection of container service --- src/Grid/Grid.php | 38 +++++++++++++++----- src/Grid/GridBuilder.php | 39 +++++++++++++++++--- src/Grid/GridFactory.php | 60 +++++++++++++++++++++---------- src/Resources/config/grid.yml | 3 +- src/Resources/config/services.xml | 7 +++- 5 files changed, 112 insertions(+), 35 deletions(-) diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index 93d2fc7..7aaa212 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -25,7 +25,12 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Twig\Environment; class Grid implements GridInterface { @@ -70,6 +75,10 @@ class Grid implements GridInterface */ protected $router; + private $twig; + + private $httpKernel; + /** * @var null|\Symfony\Component\HttpFoundation\Session\Session; */ @@ -328,14 +337,25 @@ class Grid implements GridInterface * @param string $id set if you are using more then one grid inside controller * @param GridConfigInterface|null $config The grid configuration. */ - public function __construct($container, $id = '', GridConfigInterface $config = null) - { + public function __construct( + AuthorizationCheckerInterface $authorizationChecker, + RouterInterface $router, + RequestStack $requestStack, + Environment $twig, + HttpKernelInterface $httpKernel, + // $container, + $id = '', + GridConfigInterface $config = null + ) { // @todo: why the whole container is injected? - $this->container = $container; - $this->config = $config; + // $this->container = $container; + $this->config = $config; + + $this->router = $router; + $this->request = $requestStack->getCurrentRequest(); - $this->router = $container->get('router'); - $this->request = $container->get('request_stack')->getCurrentRequest(); + $this->twig = $twig; + $this->httpKernel = $httpKernel; if (null === $this->request) { $this->request = Request::createFromGlobals(); @@ -343,7 +363,7 @@ public function __construct($container, $id = '', GridConfigInterface $config = $this->session = $this->request->getSession(); } - $this->securityContext = $container->get('security.authorization_checker'); + $this->securityContext = $authorizationChecker; $this->id = $id; @@ -682,7 +702,7 @@ protected function processMassActions($actionId) $subRequest = $this->request->duplicate([], null, $path); - $this->massActionResponse = $this->container->get('http_kernel')->handle($subRequest, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST); + $this->massActionResponse = $this->httpKernel->handle($subRequest, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST); } else { throw new \RuntimeException(sprintf(self::MASS_ACTION_CALLBACK_NOT_VALID_EX_MSG, $action->getCallback())); } @@ -2216,7 +2236,7 @@ public function getContentResponse($param1 = null, $param2 = null, ?Response $re $response = new Response(); } - $response->setContent($this->container->get('twig')->render($view, $parameters)); + $response->setContent($this->twig->render($view, $parameters)); return $response; } diff --git a/src/Grid/GridBuilder.php b/src/Grid/GridBuilder.php index 3c4c8cf..ec7365e 100644 --- a/src/Grid/GridBuilder.php +++ b/src/Grid/GridBuilder.php @@ -6,6 +6,11 @@ use APY\DataGridBundle\Grid\Exception\InvalidArgumentException; use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException; use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Twig\Environment; /** * A builder for creating Grid instances. @@ -21,6 +26,16 @@ class GridBuilder extends GridConfigBuilder implements GridBuilderInterface */ private $container; + private $authorizationChecker; + + private $router; + + private $requestStack; + + private $twig; + + private $httpKernel; + /** * The factory. * @@ -43,12 +58,26 @@ class GridBuilder extends GridConfigBuilder implements GridBuilderInterface * @param string $name The name of the grid * @param array $options The options of the grid */ - public function __construct(Container $container, GridFactoryInterface $factory, $name, array $options = []) - { + public function __construct( + AuthorizationCheckerInterface $authorizationChecker, + RouterInterface $router, + RequestStack $requestStack, + Environment $twig, + HttpKernelInterface $httpKernel, + // Container $container, + GridFactoryInterface $factory, + $name, + array $options = [] + ) { parent::__construct($name, $options); - $this->container = $container; - $this->factory = $factory; + // $this->container = $container; + $this->authorizationChecker = $authorizationChecker; + $this->router = $router; + $this->requestStack = $requestStack; + $this->twig = $twig; + $this->httpKernel = $httpKernel; + $this->factory = $factory; } /** @@ -108,7 +137,7 @@ public function getGrid() { $config = $this->getGridConfig(); - $grid = new Grid($this->container, $config->getName(), $config); + $grid = new Grid($this->authorizationChecker, $this->router, $this->requestStack, $this->twig, $this->httpKernel, $config->getName(), $config); foreach ($this->columns as $column) { $grid->addColumn($column); diff --git a/src/Grid/GridFactory.php b/src/Grid/GridFactory.php index 7be18ca..6b2ba3c 100644 --- a/src/Grid/GridFactory.php +++ b/src/Grid/GridFactory.php @@ -6,7 +6,12 @@ use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException; use APY\DataGridBundle\Grid\Source\Source; use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Twig\Environment; /** * Class GridFactory. @@ -15,28 +20,35 @@ */ class GridFactory implements GridFactoryInterface { - /** - * The service container. - * - * @var Container - */ - private $container; - /** * @var GridRegistryInterface */ private $registry; - /** - * Constructor. - * - * @param Container $container The service container - * @param GridRegistryInterface $registry The grid registry - */ - public function __construct(Container $container, GridRegistryInterface $registry) - { - $this->container = $container; - $this->registry = $registry; + private $authorizationChecker; + + private $router; + + private $requestStack; + + private $twig; + + private $httpKernel; + + public function __construct( + AuthorizationCheckerInterface $authorizationChecker, + RouterInterface $router, + RequestStack $requestStack, + Environment $twig, + HttpKernelInterface $httpKernel, + GridRegistryInterface $registry + ) { + $this->authorizationChecker = $authorizationChecker; + $this->router = $router; + $this->requestStack = $requestStack; + $this->twig = $twig; + $this->httpKernel = $httpKernel; + $this->registry = $registry; } /** @@ -52,10 +64,20 @@ public function create($type = null, Source $source = null, array $options = []) */ public function createBuilder($type = 'grid', Source $source = null, array $options = []) { - $type = $this->resolveType($type); + $type = $this->resolveType($type); $options = $this->resolveOptions($type, $source, $options); - $builder = new GridBuilder($this->container, $this, $type->getName(), $options); + $builder = new GridBuilder( + $this->authorizationChecker, + $this->router, + $this->requestStack, + $this->twig, + $this->httpKernel, + $this, + $type->getName(), + $options + ); + $builder->setType($type); $type->buildGrid($builder, $options); diff --git a/src/Resources/config/grid.yml b/src/Resources/config/grid.yml index 6300675..c6f32ff 100644 --- a/src/Resources/config/grid.yml +++ b/src/Resources/config/grid.yml @@ -2,7 +2,8 @@ services: # Core apy_grid.factory: class: APY\DataGridBundle\Grid\GridFactory - arguments: ['@service_container', '@apy_grid.registry'] +# arguments: ['@service_container', '@apy_grid.registry'] + arguments: ['@security.authorization_checker', '@router', '@request_stack', '@twig', '@http_kernel', '@apy_grid.registry'] apy_grid.registry: class: APY\DataGridBundle\Grid\GridRegistry diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index c84133d..2cd8bf8 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -21,7 +21,12 @@ - + + + + + + %apy_data_grid.limits% From c7c633ef4121b0b2d3df924b5938ecbaef36c0a7 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Mon, 30 Jan 2023 11:18:31 -0500 Subject: [PATCH 05/38] Update php requirement to be 7.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bbd33e8..c2bbb20 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "type": "symfony-bundle", "license": "MIT", "require": { - "php": ">=8.0", + "php": ">=7.4", "symfony/form": "^5.2|^6.0", "symfony/dependency-injection": "^5.2|^6.0", "symfony/config": "^5.2|^6.0", From 35b9f885a9c197f79c76ac80b5efd16821838b19 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Mon, 30 Jan 2023 12:39:44 -0500 Subject: [PATCH 06/38] Remove remaining instances of directly injecting container service --- src/Grid/Export/Export.php | 97 ++++++++++--------- src/Grid/Grid.php | 37 +++++-- src/Grid/GridBuilder.php | 42 +++++++- src/Grid/GridFactory.php | 38 ++++++-- src/Grid/Source/Entity.php | 8 +- src/Grid/Source/Source.php | 21 ++-- src/Grid/Source/Vector.php | 4 +- src/Resources/config/grid.yml | 26 ++--- src/Resources/config/services.xml | 5 + ...umnTitleAnnotationTranslationExtractor.php | 17 +--- 10 files changed, 191 insertions(+), 104 deletions(-) diff --git a/src/Grid/Export/Export.php b/src/Grid/Export/Export.php index 3a2659c..6c30207 100644 --- a/src/Grid/Export/Export.php +++ b/src/Grid/Export/Export.php @@ -13,11 +13,12 @@ namespace APY\DataGridBundle\Grid\Export; use APY\DataGridBundle\Grid\Column\ArrayColumn; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Translation\DataCollectorTranslator; +use Twig\Environment; -abstract class Export implements ExportInterface, ContainerAwareInterface +abstract class Export implements ExportInterface { const DEFAULT_TEMPLATE = '@APYDataGrid/blocks.html.twig'; @@ -31,12 +32,16 @@ abstract class Export implements ExportInterface, ContainerAwareInterface protected $parameters = []; - protected $container; - protected $templates; protected $twig; + private $translator; + + private $router; + + private $kernelCharset; + protected $grid; protected $params = []; @@ -60,37 +65,39 @@ abstract class Export implements ExportInterface, ContainerAwareInterface */ public function __construct($title, $fileName = 'export', $params = [], $charset = 'UTF-8', $role = null) { - $this->title = $title; + $this->title = $title; $this->fileName = $fileName; - $this->params = $params; - $this->charset = $charset; - $this->role = $role; + $this->params = $params; + $this->charset = $charset; + $this->role = $role; } - /** - * Sets the Container associated with this Controller. - * - * @param ContainerInterface $container A ContainerInterface instance - * - * @return \APY\DataGridBundle\Grid\Export\Export - */ - public function setContainer(ContainerInterface $container = null) + public function setTwig(Environment $twig): self + { + $this->twig = $twig; + + return $this; + } + + public function setTranslator(DataCollectorTranslator $translator): self { - $this->container = $container; + $this->translator = $translator; + + return $this; + } - $this->twig = $this->container->get('twig'); + public function setRouter(RouterInterface $router): self + { + $this->router = $router; return $this; } - /** - * gets the Container associated with this Controller. - * - * @return ContainerInterface - */ - public function getContainer() + public function setKernelCharset(string $kernelCharset): self { - return $this->container; + $this->kernelCharset = $kernelCharset; + + return $this; } /** @@ -101,12 +108,12 @@ public function getContainer() public function getResponse() { // Response - $kernelCharset = $this->container->getParameter('kernel.charset'); + $kernelCharset = $this->kernelCharset; if ($this->charset != $kernelCharset && function_exists('mb_strlen')) { $this->content = mb_convert_encoding($this->content, $this->charset, $kernelCharset); - $filesize = mb_strlen($this->content, '8bit'); + $filesize = mb_strlen($this->content, '8bit'); } else { - $filesize = strlen($this->content); + $filesize = strlen($this->content); $this->charset = $kernelCharset; } @@ -192,7 +199,7 @@ protected function getGridData($grid) protected function getRawGridData($grid) { - $result = []; + $result = []; $this->grid = $grid; if ($this->grid->isTitleSectionVisible()) { @@ -266,7 +273,7 @@ protected function getGridTitles() $titlesClean = array_map([$this, 'cleanHTML'], $matches[0]); - $i = 0; + $i = 0; $titles = []; foreach ($this->grid->getColumns() as $column) { @@ -283,12 +290,12 @@ protected function getGridTitles() protected function getRawGridTitles() { - $translator = $this->container->get('translator'); + $translator = $this->translator; $titles = []; foreach ($this->grid->getColumns() as $column) { if ($column->isVisible(true)) { - $titles[] = utf8_decode($translator->trans(/* @Ignore */$column->getTitle())); + $titles[] = utf8_decode($translator->trans(/* @Ignore */ $column->getTitle())); } } @@ -301,7 +308,7 @@ protected function getGridRows() foreach ($this->grid->getRows() as $i => $row) { foreach ($this->grid->getColumns() as $column) { if ($column->isVisible(true)) { - $cellHTML = $this->getGridCell($column, $row); + $cellHTML = $this->getGridCell($column, $row); $rows[$i][$column->getId()] = $this->cleanHTML($cellHTML); } } @@ -335,17 +342,17 @@ protected function getGridCell($column, $row) $separator = $column->getSeparator(); - $block = null; + $block = null; $return = []; foreach ($values as $sourceValue) { - $value = $column->renderCell($sourceValue, $row, $this->container->get('router')); + $value = $column->renderCell($sourceValue, $row, $this->router); $id = $this->grid->getId(); if (($id != '' && ($block !== null - || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_cell') - || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getType() . '_cell') - || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell'))) + || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_cell') + || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getType() . '_cell') + || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell'))) || $this->hasBlock($block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_cell') || $this->hasBlock($block = 'grid_' . $id . '_column_type_' . $column->getType() . '_cell') || $this->hasBlock($block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_cell') @@ -357,7 +364,7 @@ protected function getGridCell($column, $row) || $this->hasBlock($block = 'grid_column_type_' . $column->getParentType() . '_cell')) { $html = $this->renderBlock($block, ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]); } else { - $html = $this->renderBlock('grid_column_cell', ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]); + $html = $this->renderBlock('grid_column_cell', ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]); $block = null; } @@ -395,7 +402,7 @@ protected function hasBlock($name) /** * Render block. * - * @param $name string + * @param $name string * @param $parameters string * * @return string @@ -414,9 +421,9 @@ protected function renderBlock($name, $parameters) /** * Template Loader. * + * @return \Twig\TemplateWrapper[] * @throws \Exception * - * @return \Twig\TemplateWrapper[] */ protected function getTemplates() { @@ -432,15 +439,15 @@ protected function getTemplates() * * @param \Twig\TemplateWrapper|string $template * + * @return \APY\DataGridBundle\Grid\Export\Export * @throws \Exception * - * @return \APY\DataGridBundle\Grid\Export\Export */ public function setTemplate($template) { if (is_string($template)) { if (substr($template, 0, 8) === '__SELF__') { - $this->templates = $this->getTemplatesFromString(substr($template, 8)); + $this->templates = $this->getTemplatesFromString(substr($template, 8)); $this->templates[] = $this->twig->load(static::DEFAULT_TEMPLATE); } else { $this->templates = $this->getTemplatesFromString($template); @@ -461,7 +468,7 @@ protected function getTemplatesFromString($theme) $template = $this->twig->load($theme); while ($template instanceof \Twig\TemplateWrapper) { $templates[] = $template; - $template = $template->getParent([]); + $template = $template->getParent([]); } return $templates; diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index 7aaa212..e995616 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -13,14 +13,17 @@ namespace APY\DataGridBundle\Grid; +use App\Kernel; use APY\DataGridBundle\Grid\Action\MassActionInterface; use APY\DataGridBundle\Grid\Action\RowActionInterface; use APY\DataGridBundle\Grid\Column\ActionsColumn; use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Column\MassActionColumn; use APY\DataGridBundle\Grid\Export\ExportInterface; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Source\Entity; use APY\DataGridBundle\Grid\Source\Source; +use Doctrine\Bundle\DoctrineBundle\Registry; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -30,6 +33,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Translation\DataCollectorTranslator; use Twig\Environment; class Grid implements GridInterface @@ -79,6 +83,14 @@ class Grid implements GridInterface private $httpKernel; + private $doctrine; + + private $mapping; + + private $kernelCharset; + + private $translator; + /** * @var null|\Symfony\Component\HttpFoundation\Session\Session; */ @@ -343,6 +355,10 @@ public function __construct( RequestStack $requestStack, Environment $twig, HttpKernelInterface $httpKernel, + Registry $doctrine, + Manager $mapping, + Kernel $kernel, + DataCollectorTranslator $translator, // $container, $id = '', GridConfigInterface $config = null @@ -354,8 +370,12 @@ public function __construct( $this->router = $router; $this->request = $requestStack->getCurrentRequest(); - $this->twig = $twig; - $this->httpKernel = $httpKernel; + $this->twig = $twig; + $this->httpKernel = $httpKernel; + $this->doctrine = $doctrine; + $this->mapping = $mapping; + $this->kernelCharset = $kernel->getCharset(); + $this->translator = $translator; if (null === $this->request) { $this->request = Request::createFromGlobals(); @@ -430,7 +450,7 @@ public function initialize() if (null !== $source) { $this->source = $source; - $source->initialise($this->container); + $source->initialise($this->doctrine, $this->mapping); if ($source instanceof Entity) { $groupBy = $config->getGroupBy(); @@ -520,7 +540,7 @@ public function setSource(Source $source) $this->source = $source; - $this->source->initialise($this->container); + $this->source->initialise($this->doctrine, $this->mapping); // Get columns from the source $this->source->getColumns($this->columns); @@ -733,9 +753,14 @@ protected function processExports($exportId) $this->prepare(); $export = $this->exports[$exportId]; - if ($export instanceof ContainerAwareInterface) { - $export->setContainer($this->container); + + if ($export instanceof ExportInterface) { + $export->setTwig($this->twig) + ->setTranslator($this->translator) + ->setRouter($this->router) + ->setKernelCharset($this->kernelCharset); } + $export->computeData($this); $this->exportResponse = $export->getResponse(); diff --git a/src/Grid/GridBuilder.php b/src/Grid/GridBuilder.php index ec7365e..7687d91 100644 --- a/src/Grid/GridBuilder.php +++ b/src/Grid/GridBuilder.php @@ -2,14 +2,18 @@ namespace APY\DataGridBundle\Grid; +use App\Kernel; use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Exception\InvalidArgumentException; use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; +use Doctrine\Bundle\DoctrineBundle\Registry; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Translation\DataCollectorTranslator; use Twig\Environment; /** @@ -36,6 +40,14 @@ class GridBuilder extends GridConfigBuilder implements GridBuilderInterface private $httpKernel; + private $doctrine; + + private $mapping; + + private $kernel; + + private $translator; + /** * The factory. * @@ -53,10 +65,10 @@ class GridBuilder extends GridConfigBuilder implements GridBuilderInterface /** * Constructor. * - * @param Container $container The service container - * @param GridFactoryInterface $factory The grid factory - * @param string $name The name of the grid - * @param array $options The options of the grid + * @param Container $container The service container + * @param GridFactoryInterface $factory The grid factory + * @param string $name The name of the grid + * @param array $options The options of the grid */ public function __construct( AuthorizationCheckerInterface $authorizationChecker, @@ -64,6 +76,10 @@ public function __construct( RequestStack $requestStack, Environment $twig, HttpKernelInterface $httpKernel, + Registry $doctrine, + Manager $mapping, + Kernel $kernel, + DataCollectorTranslator $translator, // Container $container, GridFactoryInterface $factory, $name, @@ -77,7 +93,11 @@ public function __construct( $this->requestStack = $requestStack; $this->twig = $twig; $this->httpKernel = $httpKernel; + $this->doctrine = $doctrine; + $this->mapping = $mapping; $this->factory = $factory; + $this->kernel = $kernel; + $this->translator = $translator; } /** @@ -137,7 +157,19 @@ public function getGrid() { $config = $this->getGridConfig(); - $grid = new Grid($this->authorizationChecker, $this->router, $this->requestStack, $this->twig, $this->httpKernel, $config->getName(), $config); + $grid = new Grid( + $this->authorizationChecker, + $this->router, + $this->requestStack, + $this->twig, + $this->httpKernel, + $this->doctrine, + $this->mapping, + $this->kernel, + $this->translator, + $config->getName(), + $config + ); foreach ($this->columns as $column) { $grid->addColumn($column); diff --git a/src/Grid/GridFactory.php b/src/Grid/GridFactory.php index 6b2ba3c..3e99850 100644 --- a/src/Grid/GridFactory.php +++ b/src/Grid/GridFactory.php @@ -2,15 +2,19 @@ namespace APY\DataGridBundle\Grid; +use App\Kernel; use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Source\Source; +use Doctrine\Bundle\DoctrineBundle\Registry; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Translation\DataCollectorTranslator; use Twig\Environment; /** @@ -35,12 +39,24 @@ class GridFactory implements GridFactoryInterface private $httpKernel; + private $doctrine; + + private $mapping; + + private $kernel; + + private $translator; + public function __construct( AuthorizationCheckerInterface $authorizationChecker, RouterInterface $router, RequestStack $requestStack, Environment $twig, HttpKernelInterface $httpKernel, + Registry $doctrine, + Manager $mapping, + Kernel $kernel, + DataCollectorTranslator $translator, GridRegistryInterface $registry ) { $this->authorizationChecker = $authorizationChecker; @@ -49,6 +65,10 @@ public function __construct( $this->twig = $twig; $this->httpKernel = $httpKernel; $this->registry = $registry; + $this->doctrine = $doctrine; + $this->mapping = $mapping; + $this->kernel = $kernel; + $this->translator = $translator; } /** @@ -73,6 +93,10 @@ public function createBuilder($type = 'grid', Source $source = null, array $opti $this->requestStack, $this->twig, $this->httpKernel, + $this->doctrine, + $this->mapping, + $this->kernel, + $this->translator, $this, $type->getName(), $options @@ -97,12 +121,14 @@ public function createColumn($name, $type, array $options = []) $column = clone $this->registry->getColumn($type); - $column->__initialize(array_merge([ - 'id' => $name, - 'title' => $name, - 'field' => $name, - 'source' => true, - ], $options)); + $column->__initialize( + array_merge([ + 'id' => $name, + 'title' => $name, + 'field' => $name, + 'source' => true, + ], $options) + ); } else { $column = $type; $column->setId($name); diff --git a/src/Grid/Source/Entity.php b/src/Grid/Source/Entity.php index 1efbb1a..2283a85 100644 --- a/src/Grid/Source/Entity.php +++ b/src/Grid/Source/Entity.php @@ -15,8 +15,10 @@ use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Column\JoinColumn; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Rows; +use Doctrine\Bundle\DoctrineBundle\Registry; use Doctrine\ORM\Internal\SQLResultCasing; use Doctrine\ORM\NoResultException; use Doctrine\ORM\Query; @@ -141,17 +143,13 @@ public function __construct($entityName, $group = 'default', $managerName = null $this->setTableAlias(self::TABLE_ALIAS); } - public function initialise($container) + public function initialise(Registry $doctrine, Manager $mapping) { - $doctrine = $container->get('doctrine'); - $this->manager = version_compare(Kernel::VERSION, '2.1.0', '>=') ? $doctrine->getManager($this->managerName) : $doctrine->getEntityManager($this->managerName); $this->ormMetadata = $this->manager->getClassMetadata($this->entityName); $this->class = $this->ormMetadata->getReflectionClass()->name; - $mapping = $container->get('grid.mapping.manager'); - /* todo autoregister mapping drivers with tag */ $mapping->addDriver($this, -1); $this->metadata = $mapping->getMetadata($this->class, $this->group); diff --git a/src/Grid/Source/Source.php b/src/Grid/Source/Source.php index 248df9b..cee8aa9 100644 --- a/src/Grid/Source/Source.php +++ b/src/Grid/Source/Source.php @@ -16,8 +16,10 @@ use APY\DataGridBundle\Grid\Exception\PropertyAccessDeniedException; use APY\DataGridBundle\Grid\Helper\ColumnsIterator; use APY\DataGridBundle\Grid\Mapping\Driver\DriverInterface; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Rows; +use Doctrine\Bundle\DoctrineBundle\Registry; abstract class Source implements DriverInterface { @@ -97,14 +99,7 @@ abstract public function execute($columns, $page = 0, $limit = 0, $maxResults = */ abstract public function getTotalCount($maxResults = null); - /** - * Set container. - * - * @abstract - * - * @param $container - */ - abstract public function initialise($container); + abstract public function initialise(Registry $doctrine, Manager $mapping); /** * @abstract @@ -501,6 +496,16 @@ public function populateSelectFiltersFromData($columns, $loop = false) case 'datetime': case 'date': case 'time': + // For document + if ($value instanceof \MongoDate || $value instanceof \MongoTimestamp) { + $value = $value->sec; + } + + // Mongodb bug ? timestamp value is on the key 'i' instead of the key 't' + if (is_array($value) && array_keys($value) == ['t', 'i']) { + $value = $value['i']; + } + $displayedValue = $column->getDisplayedValue($value); $values[$displayedValue] = $displayedValue; break; diff --git a/src/Grid/Source/Vector.php b/src/Grid/Source/Vector.php index 8a06bdd..cceb723 100644 --- a/src/Grid/Source/Vector.php +++ b/src/Grid/Source/Vector.php @@ -20,7 +20,9 @@ use APY\DataGridBundle\Grid\Column\NumberColumn; use APY\DataGridBundle\Grid\Column\TextColumn; use APY\DataGridBundle\Grid\Column\UntypedColumn; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Rows; +use Doctrine\Bundle\DoctrineBundle\Registry; /** * Vector is really an Array. @@ -64,7 +66,7 @@ public function __construct(array $data, array $columns = []) $this->setColumns($columns); } - public function initialise($container) + public function initialise(Registry $doctrine, Manager $mapping) { if (!empty($this->data)) { $this->guessColumns(); diff --git a/src/Resources/config/grid.yml b/src/Resources/config/grid.yml index c6f32ff..f7de704 100644 --- a/src/Resources/config/grid.yml +++ b/src/Resources/config/grid.yml @@ -2,8 +2,8 @@ services: # Core apy_grid.factory: class: APY\DataGridBundle\Grid\GridFactory -# arguments: ['@service_container', '@apy_grid.registry'] - arguments: ['@security.authorization_checker', '@router', '@request_stack', '@twig', '@http_kernel', '@apy_grid.registry'] + # arguments: ['@service_container', '@apy_grid.registry'] + arguments: ['@security.authorization_checker', '@router', '@request_stack', '@twig', '@http_kernel', '@doctrine', '@grid.mapping.manager', '@kernel', '@translator', '@apy_grid.registry'] apy_grid.registry: class: APY\DataGridBundle\Grid\GridRegistry @@ -11,46 +11,46 @@ services: apy_grid.type.grid: class: APY\DataGridBundle\Grid\Type\GridType tags: - - { name: apy_grid.type } + - {name: apy_grid.type} # Columns apy_grid.column.text: class: APY\DataGridBundle\Grid\Column\TextColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} apy_grid.column.array: class: APY\DataGridBundle\Grid\Column\ArrayColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} apy_grid.column.blank: class: APY\DataGridBundle\Grid\Column\BlankColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} apy_grid.column.boolean: class: APY\DataGridBundle\Grid\Column\BooleanColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} apy_grid.column.date: class: APY\DataGridBundle\Grid\Column\DateColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} apy_grid.column.date_time: class: APY\DataGridBundle\Grid\Column\DateTimeColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} apy_grid.column.join: class: APY\DataGridBundle\Grid\Column\JoinColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} apy_grid.column.number: class: APY\DataGridBundle\Grid\Column\NumberColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} apy_grid.column.rank: class: APY\DataGridBundle\Grid\Column\RankColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} apy_grid.column.time: class: APY\DataGridBundle\Grid\Column\TimeColumn tags: - - { name: apy_grid.column } + - {name: apy_grid.column} diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 2cd8bf8..ff7000a 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -27,6 +27,11 @@ + + + + + %apy_data_grid.limits% diff --git a/src/Translation/ColumnTitleAnnotationTranslationExtractor.php b/src/Translation/ColumnTitleAnnotationTranslationExtractor.php index 90a9847..486dfde 100644 --- a/src/Translation/ColumnTitleAnnotationTranslationExtractor.php +++ b/src/Translation/ColumnTitleAnnotationTranslationExtractor.php @@ -12,17 +12,12 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -class ColumnTitleAnnotationTranslationExtractor implements FileVisitorInterface, \PHPParser_NodeVisitor, ContainerAwareInterface +class ColumnTitleAnnotationTranslationExtractor implements FileVisitorInterface, \PHPParser_NodeVisitor { private $annotated; private $catalogue; private $parsedClassName; - /** - * @var ContainerInterface - */ - private $container; - public function beforeTraverse(array $nodes) { $this->annotated = false; @@ -68,7 +63,7 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar if ($this->annotated) { // Get annotations for the class $annotationDriver = new Annotation(new DoctrineAnnotationReader()); - $manager = new Manager($this->container); + $manager = new Manager(); $manager->addDriver($annotationDriver, -1); $metadata = $manager->getMetadata($this->parsedClassName); @@ -87,12 +82,4 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, \Twig_Node $node) { } - - /** - * {@inheritdoc} - */ - public function setContainer(ContainerInterface $container = null) - { - $this->container = $container; - } } From 240a363ebe37f6171fc30e4d4657a622f88345bb Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Mon, 30 Jan 2023 12:59:51 -0500 Subject: [PATCH 07/38] Update required symfony versions --- composer.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index c5cd4cc..6221189 100644 --- a/composer.json +++ b/composer.json @@ -7,22 +7,22 @@ "license": "MIT", "require": { "php": ">=7.4", - "symfony/form": "^5.2|^6.0", - "symfony/dependency-injection": "^5.2|^6.0", - "symfony/config": "^5.2|^6.0", - "symfony/http-foundation": "^5.2|^6.0", - "symfony/http-kernel": "^5.2|^6.0", - "symfony/options-resolver": "^5.2|^6.0", - "symfony/security-core": "^5.2|^6.0", - "symfony/serializer": "^5.2|^6.0", + "symfony/form": "^5.2|^6.2", + "symfony/dependency-injection": "^5.2|^6.2", + "symfony/config": "^5.2|^6.2", + "symfony/http-foundation": "^5.2|^6.2", + "symfony/http-kernel": "^5.2|^6.2", + "symfony/options-resolver": "^5.2|^6.2", + "symfony/security-core": "^5.2|^6.2", + "symfony/serializer": "^5.2|^6.2", "twig/twig": "^2.4|^3.0" }, "require-dev": { "ext-intl": "*", "dg/bypass-finals": "^1.2", - "symfony/framework-bundle": "^5.2|^6.0", - "symfony/expression-language": "^5.2|^6.0", - "symfony/phpunit-bridge": "^5.2|^6.0", + "symfony/framework-bundle": "^5.2|^6.2", + "symfony/expression-language": "^5.2|^6.2", + "symfony/phpunit-bridge": "^5.2|^6.2", "phpunit/phpunit": "^8.5", "doctrine/orm": "~2.4,>=2.4.5", }, From ae76214770a9a38a95b10b544e70a064363aa84f Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Mon, 30 Jan 2023 13:57:00 -0500 Subject: [PATCH 08/38] Update function definition to be compatible with parent --- src/Grid/Mapping/Metadata/DriverHeap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grid/Mapping/Metadata/DriverHeap.php b/src/Grid/Mapping/Metadata/DriverHeap.php index 2b22a7e..10d3764 100644 --- a/src/Grid/Mapping/Metadata/DriverHeap.php +++ b/src/Grid/Mapping/Metadata/DriverHeap.php @@ -21,7 +21,7 @@ class DriverHeap extends \SplPriorityQueue * * @see SplPriorityQueue::compare() */ - public function compare($priority1, $priority2) + public function compare($priority1, $priority2): int { if ($priority1 === $priority2) { return 0; From 5ab8fd9b03e6a4ad7f0d528d667bf8e33bb11869 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Mon, 30 Jan 2023 16:45:42 -0500 Subject: [PATCH 09/38] Add return types to function declarations --- src/DependencyInjection/Configuration.php | 2 +- src/Grid/Columns.php | 5 +++-- src/Grid/Helper/ColumnsIterator.php | 2 +- src/Grid/Rows.php | 6 ++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 7b94c37..e2d83b4 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -15,7 +15,7 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('apy_data_grid'); $rootNode = $treeBuilder->getRootNode(); diff --git a/src/Grid/Columns.php b/src/Grid/Columns.php index d0b0201..639e068 100644 --- a/src/Grid/Columns.php +++ b/src/Grid/Columns.php @@ -16,6 +16,7 @@ use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Helper\ColumnsIterator; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Traversable; class Columns implements \IteratorAggregate, \Countable { @@ -42,7 +43,7 @@ public function __construct(AuthorizationCheckerInterface $authorizationChecker) * * @return ColumnsIterator */ - public function getIterator($showOnlySourceColumns = false) + public function getIterator($showOnlySourceColumns = false): Traversable { return new ColumnsIterator(new \ArrayIterator($this->columns), $showOnlySourceColumns); } @@ -128,7 +129,7 @@ public function getPrimaryColumn() /** * @return int */ - public function count() + public function count(): int { return count($this->columns); } diff --git a/src/Grid/Helper/ColumnsIterator.php b/src/Grid/Helper/ColumnsIterator.php index 6bb508d..a541bde 100644 --- a/src/Grid/Helper/ColumnsIterator.php +++ b/src/Grid/Helper/ColumnsIterator.php @@ -28,7 +28,7 @@ public function __construct(\Iterator $iterator, $showOnlySourceColumns) $this->showOnlySourceColumns = $showOnlySourceColumns; } - public function accept() + public function accept(): bool { $current = $this->getInnerIterator()->current(); diff --git a/src/Grid/Rows.php b/src/Grid/Rows.php index 495232c..fea6590 100644 --- a/src/Grid/Rows.php +++ b/src/Grid/Rows.php @@ -12,6 +12,8 @@ namespace APY\DataGridBundle\Grid; +use Traversable; + class Rows implements \IteratorAggregate, \Countable { /** @var \SplObjectStorage */ @@ -34,7 +36,7 @@ public function __construct(array $rows = []) * * @see IteratorAggregate::getIterator() */ - public function getIterator() + public function getIterator(): Traversable { return $this->rows; } @@ -58,7 +60,7 @@ public function addRow(Row $row) * * @see Countable::count() */ - public function count() + public function count(): int { return $this->rows->count(); } From aa63bb3cfa3c8394794789aad4dff5513ac26347 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 1 Feb 2023 13:05:05 -0500 Subject: [PATCH 10/38] Remove usage of internal trait --- src/Grid/Source/Entity.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Grid/Source/Entity.php b/src/Grid/Source/Entity.php index 2283a85..f4c801c 100644 --- a/src/Grid/Source/Entity.php +++ b/src/Grid/Source/Entity.php @@ -19,7 +19,10 @@ use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Rows; use Doctrine\Bundle\DoctrineBundle\Registry; -use Doctrine\ORM\Internal\SQLResultCasing; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\DB2Platform; +use Doctrine\DBAL\Platforms\OraclePlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\ORM\NoResultException; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; @@ -31,8 +34,6 @@ class Entity extends Source { - use SQLResultCasing; - public const HINT_QUERY_HAS_FETCH_JOIN = 'grid.hasFetchJoin'; const DOT_DQL_ALIAS_PH = '__dot__'; @@ -894,4 +895,21 @@ protected function checkIfQueryHasFetchJoin(QueryBuilder $qb) return false; } + + private function getSQLResultCasing(AbstractPlatform $platform, string $column): string + { + if ($platform instanceof DB2Platform || $platform instanceof OraclePlatform) { + return strtoupper($column); + } + + if ($platform instanceof PostgreSQLPlatform) { + return strtolower($column); + } + + if (method_exists(AbstractPlatform::class, 'getSQLResultCasing')) { + return $platform->getSQLResultCasing($column); + } + + return $column; + } } From 14bf8328eeaf75e33e4733568338bff74004257d Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 8 Feb 2023 11:15:48 -0500 Subject: [PATCH 11/38] Update tests to work with Symfony 6 changes --- composer.json | 3 +- src/Grid/Column/Column.php | 2 +- src/Grid/Export/ExportInterface.php | 2 + src/Grid/Grid.php | 17 +++--- src/Grid/GridBuilder.php | 8 +-- src/Grid/GridFactory.php | 9 ++-- src/Grid/Source/Entity.php | 4 +- src/Grid/Source/Source.php | 4 +- src/Grid/Source/Vector.php | 4 +- src/Resources/config/services.xml | 1 - tests/Grid/GridBuilderTest.php | 49 ++++++------------ tests/Grid/GridFactoryTest.php | 80 ++++++++++++----------------- tests/Grid/GridTest.php | 78 +++++++++++++++------------- tests/Grid/Source/VectorTest.php | 11 ++-- 14 files changed, 125 insertions(+), 147 deletions(-) diff --git a/composer.json b/composer.json index 04f3463..27f7be5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "symfony/options-resolver": "^5.2|^6.2", "symfony/security-core": "^5.2|^6.2", "symfony/serializer": "^5.2|^6.2", - "twig/twig": "^2.4|^3.0" + "twig/twig": "^2.4|^3.0", + "symfony/translation": "^5.2|^6.2" }, "require-dev": { "ext-intl": "*", diff --git a/src/Grid/Column/Column.php b/src/Grid/Column/Column.php index c887e95..e97a21c 100644 --- a/src/Grid/Column/Column.php +++ b/src/Grid/Column/Column.php @@ -240,7 +240,7 @@ public function manipulateRenderCell($callback) return $this; } - public function getCallback(): mixed { + public function getCallback() { return $this->callback; } diff --git a/src/Grid/Export/ExportInterface.php b/src/Grid/Export/ExportInterface.php index 364c164..36c4e92 100644 --- a/src/Grid/Export/ExportInterface.php +++ b/src/Grid/Export/ExportInterface.php @@ -12,6 +12,8 @@ namespace APY\DataGridBundle\Grid\Export; +use Twig\Environment; + interface ExportInterface { /** diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index 2eca2ab..2d795b1 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -13,24 +13,24 @@ namespace APY\DataGridBundle\Grid; -use App\Kernel; use APY\DataGridBundle\Grid\Action\MassActionInterface; use APY\DataGridBundle\Grid\Action\RowActionInterface; use APY\DataGridBundle\Grid\Column\ActionsColumn; use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Column\MassActionColumn; +use APY\DataGridBundle\Grid\Export\Export; use APY\DataGridBundle\Grid\Export\ExportInterface; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Source\Entity; use APY\DataGridBundle\Grid\Source\Source; -use Doctrine\Bundle\DoctrineBundle\Registry; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\DependencyInjection\Container; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Translation\DataCollectorTranslator; @@ -355,16 +355,13 @@ public function __construct( RequestStack $requestStack, Environment $twig, HttpKernelInterface $httpKernel, - Registry $doctrine, + ManagerRegistry $doctrine, Manager $mapping, - Kernel $kernel, + KernelInterface $kernel, DataCollectorTranslator $translator, - // $container, $id = '', GridConfigInterface $config = null ) { - // @todo: why the whole container is injected? - // $this->container = $container; $this->config = $config; $this->router = $router; @@ -374,7 +371,7 @@ public function __construct( $this->httpKernel = $httpKernel; $this->doctrine = $doctrine; $this->mapping = $mapping; - $this->kernelCharset = $kernel->getCharset(); + $this->kernelCharset = $kernel->getCharset() ?? 'UTF-8'; $this->translator = $translator; if (null === $this->request) { @@ -754,7 +751,7 @@ protected function processExports($exportId) $export = $this->exports[$exportId]; - if ($export instanceof ExportInterface) { + if ($export instanceof Export) { $export->setTwig($this->twig) ->setTranslator($this->translator) ->setRouter($this->router) diff --git a/src/Grid/GridBuilder.php b/src/Grid/GridBuilder.php index 7687d91..604446e 100644 --- a/src/Grid/GridBuilder.php +++ b/src/Grid/GridBuilder.php @@ -2,15 +2,15 @@ namespace APY\DataGridBundle\Grid; -use App\Kernel; use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Exception\InvalidArgumentException; use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; -use Doctrine\Bundle\DoctrineBundle\Registry; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Translation\DataCollectorTranslator; @@ -76,9 +76,9 @@ public function __construct( RequestStack $requestStack, Environment $twig, HttpKernelInterface $httpKernel, - Registry $doctrine, + ManagerRegistry $doctrine, Manager $mapping, - Kernel $kernel, + KernelInterface $kernel, DataCollectorTranslator $translator, // Container $container, GridFactoryInterface $factory, diff --git a/src/Grid/GridFactory.php b/src/Grid/GridFactory.php index 3e99850..07a059d 100644 --- a/src/Grid/GridFactory.php +++ b/src/Grid/GridFactory.php @@ -2,15 +2,14 @@ namespace APY\DataGridBundle\Grid; -use App\Kernel; use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Source\Source; -use Doctrine\Bundle\DoctrineBundle\Registry; -use Symfony\Component\DependencyInjection\Container; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -53,9 +52,9 @@ public function __construct( RequestStack $requestStack, Environment $twig, HttpKernelInterface $httpKernel, - Registry $doctrine, + ManagerRegistry $doctrine, Manager $mapping, - Kernel $kernel, + KernelInterface $kernel, DataCollectorTranslator $translator, GridRegistryInterface $registry ) { diff --git a/src/Grid/Source/Entity.php b/src/Grid/Source/Entity.php index f4c801c..68c6648 100644 --- a/src/Grid/Source/Entity.php +++ b/src/Grid/Source/Entity.php @@ -18,7 +18,6 @@ use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Rows; -use Doctrine\Bundle\DoctrineBundle\Registry; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Platforms\OraclePlatform; @@ -30,6 +29,7 @@ use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Tools\Pagination\CountWalker; use Doctrine\ORM\Tools\Pagination\Paginator; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\HttpKernel\Kernel; class Entity extends Source @@ -144,7 +144,7 @@ public function __construct($entityName, $group = 'default', $managerName = null $this->setTableAlias(self::TABLE_ALIAS); } - public function initialise(Registry $doctrine, Manager $mapping) + public function initialise(ManagerRegistry $doctrine, Manager $mapping) { $this->manager = version_compare(Kernel::VERSION, '2.1.0', '>=') ? $doctrine->getManager($this->managerName) : $doctrine->getEntityManager($this->managerName); $this->ormMetadata = $this->manager->getClassMetadata($this->entityName); diff --git a/src/Grid/Source/Source.php b/src/Grid/Source/Source.php index cee8aa9..f442990 100644 --- a/src/Grid/Source/Source.php +++ b/src/Grid/Source/Source.php @@ -19,7 +19,7 @@ use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Rows; -use Doctrine\Bundle\DoctrineBundle\Registry; +use Doctrine\Persistence\ManagerRegistry; abstract class Source implements DriverInterface { @@ -99,7 +99,7 @@ abstract public function execute($columns, $page = 0, $limit = 0, $maxResults = */ abstract public function getTotalCount($maxResults = null); - abstract public function initialise(Registry $doctrine, Manager $mapping); + abstract public function initialise(ManagerRegistry $doctrine, Manager $mapping); /** * @abstract diff --git a/src/Grid/Source/Vector.php b/src/Grid/Source/Vector.php index 7d50843..47ec9c9 100644 --- a/src/Grid/Source/Vector.php +++ b/src/Grid/Source/Vector.php @@ -22,7 +22,7 @@ use APY\DataGridBundle\Grid\Column\UntypedColumn; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Rows; -use Doctrine\Bundle\DoctrineBundle\Registry; +use Doctrine\Persistence\ManagerRegistry; /** * Vector is really an Array. @@ -66,7 +66,7 @@ public function __construct(array $data, array $columns = []) $this->setColumns($columns); } - public function initialise(Registry $doctrine, Manager $mapping) + public function initialise(ManagerRegistry $doctrine, Manager $mapping) { if (!empty($this->data)) { $this->guessColumns(); diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index ff7000a..9bd2299 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -21,7 +21,6 @@ - diff --git a/tests/Grid/GridBuilderTest.php b/tests/Grid/GridBuilderTest.php index 0c4cae2..3782068 100755 --- a/tests/Grid/GridBuilderTest.php +++ b/tests/Grid/GridBuilderTest.php @@ -8,24 +8,22 @@ use APY\DataGridBundle\Grid\Grid; use APY\DataGridBundle\Grid\GridBuilder; use APY\DataGridBundle\Grid\GridFactoryInterface; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; +use Doctrine\Persistence\ManagerRegistry; use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\Container; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Translation\DataCollectorTranslator; +use Twig\Environment; /** * Class GridBuilderTest. */ class GridBuilderTest extends TestCase { - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $container; - /** * @var \PHPUnit\Framework\MockObject\MockObject */ @@ -41,33 +39,18 @@ class GridBuilderTest extends TestCase */ protected function setUp(): void { - $self = $this; - - $this->container = $this->createMock(Container::class); - $this->container->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($param) use ($self) { - switch ($param) { - case 'router': - return $self->createMock(RouterInterface::class); - break; - case 'request_stack': - $request = new Request([], [], ['key' => 'value']); - $session = new Session(); - $request->setSession($session); - $requestStack = new RequestStack(); - $requestStack->push($request); - - return $requestStack; - break; - case 'security.authorization_checker': - return $self->createMock(AuthorizationCheckerInterface::class); - break; - } - })); + $auth = $this->createMock(AuthorizationCheckerInterface::class); + $router = $this->createMock(RouterInterface::class); + $requestStack = $this->createMock(RequestStack::class); + $twig = $this->createMock(Environment::class); + $httpKernel = $this->createMock(HttpKernelInterface::class); + $registry = $this->createMock(ManagerRegistry::class); + $manager = $this->createMock(Manager::class); + $kernel = $this->createMock(KernelInterface::class); + $translator = $this->createMock(DataCollectorTranslator::class); $this->factory = $this->createMock(GridFactoryInterface::class); - $this->builder = new GridBuilder($this->container, $this->factory, 'name'); + $this->builder = new GridBuilder($auth, $router, $requestStack, $twig, $httpKernel, $registry, $manager, $kernel, $translator, $this->factory, 'name'); } protected function tearDown(): void diff --git a/tests/Grid/GridFactoryTest.php b/tests/Grid/GridFactoryTest.php index 75915e3..3c60505 100755 --- a/tests/Grid/GridFactoryTest.php +++ b/tests/Grid/GridFactoryTest.php @@ -10,26 +10,24 @@ use APY\DataGridBundle\Grid\GridFactory; use APY\DataGridBundle\Grid\GridRegistryInterface; use APY\DataGridBundle\Grid\GridTypeInterface; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Type\GridType; +use Doctrine\Persistence\ManagerRegistry; use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\Container; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Translation\DataCollectorTranslator; +use Twig\Environment; /** * Class GridFactoryTest. */ class GridFactoryTest extends TestCase { - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $container; - /** * @var \PHPUnit\Framework\MockObject\MockObject */ @@ -47,34 +45,19 @@ class GridFactoryTest extends TestCase protected function setUp(): void { - $self = $this; - - $this->container = $this->createMock(Container::class); - $this->container->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($param) use ($self) { - switch ($param) { - case 'router': - return $self->createMock(RouterInterface::class); - break; - case 'request_stack': - $request = new Request([], [], ['key' => 'value']); - $session = new Session(); - $request->setSession($session); - $requestStack = new RequestStack(); - $requestStack->push($request); - - return $requestStack; - break; - case 'security.authorization_checker': - return $self->createMock(AuthorizationCheckerInterface::class); - break; - } - })); - + $auth = $this->createMock(AuthorizationCheckerInterface::class); + $router = $this->createMock(RouterInterface::class); + $requestStack = $this->createMock(RequestStack::class); + $twig = $this->createMock(Environment::class); + $httpKernel = $this->createMock(HttpKernelInterface::class); + $registry = $this->createMock(ManagerRegistry::class); + $manager = $this->createMock(Manager::class); + $kernel = $this->createMock(KernelInterface::class); + $translator = $this->createMock(DataCollectorTranslator::class); $this->registry = $this->createMock(GridRegistryInterface::class); - $this->builder = $this->createMock(GridBuilderInterface::class); - $this->factory = new GridFactory($this->container, $this->registry); + $this->builder = $this->createMock(GridBuilderInterface::class); + + $this->factory = new GridFactory($auth, $router, $requestStack, $twig, $httpKernel, $registry, $manager, $kernel, $translator, $this->registry); } public function testCreateWithUnexpectedType() @@ -118,7 +101,7 @@ public function testCreateBuilderWithDefaultType() public function testCreateBuilder() { - $givenOptions = ['a' => 1, 'b' => 2]; + $givenOptions = ['a' => 1, 'b' => 2]; $resolvedOptions = ['a' => 1, 'b' => 2, 'c' => 3]; $type = $this->createMock(GridTypeInterface::class); @@ -129,21 +112,26 @@ public function testCreateBuilder() $type->expects($this->once()) ->method('configureOptions') - ->with($this->callback(function ($resolver) use ($resolvedOptions) { - if (!$resolver instanceof OptionsResolver) { - return false; - } + ->with( + $this->callback(function ($resolver) use ($resolvedOptions) { + if (!$resolver instanceof OptionsResolver) { + return false; + } - $resolver->setDefaults($resolvedOptions); + $resolver->setDefaults($resolvedOptions); - return true; - })); + return true; + }) + ); $type->expects($this->once()) ->method('buildGrid') - ->with($this->callback(function ($builder) { - return $builder instanceof GridBuilder && $builder->getName() == 'TYPE'; - }), $resolvedOptions); + ->with( + $this->callback(function ($builder) { + return $builder instanceof GridBuilder && $builder->getName() == 'TYPE'; + }), + $resolvedOptions + ); $builder = $this->factory->createBuilder($type, null, $givenOptions); diff --git a/tests/Grid/GridTest.php b/tests/Grid/GridTest.php index ad231ab..ba240f8 100644 --- a/tests/Grid/GridTest.php +++ b/tests/Grid/GridTest.php @@ -14,12 +14,13 @@ use APY\DataGridBundle\Grid\Grid; use APY\DataGridBundle\Grid\GridConfigInterface; use APY\DataGridBundle\Grid\Helper\ColumnsIterator; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Rows; use APY\DataGridBundle\Grid\Source\Entity; use APY\DataGridBundle\Grid\Source\Source; +use Doctrine\Persistence\ManagerRegistry; use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\HeaderBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -28,8 +29,11 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpKernel\HttpKernel; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\Router; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Translation\DataCollectorTranslator; use Twig\Environment; use Twig\TemplateWrapper; @@ -55,6 +59,16 @@ class GridTest extends TestCase */ private $authChecker; + /** + * @var \PHPUnit\Framework\MockObject\MockObject + */ + private $registry; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject + */ + private $manager; + /** * @var \PHPUnit\Framework\MockObject\MockObject */ @@ -244,7 +258,7 @@ public function testInitializeNotEntitySource() $source ->expects($this->once()) ->method('initialise') - ->with($this->container); + ->with($this->registry, $this->manager); $this->grid->initialize(); } @@ -263,7 +277,7 @@ public function testInitializeEntitySourceWithoutGroupByFunction() $source ->expects($this->once()) ->method('initialise') - ->with($this->container); + ->with($this->registry, $this->manager); $source ->expects($this->never()) ->method('setGroupBy'); @@ -290,7 +304,7 @@ public function testInitializeEntitySourceWithoutGroupByScalarValue() $source ->expects($this->once()) ->method('initialise') - ->with($this->container); + ->with($this->registry, $this->manager); $source ->expects($this->atLeastOnce()) ->method('setGroupBy') @@ -318,7 +332,7 @@ public function testInitializeEntitySourceWithoutGroupByArrayValues() $source ->expects($this->once()) ->method('initialise') - ->with($this->container); + ->with($this->registry, $this->manager); $source ->expects($this->atLeastOnce()) ->method('setGroupBy') @@ -431,7 +445,7 @@ public function testSetSource() $source ->expects($this->once()) ->method('initialise') - ->with($this->container); + ->with($this->registry, $this->manager); $source ->expects($this->once()) ->method('getColumns') @@ -4435,27 +4449,27 @@ private function arrange($gridConfigInterface = null, $id = 'id', $httpKernel = $environment = $this->createMock(Environment::class); $this->environment = $environment; - $containerGetMap = [ - ['router', Container::EXCEPTION_ON_INVALID_REFERENCE, $this->router], - ['request_stack', Container::EXCEPTION_ON_INVALID_REFERENCE, $this->requestStack], - ['security.authorization_checker', Container::EXCEPTION_ON_INVALID_REFERENCE, $this->authChecker], - ['http_kernel', Container::EXCEPTION_ON_INVALID_REFERENCE, $httpKernel], - ['twig', Container::EXCEPTION_ON_INVALID_REFERENCE, $this->environment], - ]; - - $container = $this - ->getMockBuilder(Container::class) - ->disableOriginalConstructor() - ->getMock(); - $container - ->method('get') - ->will($this->returnValueMap($containerGetMap)); - $this->container = $container; + $this->registry = $this->createMock(ManagerRegistry::class); + $this->manager = $this->createMock(Manager::class); + $kernel = $this->createMock(KernelInterface::class); + $translator = $this->createMock(DataCollectorTranslator::class); $this->gridId = $id; $this->gridHash = 'grid_' . $this->gridId; - $this->grid = new Grid($container, $this->gridId, $gridConfigInterface); + $this->grid = new Grid( + $this->authChecker, + $this->router, + $this->requestStack, + $this->environment, + $httpKernel ?? $this->createMock(HttpKernelInterface::class), + $this->registry, + $this->manager, + $kernel, + $translator, + $this->gridId, + $gridConfigInterface + ); } private function mockResetGridSessionWhenResetFilterIsPressed() @@ -4735,10 +4749,12 @@ private function mockMassActionControllerResponse() $this->arrangeGridSourceDataLoadedWithRows($rows); $this->arrangeGridPrimaryColumn(); - $this->stubRequestWithData([ - Grid::REQUEST_QUERY_MASS_ACTION => 0, - Grid::REQUEST_QUERY_MASS_ACTION_ALL_KEYS_SELECTED => true, - ]); + $this->stubRequestWithData( + [ + Grid::REQUEST_QUERY_MASS_ACTION => 0, + Grid::REQUEST_QUERY_MASS_ACTION_ALL_KEYS_SELECTED => true, + ] + ); $controllerCb = 'VendorBundle:Controller:Action'; $param1 = 'param1'; @@ -4797,10 +4813,6 @@ private function mockExports() ->expects($this->once()) ->method('computeData') ->with($this->grid); - $export - ->expects($this->once()) - ->method('setContainer') - ->with($this->container); return $response; } @@ -4849,10 +4861,6 @@ private function mockExportsButNotFiltersPageOrderLimit() ->expects($this->once()) ->method('computeData') ->with($this->grid); - $export - ->expects($this->once()) - ->method('setContainer') - ->with($this->container); $this ->session diff --git a/tests/Grid/Source/VectorTest.php b/tests/Grid/Source/VectorTest.php index 4fa7e83..d4c52a4 100644 --- a/tests/Grid/Source/VectorTest.php +++ b/tests/Grid/Source/VectorTest.php @@ -5,10 +5,11 @@ use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Column\UntypedColumn; use APY\DataGridBundle\Grid\Columns; +use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Source\Vector; +use Doctrine\Persistence\ManagerRegistry; use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\Container; class VectorTest extends TestCase { @@ -54,7 +55,7 @@ public function testCreateVectorWithColumns() public function testInitialiseWithoutData() { - $this->vector->initialise($this->createMock(Container::class)); + $this->vector->initialise($this->createMock(ManagerRegistry::class), $this->createMock(Manager::class)); $this->assertEmpty($this->vector->getColumnsArray()); } @@ -102,7 +103,7 @@ public function testInizialiseWithGuessedColumnsMergedToAlreadySettedColumns() ); $uc2->setType('text'); - $vector->initialise($this->createMock(Container::class)); + $vector->initialise($this->createMock(ManagerRegistry::class), $this->createMock(Manager::class)); $this->assertEquals([$column, $column2, $uc1, $uc2], $vector->getColumnsArray()); } @@ -123,7 +124,7 @@ public function testInizialiseWithoutGuessedColumns() $vector = new Vector([[$columnId => 'c1', $column2Id => 'c2']], [$column, $column2]); - $vector->initialise($this->createMock(Container::class)); + $vector->initialise($this->createMock(ManagerRegistry::class), $this->createMock(Manager::class)); $this->assertEquals([$column, $column2], $vector->getColumnsArray()); } @@ -136,7 +137,7 @@ public function testInizializeWithGuessedColumn($vectorValue, UntypedColumn $unt $untypedColumn->setType($columnType); $vector = new Vector($vectorValue); - $vector->initialise($this->createMock(Container::class)); + $vector->initialise($this->createMock(ManagerRegistry::class), $this->createMock(Manager::class)); $this->assertEquals([$untypedColumn], $vector->getColumnsArray()); } From 990b7618e53377148d29cb234246f09a91b85804 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 8 Feb 2023 11:27:53 -0500 Subject: [PATCH 12/38] Various clean up --- src/Grid/Column/Column.php | 2 +- src/Grid/Columns.php | 3 +-- src/Grid/Export/Export.php | 6 +++--- src/Grid/Export/ExportInterface.php | 2 -- src/Grid/Grid.php | 15 +++++++------ src/Grid/GridBuilder.php | 27 ++++++++--------------- src/Grid/GridFactory.php | 33 ++++++++++++++++------------- src/Grid/Rows.php | 4 +--- src/Resources/config/grid.yml | 23 ++++++++++---------- 9 files changed, 52 insertions(+), 63 deletions(-) diff --git a/src/Grid/Column/Column.php b/src/Grid/Column/Column.php index e97a21c..c887e95 100644 --- a/src/Grid/Column/Column.php +++ b/src/Grid/Column/Column.php @@ -240,7 +240,7 @@ public function manipulateRenderCell($callback) return $this; } - public function getCallback() { + public function getCallback(): mixed { return $this->callback; } diff --git a/src/Grid/Columns.php b/src/Grid/Columns.php index cbe9f6f..ba745aa 100644 --- a/src/Grid/Columns.php +++ b/src/Grid/Columns.php @@ -16,7 +16,6 @@ use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Helper\ColumnsIterator; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Traversable; class Columns implements \IteratorAggregate, \Countable { @@ -43,7 +42,7 @@ public function __construct(AuthorizationCheckerInterface $authorizationChecker) * * @return ColumnsIterator */ - public function getIterator($showOnlySourceColumns = false): Traversable + public function getIterator($showOnlySourceColumns = false): \Traversable { return new ColumnsIterator(new \ArrayIterator($this->columns), $showOnlySourceColumns); } diff --git a/src/Grid/Export/Export.php b/src/Grid/Export/Export.php index 6c30207..7d5ae8a 100644 --- a/src/Grid/Export/Export.php +++ b/src/Grid/Export/Export.php @@ -36,11 +36,11 @@ abstract class Export implements ExportInterface protected $twig; - private $translator; + private DataCollectorTranslator $translator; - private $router; + private RouterInterface $router; - private $kernelCharset; + private string $kernelCharset; protected $grid; diff --git a/src/Grid/Export/ExportInterface.php b/src/Grid/Export/ExportInterface.php index 36c4e92..364c164 100644 --- a/src/Grid/Export/ExportInterface.php +++ b/src/Grid/Export/ExportInterface.php @@ -12,8 +12,6 @@ namespace APY\DataGridBundle\Grid\Export; -use Twig\Environment; - interface ExportInterface { /** diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index 2d795b1..d1ac2b2 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -79,17 +79,17 @@ class Grid implements GridInterface */ protected $router; - private $twig; + private Environment $twig; - private $httpKernel; + private HttpKernelInterface $httpKernel; - private $doctrine; + private ManagerRegistry $doctrine; - private $mapping; + private Manager $mapping; - private $kernelCharset; + private DataCollectorTranslator $translator; - private $translator; + private string $kernelCharset; /** * @var null|\Symfony\Component\HttpFoundation\Session\Session; @@ -1383,7 +1383,8 @@ public function getTweaks() return $this->tweaks; } - public function getAllTweaks(): ?array { + public function getAllTweaks(): ?array + { return $this->tweaks; } diff --git a/src/Grid/GridBuilder.php b/src/Grid/GridBuilder.php index 604446e..5630331 100644 --- a/src/Grid/GridBuilder.php +++ b/src/Grid/GridBuilder.php @@ -23,30 +23,23 @@ */ class GridBuilder extends GridConfigBuilder implements GridBuilderInterface { - /** - * The container. - * - * @var Container - */ - private $container; - - private $authorizationChecker; + private AuthorizationCheckerInterface $authorizationChecker; - private $router; + private RouterInterface $router; - private $requestStack; + private RequestStack $requestStack; - private $twig; + private Environment $twig; - private $httpKernel; + private HttpKernelInterface $httpKernel; - private $doctrine; + private ManagerRegistry $doctrine; - private $mapping; + private Manager $mapping; - private $kernel; + private KernelInterface $kernel; - private $translator; + private DataCollectorTranslator $translator; /** * The factory. @@ -80,14 +73,12 @@ public function __construct( Manager $mapping, KernelInterface $kernel, DataCollectorTranslator $translator, - // Container $container, GridFactoryInterface $factory, $name, array $options = [] ) { parent::__construct($name, $options); - // $this->container = $container; $this->authorizationChecker = $authorizationChecker; $this->router = $router; $this->requestStack = $requestStack; diff --git a/src/Grid/GridFactory.php b/src/Grid/GridFactory.php index 07a059d..0488498 100644 --- a/src/Grid/GridFactory.php +++ b/src/Grid/GridFactory.php @@ -28,23 +28,23 @@ class GridFactory implements GridFactoryInterface */ private $registry; - private $authorizationChecker; + private AuthorizationCheckerInterface $authorizationChecker; - private $router; + private RouterInterface $router; - private $requestStack; + private RequestStack $requestStack; - private $twig; + private Environment $twig; - private $httpKernel; + private HttpKernelInterface $httpKernel; - private $doctrine; + private ManagerRegistry $doctrine; - private $mapping; + private Manager $mapping; - private $kernel; + private KernelInterface $kernel; - private $translator; + private DataCollectorTranslator $translator; public function __construct( AuthorizationCheckerInterface $authorizationChecker, @@ -121,12 +121,15 @@ public function createColumn($name, $type, array $options = []) $column = clone $this->registry->getColumn($type); $column->__initialize( - array_merge([ - 'id' => $name, - 'title' => $name, - 'field' => $name, - 'source' => true, - ], $options) + array_merge( + [ + 'id' => $name, + 'title' => $name, + 'field' => $name, + 'source' => true, + ], + $options + ) ); } else { $column = $type; diff --git a/src/Grid/Rows.php b/src/Grid/Rows.php index fea6590..fbc88dc 100644 --- a/src/Grid/Rows.php +++ b/src/Grid/Rows.php @@ -12,8 +12,6 @@ namespace APY\DataGridBundle\Grid; -use Traversable; - class Rows implements \IteratorAggregate, \Countable { /** @var \SplObjectStorage */ @@ -36,7 +34,7 @@ public function __construct(array $rows = []) * * @see IteratorAggregate::getIterator() */ - public function getIterator(): Traversable + public function getIterator(): \Traversable { return $this->rows; } diff --git a/src/Resources/config/grid.yml b/src/Resources/config/grid.yml index f7de704..226f8cb 100644 --- a/src/Resources/config/grid.yml +++ b/src/Resources/config/grid.yml @@ -2,7 +2,6 @@ services: # Core apy_grid.factory: class: APY\DataGridBundle\Grid\GridFactory - # arguments: ['@service_container', '@apy_grid.registry'] arguments: ['@security.authorization_checker', '@router', '@request_stack', '@twig', '@http_kernel', '@doctrine', '@grid.mapping.manager', '@kernel', '@translator', '@apy_grid.registry'] apy_grid.registry: class: APY\DataGridBundle\Grid\GridRegistry @@ -11,46 +10,46 @@ services: apy_grid.type.grid: class: APY\DataGridBundle\Grid\Type\GridType tags: - - {name: apy_grid.type} + - { name: apy_grid.type } # Columns apy_grid.column.text: class: APY\DataGridBundle\Grid\Column\TextColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } apy_grid.column.array: class: APY\DataGridBundle\Grid\Column\ArrayColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } apy_grid.column.blank: class: APY\DataGridBundle\Grid\Column\BlankColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } apy_grid.column.boolean: class: APY\DataGridBundle\Grid\Column\BooleanColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } apy_grid.column.date: class: APY\DataGridBundle\Grid\Column\DateColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } apy_grid.column.date_time: class: APY\DataGridBundle\Grid\Column\DateTimeColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } apy_grid.column.join: class: APY\DataGridBundle\Grid\Column\JoinColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } apy_grid.column.number: class: APY\DataGridBundle\Grid\Column\NumberColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } apy_grid.column.rank: class: APY\DataGridBundle\Grid\Column\RankColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } apy_grid.column.time: class: APY\DataGridBundle\Grid\Column\TimeColumn tags: - - {name: apy_grid.column} + - { name: apy_grid.column } From 2b938a595379f6fd71d4fd874378d762141e767a Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 8 Feb 2023 12:09:56 -0500 Subject: [PATCH 13/38] Update function definitions to include return type --- src/Grid/GridManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Grid/GridManager.php b/src/Grid/GridManager.php index aa1aa98..45a5253 100644 --- a/src/Grid/GridManager.php +++ b/src/Grid/GridManager.php @@ -37,12 +37,12 @@ public function __construct($container) $this->grids = new \SplObjectStorage(); } - public function getIterator() + public function getIterator(): \Traversable { return $this->grids; } - public function count() + public function count(): int { return $this->grids->count(); } From d0fb7847bd9f529cb5bb862392b1850c0c4af729 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 8 Feb 2023 12:22:34 -0500 Subject: [PATCH 14/38] Update service definition --- src/Resources/config/services.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 9bd2299..05f85ac 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -29,7 +29,7 @@ - + %apy_data_grid.limits% From 3f9c2ac4372ac94a837de0eeb7e9667f2fa033e6 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 8 Feb 2023 12:33:26 -0500 Subject: [PATCH 15/38] Revert service ID change --- src/Resources/config/services.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 05f85ac..9bd2299 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -29,7 +29,7 @@ - + %apy_data_grid.limits% From 0f5889a1e0b33816ac860b599c8ff38fb7a07bc6 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 8 Feb 2023 12:48:27 -0500 Subject: [PATCH 16/38] Replace instances of DataCollectorTranslator with TranslatorInterface --- src/Grid/Export/Export.php | 6 +++--- src/Grid/Grid.php | 6 +++--- src/Grid/GridBuilder.php | 6 +++--- src/Grid/GridFactory.php | 6 +++--- tests/Grid/GridBuilderTest.php | 4 ++-- tests/Grid/GridFactoryTest.php | 4 ++-- tests/Grid/GridTest.php | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Grid/Export/Export.php b/src/Grid/Export/Export.php index 7d5ae8a..9a3ed26 100644 --- a/src/Grid/Export/Export.php +++ b/src/Grid/Export/Export.php @@ -15,7 +15,7 @@ use APY\DataGridBundle\Grid\Column\ArrayColumn; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; abstract class Export implements ExportInterface @@ -36,7 +36,7 @@ abstract class Export implements ExportInterface protected $twig; - private DataCollectorTranslator $translator; + private TranslatorInterface $translator; private RouterInterface $router; @@ -79,7 +79,7 @@ public function setTwig(Environment $twig): self return $this; } - public function setTranslator(DataCollectorTranslator $translator): self + public function setTranslator(TranslatorInterface $translator): self { $this->translator = $translator; diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index d1ac2b2..19ee1e8 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -33,7 +33,7 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; class Grid implements GridInterface @@ -87,7 +87,7 @@ class Grid implements GridInterface private Manager $mapping; - private DataCollectorTranslator $translator; + private TranslatorInterface $translator; private string $kernelCharset; @@ -358,7 +358,7 @@ public function __construct( ManagerRegistry $doctrine, Manager $mapping, KernelInterface $kernel, - DataCollectorTranslator $translator, + TranslatorInterface $translator, $id = '', GridConfigInterface $config = null ) { diff --git a/src/Grid/GridBuilder.php b/src/Grid/GridBuilder.php index 5630331..6a75ebf 100644 --- a/src/Grid/GridBuilder.php +++ b/src/Grid/GridBuilder.php @@ -13,7 +13,7 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; /** @@ -39,7 +39,7 @@ class GridBuilder extends GridConfigBuilder implements GridBuilderInterface private KernelInterface $kernel; - private DataCollectorTranslator $translator; + private TranslatorInterface $translator; /** * The factory. @@ -72,7 +72,7 @@ public function __construct( ManagerRegistry $doctrine, Manager $mapping, KernelInterface $kernel, - DataCollectorTranslator $translator, + TranslatorInterface $translator, GridFactoryInterface $factory, $name, array $options = [] diff --git a/src/Grid/GridFactory.php b/src/Grid/GridFactory.php index 0488498..af6207b 100644 --- a/src/Grid/GridFactory.php +++ b/src/Grid/GridFactory.php @@ -13,7 +13,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; /** @@ -44,7 +44,7 @@ class GridFactory implements GridFactoryInterface private KernelInterface $kernel; - private DataCollectorTranslator $translator; + private TranslatorInterface $translator; public function __construct( AuthorizationCheckerInterface $authorizationChecker, @@ -55,7 +55,7 @@ public function __construct( ManagerRegistry $doctrine, Manager $mapping, KernelInterface $kernel, - DataCollectorTranslator $translator, + TranslatorInterface $translator, GridRegistryInterface $registry ) { $this->authorizationChecker = $authorizationChecker; diff --git a/tests/Grid/GridBuilderTest.php b/tests/Grid/GridBuilderTest.php index 3782068..320ca77 100755 --- a/tests/Grid/GridBuilderTest.php +++ b/tests/Grid/GridBuilderTest.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; /** @@ -47,7 +47,7 @@ protected function setUp(): void $registry = $this->createMock(ManagerRegistry::class); $manager = $this->createMock(Manager::class); $kernel = $this->createMock(KernelInterface::class); - $translator = $this->createMock(DataCollectorTranslator::class); + $translator = $this->createMock(TranslatorInterface::class); $this->factory = $this->createMock(GridFactoryInterface::class); $this->builder = new GridBuilder($auth, $router, $requestStack, $twig, $httpKernel, $registry, $manager, $kernel, $translator, $this->factory, 'name'); diff --git a/tests/Grid/GridFactoryTest.php b/tests/Grid/GridFactoryTest.php index 3c60505..a006584 100755 --- a/tests/Grid/GridFactoryTest.php +++ b/tests/Grid/GridFactoryTest.php @@ -20,7 +20,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; /** @@ -53,7 +53,7 @@ protected function setUp(): void $registry = $this->createMock(ManagerRegistry::class); $manager = $this->createMock(Manager::class); $kernel = $this->createMock(KernelInterface::class); - $translator = $this->createMock(DataCollectorTranslator::class); + $translator = $this->createMock(TranslatorInterface::class); $this->registry = $this->createMock(GridRegistryInterface::class); $this->builder = $this->createMock(GridBuilderInterface::class); diff --git a/tests/Grid/GridTest.php b/tests/Grid/GridTest.php index ba240f8..6c535e0 100644 --- a/tests/Grid/GridTest.php +++ b/tests/Grid/GridTest.php @@ -33,7 +33,7 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\Router; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; use Twig\TemplateWrapper; @@ -4452,7 +4452,7 @@ private function arrange($gridConfigInterface = null, $id = 'id', $httpKernel = $this->registry = $this->createMock(ManagerRegistry::class); $this->manager = $this->createMock(Manager::class); $kernel = $this->createMock(KernelInterface::class); - $translator = $this->createMock(DataCollectorTranslator::class); + $translator = $this->createMock(TranslatorInterface::class); $this->gridId = $id; $this->gridHash = 'grid_' . $this->gridId; From 7a874e19b4f4ea515dd8bd80f0e9c8ab2f863802 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 9 Feb 2023 11:18:52 -0500 Subject: [PATCH 17/38] Remove .idea from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 011b104..e01bc6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /vendor/ -/.idea/ /.phpunit.result.cache /composer.lock /phpunit.xml From 4ed29f82661eb079ba12f47c2ba2a3e6a8ba4e0b Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Tue, 14 Feb 2023 15:48:46 -0500 Subject: [PATCH 18/38] WIP: Add types --- composer.json | 4 +- src/APYDataGridBundle.php | 2 +- .../APYDataGridExtension.php | 2 +- .../Compiler/GridExtensionPass.php | 2 +- src/DependencyInjection/Compiler/GridPass.php | 2 +- .../Compiler/TranslationPass.php | 2 +- src/Grid/AbstractType.php | 6 +- src/Grid/Action/DeleteMassAction.php | 7 +- src/Grid/Action/MassAction.php | 158 ++------- src/Grid/Action/MassActionInterface.php | 10 +- src/Grid/Action/RowAction.php | 283 +++------------ src/Grid/Action/RowActionInterface.php | 18 +- src/Grid/Column/ActionsColumn.php | 65 ++-- src/Grid/Column/ArrayColumn.php | 45 +-- src/Grid/Column/BlankColumn.php | 8 +- src/Grid/Column/BooleanColumn.php | 27 +- src/Grid/Column/Column.php | 288 ++++++++-------- src/Grid/Column/DateColumn.php | 10 +- src/Grid/Column/DateTimeColumn.php | 54 ++- src/Grid/Column/JoinColumn.php | 14 +- src/Grid/Column/MassActionColumn.php | 28 +- src/Grid/Column/NumberColumn.php | 96 +++--- src/Grid/Column/RankColumn.php | 11 +- src/Grid/Column/SimpleArrayColumn.php | 10 +- src/Grid/Column/TextColumn.php | 6 +- src/Grid/Column/TimeColumn.php | 6 +- src/Grid/Column/UntypedColumn.php | 10 +- src/Grid/Columns.php | 102 ++---- .../ColumnAlreadyExistsException.php | 7 +- .../Exception/ColumnNotFoundException.php | 7 +- .../Exception/TypeAlreadyExistsException.php | 7 +- src/Grid/Exception/TypeNotFoundException.php | 7 +- .../Exception/UnexpectedTypeException.php | 17 +- src/Grid/Export/CSVExport.php | 6 +- src/Grid/Export/DSVExport.php | 10 +- src/Grid/Export/ExcelExport.php | 8 +- src/Grid/Export/Export.php | 323 ++++-------------- src/Grid/Export/ExportInterface.php | 11 +- src/Grid/Export/JSONExport.php | 6 +- src/Grid/Export/PHPExcel2003Export.php | 2 +- src/Grid/Export/PHPExcel2007Export.php | 2 +- src/Grid/Export/PHPExcel5Export.php | 22 +- src/Grid/Export/PHPExcelHTMLExport.php | 6 +- src/Grid/Export/PHPExcelPDFExport.php | 6 +- src/Grid/Export/SCSVExport.php | 2 +- src/Grid/Export/TSVExport.php | 6 +- src/Grid/Export/XMLExport.php | 9 +- src/Grid/Filter.php | 60 ++-- src/Grid/Grid.php | 162 ++++----- src/Grid/GridBuilder.php | 34 +- src/Grid/GridBuilderInterface.php | 10 +- src/Grid/GridConfigBuilder.php | 277 +++------------ src/Grid/GridConfigBuilderInterface.php | 2 +- src/Grid/GridConfigInterface.php | 36 +- src/Grid/GridFactory.php | 31 +- src/Grid/GridFactoryInterface.php | 6 +- src/Grid/GridInterface.php | 4 +- src/Grid/GridManager.php | 57 ++-- src/Grid/GridRegistry.php | 34 +- src/Grid/GridRegistryInterface.php | 8 +- src/Grid/GridTypeInterface.php | 6 +- src/Grid/Helper/ColumnsIterator.php | 9 +- src/Grid/Helper/ORMCountWalker.php | 9 +- src/Grid/Mapping/Column.php | 13 +- src/Grid/Mapping/Driver/Annotation.php | 49 +-- src/Grid/Mapping/Driver/DriverInterface.php | 6 +- src/Grid/Mapping/Metadata/DriverHeap.php | 2 +- src/Grid/Mapping/Metadata/Manager.php | 23 +- src/Grid/Mapping/Metadata/Metadata.php | 43 ++- src/Grid/Mapping/Source.php | 39 ++- src/Grid/Row.php | 106 ++---- src/Grid/Rows.php | 22 +- src/Grid/Source/Entity.php | 238 ++++--------- src/Grid/Source/Source.php | 211 ++++-------- src/Grid/Source/Vector.php | 4 +- src/Grid/Type/GridType.php | 6 +- ...umnTitleAnnotationTranslationExtractor.php | 29 +- src/Twig/DataGridExtension.php | 210 ++---------- 78 files changed, 1150 insertions(+), 2336 deletions(-) diff --git a/composer.json b/composer.json index 27f7be5..e700d67 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,9 @@ "symfony/security-core": "^5.2|^6.2", "symfony/serializer": "^5.2|^6.2", "twig/twig": "^2.4|^3.0", - "symfony/translation": "^5.2|^6.2" + "symfony/translation": "^5.2|^6.2", + "jms/translation-bundle": "^1.8", + "doctrine/annotations": "^2.0" }, "require-dev": { "ext-intl": "*", diff --git a/src/APYDataGridBundle.php b/src/APYDataGridBundle.php index 0d0301d..e986e18 100644 --- a/src/APYDataGridBundle.php +++ b/src/APYDataGridBundle.php @@ -19,7 +19,7 @@ class APYDataGridBundle extends Bundle { - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/src/DependencyInjection/APYDataGridExtension.php b/src/DependencyInjection/APYDataGridExtension.php index a2e298c..45a1bd1 100644 --- a/src/DependencyInjection/APYDataGridExtension.php +++ b/src/DependencyInjection/APYDataGridExtension.php @@ -20,7 +20,7 @@ class APYDataGridExtension extends Extension { - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); diff --git a/src/DependencyInjection/Compiler/GridExtensionPass.php b/src/DependencyInjection/Compiler/GridExtensionPass.php index c51804c..baf75bf 100644 --- a/src/DependencyInjection/Compiler/GridExtensionPass.php +++ b/src/DependencyInjection/Compiler/GridExtensionPass.php @@ -18,7 +18,7 @@ class GridExtensionPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (false === $container->hasDefinition('grid')) { return; diff --git a/src/DependencyInjection/Compiler/GridPass.php b/src/DependencyInjection/Compiler/GridPass.php index 5ec4188..d366146 100644 --- a/src/DependencyInjection/Compiler/GridPass.php +++ b/src/DependencyInjection/Compiler/GridPass.php @@ -20,7 +20,7 @@ class GridPass implements CompilerPassInterface * * @api */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->hasDefinition('apy_grid.registry')) { return; diff --git a/src/DependencyInjection/Compiler/TranslationPass.php b/src/DependencyInjection/Compiler/TranslationPass.php index eda4571..514f51e 100644 --- a/src/DependencyInjection/Compiler/TranslationPass.php +++ b/src/DependencyInjection/Compiler/TranslationPass.php @@ -16,7 +16,7 @@ class TranslationPass implements CompilerPassInterface /** * {@inheritdoc} */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->hasDefinition('jms_translation.extractor.file_extractor')) { return; diff --git a/src/Grid/AbstractType.php b/src/Grid/AbstractType.php index 2783e6b..0361f0e 100644 --- a/src/Grid/AbstractType.php +++ b/src/Grid/AbstractType.php @@ -14,19 +14,19 @@ abstract class AbstractType implements GridTypeInterface /** * {@inheritdoc} */ - public function buildGrid(GridBuilder $builder, array $options = []) + public function buildGrid(GridBuilder $builder, array $options = []): void { } /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { } /** * {@inheritdoc} */ - abstract public function getName(); + abstract public function getName(): string; } diff --git a/src/Grid/Action/DeleteMassAction.php b/src/Grid/Action/DeleteMassAction.php index 79759e3..b9f6ef9 100644 --- a/src/Grid/Action/DeleteMassAction.php +++ b/src/Grid/Action/DeleteMassAction.php @@ -14,12 +14,7 @@ class DeleteMassAction extends MassAction { - /** - * Default DeleteMassAction constructor. - * - * @param bool $confirm Show confirm message if true - */ - public function __construct($confirm = false) + public function __construct(bool $confirm = false) { parent::__construct('Delete', 'static::deleteAction', $confirm); } diff --git a/src/Grid/Action/MassAction.php b/src/Grid/Action/MassAction.php index ab4a5a4..2182449 100644 --- a/src/Grid/Action/MassAction.php +++ b/src/Grid/Action/MassAction.php @@ -14,187 +14,101 @@ class MassAction implements MassActionInterface { - /** @var string */ - protected $title; - - /** @var string|null */ - protected $callback; - - /** @var bool */ - protected $confirm; - - /** @var string */ - protected $confirmMessage; - - /** @var array */ - protected $parameters = []; - - /** @var string|null */ - protected $role; - - /** - * Default MassAction constructor. - * - * @param string $title Title of the mass action - * @param string $callback Callback of the mass action - * @param bool $confirm Show confirm message if true - * @param array $parameters Additional parameters - * @param string $role Security role - */ - public function __construct($title, $callback = null, $confirm = false, $parameters = [], $role = null) - { - $this->title = $title; - $this->callback = $callback; - $this->confirm = $confirm; + private string $title; + + private ?string $callback; + + private bool $confirm; + + private string $confirmMessage; + + private array $parameters = []; + + private ?string $role; + + public function __construct( + string $title, + ?string $callback = null, + bool $confirm = false, + array $parameters = [], + ?string $role = null + ) { + $this->title = $title; + $this->callback = $callback; + $this->confirm = $confirm; $this->confirmMessage = 'Do you want to ' . strtolower($title) . ' the selected rows?'; - $this->parameters = $parameters; - $this->role = $role; + $this->parameters = $parameters; + $this->role = $role; } - // @todo: has this setter sense? we passed the title from constructor - /** - * Set action title. - * - * @param string $title - * - * @return self - */ - public function setTitle($title) + public function setTitle(string $title): self { $this->title = $title; return $this; } - /** - * get action title. - * - * @return string - */ - public function getTitle() + public function getTitle(): string { return $this->title; } - /** - * Set action callback. - * - * @param string $callback - * - * @return self - */ - public function setCallback($callback) + public function setCallback(string $callback): self { $this->callback = $callback; return $this; } - /** - * get action callback. - * - * @return string - */ - public function getCallback() + public function getCallback(): ?string { return $this->callback; } - // @todo: we should change this to something like "enableConfirm" as "false" is the default value and has pretty much - // nosense to use setConfirm with false parameter. - /** - * Set action confirm. - * - * @param bool $confirm - * - * @return self - */ - public function setConfirm($confirm) + public function setConfirm(bool $confirm): self { $this->confirm = $confirm; return $this; } - // @todo: could we change this to neddConfirm? - /** - * Get action confirm. - * - * @return bool - */ - public function getConfirm() + public function getConfirm(): bool { return $this->confirm; } - /** - * Set action confirmMessage. - * - * @param string $confirmMessage - * - * @return self - */ - public function setConfirmMessage($confirmMessage) + public function setConfirmMessage(string $confirmMessage): self { $this->confirmMessage = $confirmMessage; return $this; } - /** - * get action confirmMessage. - * - * @return string - */ - public function getConfirmMessage() + public function getConfirmMessage(): string { return $this->confirmMessage; } - /** - * Set action/controller parameters. - * - * @param array $parameters - * - * @return $this - */ - public function setParameters(array $parameters) + public function setParameters(array $parameters): self { $this->parameters = $parameters; return $this; } - /** - * Get action/controller parameters. - * - * @return array - */ - public function getParameters() + public function getParameters(): array { return $this->parameters; } - /** - * set role. - * - * @param string $role - * - * @return self - */ - public function setRole($role) + public function setRole(string $role): self { $this->role = $role; return $this; } - /** - * Get role. - * - * @return string - */ - public function getRole() + public function getRole(): ?string { return $this->role; } diff --git a/src/Grid/Action/MassActionInterface.php b/src/Grid/Action/MassActionInterface.php index 72ba96d..c0f2be6 100644 --- a/src/Grid/Action/MassActionInterface.php +++ b/src/Grid/Action/MassActionInterface.php @@ -19,33 +19,33 @@ interface MassActionInterface * * @return string */ - public function getTitle(); + public function getTitle(): string; /** * get action callback. * * @return string */ - public function getCallback(); + public function getCallback(): ?string; /** * get action confirm. * * @return bool */ - public function getConfirm(); + public function getConfirm(): bool; /** * get action confirmMessage. * * @return bool */ - public function getConfirmMessage(); + public function getConfirmMessage(): string; /** * get additional parameters. * * @return array */ - public function getParameters(); + public function getParameters(): array; } diff --git a/src/Grid/Action/RowAction.php b/src/Grid/Action/RowAction.php index 011d985..9f7be5a 100644 --- a/src/Grid/Action/RowAction.php +++ b/src/Grid/Action/RowAction.php @@ -16,56 +16,38 @@ class RowAction implements RowActionInterface { - /** @var string */ - protected $title; + private string $title; - /** @var string */ - protected $route; + private string $route; - /** @var bool */ - protected $confirm; + private bool $confirm; - /** @var string */ - protected $confirmMessage; + private string $confirmMessage; - /** @var string */ - protected $target; + private string $target; - /** @var string */ - protected $column = '__actions'; + private string $column = '__actions'; - /** @var array */ - protected $routeParameters = []; + private array $routeParameters = []; - /** @var array */ - protected $routeParametersMapping = []; + private array $routeParametersMapping = []; - /** @var array */ - protected $attributes = []; + private array $attributes = []; - /** @var string|null */ - protected $role; + private ?string $role; - /** @var array */ - protected $callbacks = []; + private array $callbacks = []; - /** @var bool */ - protected $enabled = true; + private bool $enabled = true; - /** - * Default RowAction constructor. - * - * @param string $title Title of the row action - * @param string $route Route to the row action - * @param bool $confirm Show confirm message if true - * @param string $target Set the target of this action (_self,_blank,_parent,_top) - * @param array $attributes Attributes of the anchor tag - * @param string $role Security role - * - * @return \APY\DataGridBundle\Grid\Action\RowAction - */ - public function __construct($title, $route, $confirm = false, $target = '_self', $attributes = [], $role = null) - { + public function __construct( + string $title, + string $route, + bool $confirm = false, + string $target = '_self', + array $attributes = [], + ?string $role = null + ) { $this->title = $title; $this->route = $route; $this->confirm = $confirm; @@ -75,152 +57,79 @@ public function __construct($title, $route, $confirm = false, $target = '_self', $this->role = $role; } - // @todo: has this setter real sense? we passed this value from constructor - - /** - * Set action title. - * - * @param string $title - * - * @return self - */ - public function setTitle($title) + public function setTitle(string $title): self { $this->title = $title; return $this; } - /** - * {@inheritdoc} - */ - public function getTitle() + public function getTitle(): string { return $this->title; } - // @todo: has this setter real sense? we passed this value from constructor - - /** - * Set action route. - * - * @param string $route - * - * @return self - */ - public function setRoute($route) + public function setRoute(string $route): self { $this->route = $route; return $this; } - /** - * {@inheritdoc} - */ - public function getRoute() + public function getRoute(): string { return $this->route; } - // @todo: we should change this to something like "enableConfirm" as "false" is the default value and has pretty much - // nosense to use setConfirm with false parameter. - /** - * Set action confirm. - * - * @param bool $confirm - * - * @return self - */ - public function setConfirm($confirm) + public function setConfirm(bool $confirm): self { $this->confirm = $confirm; return $this; } - /** - * {@inheritdoc} - */ - public function getConfirm() + public function getConfirm(): bool { return $this->confirm; } - /** - * Set action confirmMessage. - * - * @param string $confirmMessage - * - * @return self - */ - public function setConfirmMessage($confirmMessage) + public function setConfirmMessage(string $confirmMessage): self { $this->confirmMessage = $confirmMessage; return $this; } - /** - * {@inheritdoc} - */ - public function getConfirmMessage() + public function getConfirmMessage(): string { return $this->confirmMessage; } - /** - * Set action target. - * - * @param string $target - * - * @return self - */ - public function setTarget($target) + public function setTarget(string $target): self { $this->target = $target; return $this; } - /** - * {@inheritdoc} - */ - public function getTarget() + public function getTarget(): string { return $this->target; } - /** - * Set action column. - * - * @param string $column Identifier of the action column - * - * @return self - */ - public function setColumn($column) + public function setColumn(string $column): self { $this->column = $column; return $this; } - /** - * {@inheritdoc} - */ - public function getColumn() + public function getColumn(): string { return $this->column; } - /** - * Add route parameter. - * - * @param array|string $routeParameters - * - * @return self - */ - public function addRouteParameters($routeParameters) + public function addRouteParameters(array|string $routeParameters): self { $routeParameters = (array)$routeParameters; @@ -235,139 +144,70 @@ public function addRouteParameters($routeParameters) return $this; } - /** - * Set route parameters. - * - * @param array|string $routeParameters - * - * @return self - */ - public function setRouteParameters($routeParameters) + public function setRouteParameters(array|string $routeParameters): self { $this->routeParameters = (array)$routeParameters; return $this; } - /** - * {@inheritdoc} - */ - public function getRouteParameters() + public function getRouteParameters(): array { return $this->routeParameters; } - // @todo: why is this accepting string? it seems pretty useless, isn't it? - - /** - * Set route parameters mapping. - * - * @param array|string $routeParametersMapping - * - * @return self - */ - public function setRouteParametersMapping($routeParametersMapping) + public function setRouteParametersMapping(array|string $routeParametersMapping): self { $this->routeParametersMapping = (array)$routeParametersMapping; return $this; } - /** - * Map the parameter. - * - * @param string $name parameter - * - * @return null|string - */ - public function getRouteParametersMapping($name) + public function getRouteParametersMapping(string $name): ?string { return isset($this->routeParametersMapping[$name]) ? $this->routeParametersMapping[$name] : null; } - /** - * Set attributes. - * - * @param array $attributes - * - * @return self - */ - public function setAttributes(array $attributes) + public function setAttributes(array $attributes): self { $this->attributes = $attributes; return $this; } - /** - * Add attribute. - * - * @param string $name - * @param string $value - * - * @return self - */ - public function addAttribute($name, $value) + public function addAttribute(string $name, string $value): self { $this->attributes[$name] = $value; return $this; } - /** - * {@inheritdoc} - */ - public function getAttributes() + public function getAttributes(): array { return $this->attributes; } - /** - * set role. - * - * @param string $role - * - * @return self - */ - public function setRole($role) + public function setRole(string $role): self { $this->role = $role; return $this; } - /** - * Get role. - * - * @return string - */ - public function getRole() + public function getRole(): ?string { return $this->role; } /** - * Set render callback. - * - * @param \Closure $callback - * - * @return self * @deprecated This is deprecated and will be removed in 3.0; use addManipulateRender instead. - * */ public function manipulateRender(\Closure $callback) { return $this->addManipulateRender($callback); } - /** - * Add a callback to render callback stack. - * - * @param \Closure $callback - * - * @return self - */ - public function addManipulateRender($callback) + public function addManipulateRender(\Closure $callback): self { $this->callbacks[] = $callback; @@ -379,19 +219,12 @@ public function getCallbacks(): array return $this->callbacks; } - /** - * Render action for row. - * - * @param Row $row - * - * @return RowAction|null - */ - public function render($row) + public function render(Row $row): ?self { foreach ($this->callbacks as $callback) { if (is_callable($callback)) { if (null === call_user_func($callback, $this, $row)) { - return; + return null; } } } @@ -399,29 +232,15 @@ public function render($row) return $this; } - // @todo: should not this be "isEnabled"? - - /** - * {@inheritdoc} - */ - public function getEnabled() - { - return $this->enabled; - } - - // @todo: should not this be "enable" as default value is false? - - /** - * Set the enabled state of this action. - * - * @param bool $enabled - * - * @return self - */ - public function setEnabled($enabled) + public function setEnabled(bool $enabled): self { $this->enabled = $enabled; return $this; } + + public function getEnabled(): bool + { + return $this->enabled; + } } diff --git a/src/Grid/Action/RowActionInterface.php b/src/Grid/Action/RowActionInterface.php index f21f959..a937e47 100644 --- a/src/Grid/Action/RowActionInterface.php +++ b/src/Grid/Action/RowActionInterface.php @@ -22,61 +22,61 @@ interface RowActionInterface * * @return string */ - public function getTitle(); + public function getTitle(): string; /** * get action route. * * @return string */ - public function getRoute(); + public function getRoute(): string; /** * get action confirm. * * @return bool */ - public function getConfirm(); + public function getConfirm(): bool; /** * get action confirmMessage. * * @return string */ - public function getConfirmMessage(); + public function getConfirmMessage(): string; /** * get action target. * * @return string */ - public function getTarget(); + public function getTarget(): string; /** * get the action column id. * * @return string */ - public function getColumn(); + public function getColumn(): string; /** * get route parameters. * * @return array */ - public function getRouteParameters(); + public function getRouteParameters(): array; /** * get attributes of the link. * * @return array */ - public function getAttributes(); + public function getAttributes(): array; /** * get action enabled. * * @return bool */ - public function getEnabled(); + public function getEnabled(): bool; } diff --git a/src/Grid/Column/ActionsColumn.php b/src/Grid/Column/ActionsColumn.php index 19d6a0d..364a949 100644 --- a/src/Grid/Column/ActionsColumn.php +++ b/src/Grid/Column/ActionsColumn.php @@ -12,31 +12,29 @@ namespace APY\DataGridBundle\Grid\Column; +use APY\DataGridBundle\Grid\Action\RowAction; +use APY\DataGridBundle\Grid\Row; + class ActionsColumn extends Column { - protected $rowActions; - - /** - * ActionsColumn constructor. - * - * @param string $column Identifier of the column - * @param string $title Title of the column - * @param array $rowActions Array of rowAction - */ - public function __construct($column, $title, array $rowActions = []) + private array $rowActions; + + public function __construct(string $column, string $title, array $rowActions = []) { $this->rowActions = $rowActions; - parent::__construct([ - 'id' => $column, - 'title' => $title, - 'sortable' => false, - 'source' => false, - 'filterable' => true, // Show a reset link instead of a filter - ]); + parent::__construct( + [ + 'id' => $column, + 'title' => $title, + 'sortable' => false, + 'source' => false, + 'filterable' => true, + ] + ); } - public function getRouteParameters($row, $action) + public function getRouteParameters(Row $row, RowAction $action): array { $actionParameters = $action->getRouteParameters(); @@ -60,7 +58,7 @@ public function getRouteParameters($row, $action) return [$row->getPrimaryField() => $row->getPrimaryFieldValue()]; } - protected function getValidRouteParameters($name) + protected function getValidRouteParameters(string $name): string { $pos = 0; while (($pos = strpos($name, '.', ++$pos)) !== false) { @@ -70,19 +68,19 @@ protected function getValidRouteParameters($name) return $name; } - public function getRowActions() - { - return $this->rowActions; - } - - public function setRowActions(array $rowActions) + public function setRowActions(array $rowActions): self { $this->rowActions = $rowActions; return $this; } - public function isVisible($isExported = false) + public function getRowActions(): array + { + return $this->rowActions; + } + + public function isVisible(bool $isExported = false): bool { if ($isExported) { return false; @@ -91,23 +89,16 @@ public function isVisible($isExported = false) return parent::isVisible(); } - public function getFilterType() + public function getFilterType(): string { return $this->getType(); } - /** - * Get the list of actions to render. - * - * @param $row - * - * @return array - */ - public function getActionsToRender($row) + public function getActionsToRender(Row $row): array { $list = $this->rowActions; foreach ($list as $i => $a) { - $action = clone $a; + $action = clone $a; $list[$i] = $action->render($row); if (null === $list[$i]) { unset($list[$i]); @@ -117,7 +108,7 @@ public function getActionsToRender($row) return $list; } - public function getType() + public function getType(): string { return 'actions'; } diff --git a/src/Grid/Column/ArrayColumn.php b/src/Grid/Column/ArrayColumn.php index 145c15d..2e0647d 100644 --- a/src/Grid/Column/ArrayColumn.php +++ b/src/Grid/Column/ArrayColumn.php @@ -13,24 +13,31 @@ namespace APY\DataGridBundle\Grid\Column; use APY\DataGridBundle\Grid\Filter; +use APY\DataGridBundle\Grid\Row; +use Symfony\Component\Routing\RouterInterface; class ArrayColumn extends Column { - public function __initialize(array $params) + public function __initialize(array $params): void { parent::__initialize($params); - $this->setOperators($this->getParam('operators', [ - self::OPERATOR_LIKE, - self::OPERATOR_NLIKE, - self::OPERATOR_EQ, - self::OPERATOR_NEQ, - self::OPERATOR_ISNULL, - self::OPERATOR_ISNOTNULL, - ])); + $this->setOperators( + $this->getParam( + 'operators', + [ + self::OPERATOR_LIKE, + self::OPERATOR_NLIKE, + self::OPERATOR_EQ, + self::OPERATOR_NEQ, + self::OPERATOR_ISNULL, + self::OPERATOR_ISNOTNULL, + ] + ) + ); } - public function getFilters($source) + public function getFilters(string $source): array { $parentFilters = parent::getFilters($source); @@ -42,11 +49,11 @@ public function getFilters($source) switch ($filter->getOperator()) { case self::OPERATOR_EQ: case self::OPERATOR_NEQ: - $filterValues = (array) $filter->getValue(); - $value = ''; - $counter = 1; + $filterValues = (array)$filter->getValue(); + $value = ''; + $counter = 1; foreach ($filterValues as $filterValue) { - $len = strlen($filterValue); + $len = strlen($filterValue); $value .= 'i:' . $counter++ . ';s:' . $len . ':"' . $filterValue . '";'; } @@ -54,8 +61,8 @@ public function getFilters($source) break; case self::OPERATOR_LIKE: case self::OPERATOR_NLIKE: - $len = strlen($filter->getValue()); - $value = 's:' . $len . ':"' . $filter->getValue() . '";'; + $len = strlen($filter->getValue()); + $value = 's:' . $len . ':"' . $filter->getValue() . '";'; $filters[] = new Filter($filter->getOperator(), $value); break; case self::OPERATOR_ISNULL: @@ -76,7 +83,7 @@ public function getFilters($source) return $filters; } - public function renderCell($values, $row, $router) + public function renderCell(mixed $values, Row $row, RouterInterface $router): array { if (is_callable($this->callback)) { return call_user_func($this->callback, $values, $row, $router); @@ -86,7 +93,7 @@ public function renderCell($values, $row, $router) if (is_array($values) || $values instanceof \Traversable) { foreach ($values as $key => $value) { // @todo: this seems like dead code - if (!is_array($value) && isset($this->values[(string) $value])) { + if (!is_array($value) && isset($this->values[(string)$value])) { $value = $this->values[$value]; } @@ -97,7 +104,7 @@ public function renderCell($values, $row, $router) return $return; } - public function getType() + public function getType(): string { return 'array'; } diff --git a/src/Grid/Column/BlankColumn.php b/src/Grid/Column/BlankColumn.php index 0e053fb..6e0f99a 100644 --- a/src/Grid/Column/BlankColumn.php +++ b/src/Grid/Column/BlankColumn.php @@ -14,16 +14,16 @@ class BlankColumn extends Column { - public function __initialize(array $params) + public function __initialize(array $params): void { $params['filterable'] = false; - $params['sortable'] = false; - $params['source'] = false; + $params['sortable'] = false; + $params['source'] = false; parent::__initialize($params); } - public function getType() + public function getType(): string { return 'blank'; } diff --git a/src/Grid/Column/BooleanColumn.php b/src/Grid/Column/BooleanColumn.php index f3aebcc..4193836 100644 --- a/src/Grid/Column/BooleanColumn.php +++ b/src/Grid/Column/BooleanColumn.php @@ -12,16 +12,19 @@ namespace APY\DataGridBundle\Grid\Column; +use APY\DataGridBundle\Grid\Row; +use Symfony\Component\Routing\RouterInterface; + class BooleanColumn extends Column { - public function __initialize(array $params) + public function __initialize(array $params): void { - $params['filter'] = 'select'; - $params['selectFrom'] = 'values'; - $params['operators'] = [self::OPERATOR_EQ]; - $params['defaultOperator'] = self::OPERATOR_EQ; + $params['filter'] = 'select'; + $params['selectFrom'] = 'values'; + $params['operators'] = [self::OPERATOR_EQ]; + $params['defaultOperator'] = self::OPERATOR_EQ; $params['operatorsVisible'] = false; - $params['selectMulti'] = false; + $params['selectMulti'] = false; parent::__initialize($params); @@ -30,9 +33,9 @@ public function __initialize(array $params) $this->setValues($this->getParam('values', [1 => 'true', 0 => 'false'])); } - public function isQueryValid($query) + public function isQueryValid(mixed $query): bool { - $query = (array) $query; + $query = (array)$query; if ($query[0] === true || $query[0] === false || $query[0] == 0 || $query[0] == 1) { return true; } @@ -40,19 +43,19 @@ public function isQueryValid($query) return false; } - public function renderCell($value, $row, $router) + public function renderCell(mixed $value, Row $row, RouterInterface $router): mixed { $value = parent::renderCell($value, $row, $router); - return $value ?: 'false'; + return $value ? : false; } - public function getDisplayedValue($value) + public function getDisplayedValue(mixed $value): mixed { return is_bool($value) ? ($value ? 1 : 0) : $value; } - public function getType() + public function getType(): string { return 'boolean'; } diff --git a/src/Grid/Column/Column.php b/src/Grid/Column/Column.php index c887e95..40f7809 100644 --- a/src/Grid/Column/Column.php +++ b/src/Grid/Column/Column.php @@ -15,39 +15,34 @@ use APY\DataGridBundle\Grid\Filter; use APY\DataGridBundle\Grid\Row; use Doctrine\Common\Version as DoctrineVersion; +use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; abstract class Column { - const DEFAULT_VALUE = null; - - /** - * Filter. - */ - const DATA_CONJUNCTION = 0; - const DATA_DISJUNCTION = 1; - - const OPERATOR_EQ = 'eq'; - const OPERATOR_NEQ = 'neq'; - const OPERATOR_LT = 'lt'; - const OPERATOR_LTE = 'lte'; - const OPERATOR_GT = 'gt'; - const OPERATOR_GTE = 'gte'; - const OPERATOR_BTW = 'btw'; - const OPERATOR_BTWE = 'btwe'; - const OPERATOR_LIKE = 'like'; - const OPERATOR_NLIKE = 'nlike'; - const OPERATOR_RLIKE = 'rlike'; - const OPERATOR_LLIKE = 'llike'; - const OPERATOR_SLIKE = 'slike'; //simple/strict LIKE - const OPERATOR_NSLIKE = 'nslike'; - const OPERATOR_RSLIKE = 'rslike'; - const OPERATOR_LSLIKE = 'lslike'; - - const OPERATOR_ISNULL = 'isNull'; - const OPERATOR_ISNOTNULL = 'isNotNull'; - - protected static $availableOperators = [ + public const DEFAULT_VALUE = null; + public const DATA_CONJUNCTION = 0; + public const DATA_DISJUNCTION = 1; + public const OPERATOR_EQ = 'eq'; + public const OPERATOR_NEQ = 'neq'; + public const OPERATOR_LT = 'lt'; + public const OPERATOR_LTE = 'lte'; + public const OPERATOR_GT = 'gt'; + public const OPERATOR_GTE = 'gte'; + public const OPERATOR_BTW = 'btw'; + public const OPERATOR_BTWE = 'btwe'; + public const OPERATOR_LIKE = 'like'; + public const OPERATOR_NLIKE = 'nlike'; + public const OPERATOR_RLIKE = 'rlike'; + public const OPERATOR_LLIKE = 'llike'; + public const OPERATOR_SLIKE = 'slike'; //simple/strict LIKE + public const OPERATOR_NSLIKE = 'nslike'; + public const OPERATOR_RSLIKE = 'rslike'; + public const OPERATOR_LSLIKE = 'lslike'; + public const OPERATOR_ISNULL = 'isNull'; + public const OPERATOR_ISNOTNULL = 'isNotNull'; + + protected static array $availableOperators = [ self::OPERATOR_EQ, self::OPERATOR_NEQ, self::OPERATOR_LT, @@ -71,11 +66,11 @@ abstract class Column /** * Align. */ - const ALIGN_LEFT = 'left'; - const ALIGN_RIGHT = 'right'; - const ALIGN_CENTER = 'center'; + public const ALIGN_LEFT = 'left'; + public const ALIGN_RIGHT = 'right'; + public const ALIGN_CENTER = 'center'; - protected static $aligns = [ + protected static array $aligns = [ self::ALIGN_LEFT, self::ALIGN_RIGHT, self::ALIGN_CENTER, @@ -84,58 +79,88 @@ abstract class Column /** * Internal parameters. */ - protected $id; - protected $title; - protected $sortable; - protected $filterable; - protected $visible; - protected $callback; - protected $order; - protected $size; - protected $visibleForSource; - protected $primary; - protected $align; - protected $inputType; - protected $field; - protected $role; - protected $filterType; - protected $params; - protected $isSorted = false; - protected $orderUrl; - protected $authorizationChecker; - protected $data; - protected $operatorsVisible; - protected $operators; - protected $defaultOperator; - protected $values = []; - protected $selectFrom; - protected $selectMulti; - protected $selectExpanded; - protected $searchOnClick = false; - protected $safe; - protected $separator; - protected $joinType; - protected $export; - protected $class; - protected $isManualField; - protected $useHaving; - protected $isAggregate; - protected $usePrefixTitle; - protected $translationDomain; - - protected $dataJunction = self::DATA_CONJUNCTION; + private $id; - /** - * Default Column constructor. - * - * @param array $params - */ - public function __construct($params = null) + private $title; + + private $sortable; + + private $filterable; + + private $visible; + + private $callback; + + private $order; + + private $size; + + private $visibleForSource; + + private $primary; + + private $align; + + private $inputType; + + private $field; + + private $role; + + private $filterType; + + private $params; + + private $isSorted = false; + + private $authorizationChecker; + + private $data; + + private $operatorsVisible; + + private $operators; + + private $defaultOperator; + + private $values = []; + + private $selectFrom; + + private $selectMulti; + + private $selectExpanded; + + private $searchOnClick = false; + + private $safe; + + private $separator; + + private $joinType; + + private $export; + + private $class; + + private $isManualField; + + private $useHaving; + + private $isAggregate; + + private $usePrefixTitle; + + private $translationDomain; + + protected int $dataJunction = self::DATA_CONJUNCTION; + + public function __construct(?array $params = null) { - $this->__initialize((array) $params); + $this->__initialize((array)$params); } - public function __initialize(array $params) + public function __initialize(array $params): void { $this->params = $params; $this->setId($this->getParam('id')); @@ -162,26 +187,28 @@ public function __initialize(array $params) $this->setUsePrefixTitle($this->getParam('usePrefixTitle', true)); // Order is important for the order display - $this->setOperators($this->getParam('operators', [ - self::OPERATOR_EQ, - self::OPERATOR_NEQ, - self::OPERATOR_LT, - self::OPERATOR_LTE, - self::OPERATOR_GT, - self::OPERATOR_GTE, - self::OPERATOR_BTW, - self::OPERATOR_BTWE, - self::OPERATOR_LIKE, - self::OPERATOR_NLIKE, - self::OPERATOR_RLIKE, - self::OPERATOR_LLIKE, - self::OPERATOR_SLIKE, - self::OPERATOR_NSLIKE, - self::OPERATOR_RSLIKE, - self::OPERATOR_LSLIKE, - self::OPERATOR_ISNULL, - self::OPERATOR_ISNOTNULL, - ])); + $this->setOperators( + $this->getParam('operators', [ + self::OPERATOR_EQ, + self::OPERATOR_NEQ, + self::OPERATOR_LT, + self::OPERATOR_LTE, + self::OPERATOR_GT, + self::OPERATOR_GTE, + self::OPERATOR_BTW, + self::OPERATOR_BTWE, + self::OPERATOR_LIKE, + self::OPERATOR_NLIKE, + self::OPERATOR_RLIKE, + self::OPERATOR_LLIKE, + self::OPERATOR_SLIKE, + self::OPERATOR_NSLIKE, + self::OPERATOR_RSLIKE, + self::OPERATOR_LSLIKE, + self::OPERATOR_ISNULL, + self::OPERATOR_ISNOTNULL, + ]) + ); $this->setDefaultOperator($this->getParam('defaultOperator', self::OPERATOR_LIKE)); $this->setSelectMulti($this->getParam('selectMulti', false)); $this->setSelectExpanded($this->getParam('selectExpanded', false)); @@ -193,7 +220,7 @@ public function __initialize(array $params) $this->setTranslationDomain($this->getParam('translation_domain')); } - public function getParams() + public function getParams(): ?array { return $this->params; } @@ -203,23 +230,14 @@ public function getParam($id, $default = null) return isset($this->params[$id]) ? $this->params[$id] : $default; } - /** - * Draw cell. - * - * @param mixed $value - * @param Row $row - * @param $router - * - * @return string - */ - public function renderCell($value, $row, $router) + public function renderCell(mixed $value, Row $row, RouterInterface $router): mixed { if (is_callable($this->callback)) { return call_user_func($this->callback, $value, $row, $router); } - $value = is_bool($value) ? (int) $value : $value; - if (array_key_exists((string) $value, $this->values)) { + $value = is_bool($value) ? (int)$value : $value; + if (array_key_exists((string)$value, $this->values)) { $value = $this->values[$value]; } @@ -240,7 +258,8 @@ public function manipulateRenderCell($callback) return $this; } - public function getCallback(): mixed { + public function getCallback(): mixed + { return $this->callback; } @@ -317,12 +336,7 @@ public function setVisible($visible) return $this; } - /** - * Return column visibility. - * - * @return bool return true when column is visible - */ - public function isVisible($isExported = false) + public function isVisible(bool $isExported = false): bool { $visible = $isExported && $this->export !== null ? $this->export : $this->visible; @@ -464,7 +478,7 @@ public function getDefaultOrder() public function setOrder($order) { if ($order !== null) { - $this->order = $order; + $this->order = $order; $this->isSorted = true; } @@ -523,12 +537,12 @@ public function setData($data) $hasValue = false; if (isset($data['from']) && $this->isQueryValid($data['from'])) { $this->data['from'] = $data['from']; - $hasValue = true; + $hasValue = true; } if (isset($data['to']) && $this->isQueryValid($data['to'])) { $this->data['to'] = $data['to']; - $hasValue = true; + $hasValue = true; } $isNullOperator = (isset($data['operator']) && ($data['operator'] === self::OPERATOR_ISNULL || $data['operator'] === self::OPERATOR_ISNOTNULL)); @@ -551,12 +565,12 @@ public function getData() $hasValue = false; if (isset($this->data['from']) && $this->data['from'] != $this::DEFAULT_VALUE) { $result['from'] = $this->data['from']; - $hasValue = true; + $hasValue = true; } if (isset($this->data['to']) && $this->data['to'] != $this::DEFAULT_VALUE) { $result['to'] = $this->data['to']; - $hasValue = true; + $hasValue = true; } $isNullOperator = (isset($this->data['operator']) && ($this->data['operator'] === self::OPERATOR_ISNULL || $this->data['operator'] === self::OPERATOR_ISNOTNULL)); @@ -567,7 +581,8 @@ public function getData() return $result; } - public function getDataAttribute(): array { + public function getDataAttribute(): array + { return $this->data; } @@ -576,7 +591,7 @@ public function getDataAttribute(): array { * * @return bool */ - public function isQueryValid($query) + public function isQueryValid(mixed $query): bool { return true; } @@ -700,7 +715,7 @@ public function setFilterType($filterType) { $this->filterType = strtolower($filterType); - return $this; + return $this; } public function getFilterType() @@ -708,7 +723,7 @@ public function getFilterType() return $this->filterType; } - public function getFilters($source) + public function getFilters(string $source): array { $filters = []; @@ -750,7 +765,7 @@ public function getFilters($source) case self::OPERATOR_NEQ: case self::OPERATOR_NLIKE: case self::OPERATOR_NSLIKE: - foreach ((array) $this->data['from'] as $value) { + foreach ((array)$this->data['from'] as $value) { $filters[] = new Filter($this->data['operator'], $value); } break; @@ -799,14 +814,16 @@ public function getOperators() // @see http://www.doctrine-project.org/jira/browse/DDC-1857 // @see http://www.doctrine-project.org/jira/browse/DDC-1858 if ($this->hasDQLFunction() && version_compare(DoctrineVersion::VERSION, '2.5') < 0) { - return array_intersect($this->operators, [self::OPERATOR_EQ, + return array_intersect($this->operators, [ + self::OPERATOR_EQ, self::OPERATOR_NEQ, self::OPERATOR_LT, self::OPERATOR_LTE, self::OPERATOR_GT, self::OPERATOR_GTE, self::OPERATOR_BTW, - self::OPERATOR_BTWE, ]); + self::OPERATOR_BTWE, + ]); } return $this->operators; @@ -918,7 +935,8 @@ public function setAuthorizationChecker(AuthorizationCheckerInterface $authoriza return $this; } - public function getAuthorizationChecker(): ?AuthorizationCheckerInterface { + public function getAuthorizationChecker(): ?AuthorizationCheckerInterface + { return $this->authorizationChecker; } @@ -927,7 +945,7 @@ public function getParentType() return ''; } - public function getType() + public function getType(): ?string { return ''; } diff --git a/src/Grid/Column/DateColumn.php b/src/Grid/Column/DateColumn.php index 8689e7b..1bdf018 100644 --- a/src/Grid/Column/DateColumn.php +++ b/src/Grid/Column/DateColumn.php @@ -16,13 +16,13 @@ class DateColumn extends DateTimeColumn { - protected $timeFormat = \IntlDateFormatter::NONE; + protected int $timeFormat = \IntlDateFormatter::NONE; - protected $fallbackFormat = 'Y-m-d'; + protected string $fallbackFormat = 'Y-m-d'; - protected $fallbackInputFormat = 'Y-m-d'; + protected string $fallbackInputFormat = 'Y-m-d'; - public function getFilters($source) + public function getFilters(string $source): array { $parentFilters = parent::getFilters($source); @@ -64,7 +64,7 @@ public function getFilters($source) return $filters; } - public function getType() + public function getType(): string { return 'date'; } diff --git a/src/Grid/Column/DateTimeColumn.php b/src/Grid/Column/DateTimeColumn.php index 68df14f..0138c4a 100644 --- a/src/Grid/Column/DateTimeColumn.php +++ b/src/Grid/Column/DateTimeColumn.php @@ -12,25 +12,27 @@ namespace APY\DataGridBundle\Grid\Column; +use APY\DataGridBundle\Grid\Row; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer; +use Symfony\Component\Routing\RouterInterface; class DateTimeColumn extends Column { - protected $dateFormat = \IntlDateFormatter::MEDIUM; + protected int $dateFormat = \IntlDateFormatter::MEDIUM; - protected $timeFormat = \IntlDateFormatter::MEDIUM; + protected int $timeFormat = \IntlDateFormatter::MEDIUM; - protected $format; + protected string $format; - protected $fallbackFormat = 'Y-m-d H:i:s'; + protected string $fallbackFormat = 'Y-m-d H:i:s'; - protected $inputFormat; + protected string $inputFormat; - protected $fallbackInputFormat = 'Y-m-d H:i:s'; + protected string $fallbackInputFormat = 'Y-m-d H:i:s'; - protected $timezone; + protected string $timezone; - public function __initialize(array $params) + public function __initialize(array $params): void { parent::__initialize($params); @@ -52,19 +54,19 @@ public function __initialize(array $params) $this->setTimezone($this->getParam('timezone', date_default_timezone_get())); } - public function isQueryValid($query) + public function isQueryValid(mixed $query): bool { $result = array_filter((array) $query, [$this, 'isDateTime']); return !empty($result); } - protected function isDateTime($query) + protected function isDateTime(mixed $query): bool { return false !== \DateTime::createFromFormat($this->inputFormat, $query); } - public function getFilters($source) + public function getFilters(string $source): array { $parentFilters = parent::getFilters($source); @@ -76,7 +78,7 @@ public function getFilters($source) return $filters; } - public function renderCell($value, $row, $router) + public function renderCell(mixed $value, Row $row, RouterInterface $router): mixed { $value = $this->getDisplayedValue($value); @@ -87,7 +89,7 @@ public function renderCell($value, $row, $router) return $value; } - public function getDisplayedValue($value) + public function getDisplayedValue(\Datetime|\DateTimeImmutable|string|int $value): string { if (!empty($value)) { $dateTime = $this->getDatetime($value, new \DateTimeZone($this->getTimezone())); @@ -113,15 +115,7 @@ public function getDisplayedValue($value) return ''; } - /** - * DateTimeHelper::getDatetime() from SonataIntlBundle. - * - * @param \Datetime|\DateTimeImmutable|string|int $data - * @param \DateTimeZone timezone - * - * @return \Datetime - */ - protected function getDatetime($data, \DateTimeZone $timezone) + protected function getDatetime(\Datetime|\DateTimeImmutable|string|int $data, \DateTimeZone $timezone): \DateTimeInterface { if ($data instanceof \DateTime || $data instanceof \DateTimeImmutable) { return $data->setTimezone($timezone); @@ -143,41 +137,43 @@ protected function getDatetime($data, \DateTimeZone $timezone) return $date; } - public function setFormat($format) + public function setFormat(string $format): self { $this->format = $format; return $this; } - public function getFormat() + public function getFormat(): string { return $this->format; } - public function setInputFormat($inputFormat) + public function setInputFormat(string $inputFormat): self { $this->inputFormat = $inputFormat; return $this; } - public function getInputFormat() + public function getInputFormat(): string { return $this->inputFormat; } - public function getTimezone() + public function getTimezone(): string { return $this->timezone; } - public function setTimezone($timezone) + public function setTimezone(string $timezone): self { $this->timezone = $timezone; + + return $this; } - public function getType() + public function getType(): string { return 'datetime'; } diff --git a/src/Grid/Column/JoinColumn.php b/src/Grid/Column/JoinColumn.php index 3cfe820..0b247bb 100644 --- a/src/Grid/Column/JoinColumn.php +++ b/src/Grid/Column/JoinColumn.php @@ -14,11 +14,11 @@ class JoinColumn extends TextColumn { - protected $joinColumns = []; + private array $joinColumns = []; - protected $dataJunction = self::DATA_DISJUNCTION; + protected int $dataJunction = self::DATA_DISJUNCTION; - public function __initialize(array $params) + public function __initialize(array $params): void { parent::__initialize($params); @@ -29,17 +29,17 @@ public function __initialize(array $params) $this->setIsManualField(true); } - public function setJoinColumns(array $columns) + public function setJoinColumns(array $columns): void { $this->joinColumns = $columns; } - public function getJoinColumns() + public function getJoinColumns(): array { return $this->joinColumns; } - public function getFilters($source) + public function getFilters(string $source): array { $filters = []; @@ -57,7 +57,7 @@ public function getFilters($source) return $filters; } - public function getType() + public function getType(): string { return 'join'; } diff --git a/src/Grid/Column/MassActionColumn.php b/src/Grid/Column/MassActionColumn.php index bd97b12..1195d59 100644 --- a/src/Grid/Column/MassActionColumn.php +++ b/src/Grid/Column/MassActionColumn.php @@ -14,22 +14,24 @@ class MassActionColumn extends Column { - const ID = '__action'; + public const ID = '__action'; public function __construct() { - parent::__construct([ - 'id' => self::ID, - 'title' => '', - 'size' => 15, - 'filterable' => true, - 'sortable' => false, - 'source' => false, - 'align' => Column::ALIGN_CENTER, - ]); + parent::__construct( + [ + 'id' => self::ID, + 'title' => '', + 'size' => 15, + 'filterable' => true, + 'sortable' => false, + 'source' => false, + 'align' => Column::ALIGN_CENTER, + ] + ); } - public function isVisible($isExported = false) + public function isVisible(bool $isExported = false): bool { if ($isExported) { return false; @@ -38,12 +40,12 @@ public function isVisible($isExported = false) return parent::isVisible(); } - public function getFilterType() + public function getFilterType(): string { return $this->getType(); } - public function getType() + public function getType(): string { return 'massaction'; } diff --git a/src/Grid/Column/NumberColumn.php b/src/Grid/Column/NumberColumn.php index 75cbc79..a6c63cb 100644 --- a/src/Grid/Column/NumberColumn.php +++ b/src/Grid/Column/NumberColumn.php @@ -12,7 +12,9 @@ namespace APY\DataGridBundle\Grid\Column; +use APY\DataGridBundle\Grid\Row; use Symfony\Component\Form\Exception\TransformationFailedException; +use Symfony\Component\Routing\RouterInterface; class NumberColumn extends Column { @@ -26,25 +28,25 @@ class NumberColumn extends Column 'spellout' => \NumberFormatter::SPELLOUT, ]; - protected $style; + private int $style; - protected $locale; + private string $locale; - protected $precision; + private ?int $precision; - protected $grouping; + private int|bool $grouping; - protected $roundingMode; + private int $roundingMode; - protected $ruleSet; + private int|string|null $ruleSet; - protected $currencyCode; + private string $currencyCode; - protected $fractional; + private bool $fractional; - protected $maxFractionDigits; + private ?int $maxFractionDigits; - public function __initialize(array $params) + public function __initialize(array $params): void { parent::__initialize($params); @@ -63,29 +65,31 @@ public function __initialize(array $params) $this->setRuleSet($this->getParam('ruleSet', '%in-numerals')); // or '%with-words' } - $this->setOperators($this->getParam('operators', [ - self::OPERATOR_EQ, - self::OPERATOR_NEQ, - self::OPERATOR_LT, - self::OPERATOR_LTE, - self::OPERATOR_GT, - self::OPERATOR_GTE, - self::OPERATOR_BTW, - self::OPERATOR_BTWE, - self::OPERATOR_ISNULL, - self::OPERATOR_ISNOTNULL, - ])); + $this->setOperators( + $this->getParam('operators', [ + self::OPERATOR_EQ, + self::OPERATOR_NEQ, + self::OPERATOR_LT, + self::OPERATOR_LTE, + self::OPERATOR_GT, + self::OPERATOR_GTE, + self::OPERATOR_BTW, + self::OPERATOR_BTWE, + self::OPERATOR_ISNULL, + self::OPERATOR_ISNOTNULL, + ]) + ); $this->setDefaultOperator($this->getParam('defaultOperator', self::OPERATOR_EQ)); } - public function isQueryValid($query) + public function isQueryValid(mixed $query): bool { - $result = array_filter((array) $query, 'is_numeric'); + $result = array_filter((array)$query, 'is_numeric'); return !empty($result); } - public function renderCell($value, $row, $router) + public function renderCell(mixed $value, Row $row, RouterInterface $router): mixed { if (is_callable($this->callback)) { return call_user_func($this->callback, $value, $row, $router); @@ -94,7 +98,7 @@ public function renderCell($value, $row, $router) return $this->getDisplayedValue($value); } - public function getDisplayedValue($value) + public function getDisplayedValue(mixed $value): mixed { if ($value !== null && $value !== '') { $formatter = new \NumberFormatter($this->locale, $this->style); @@ -136,7 +140,7 @@ public function getDisplayedValue($value) throw new TransformationFailedException($formatter->getErrorMessage()); } - if (array_key_exists((string) $value, $this->values)) { + if (array_key_exists((string)$value, $this->values)) { $value = $this->values[$value]; } @@ -146,7 +150,7 @@ public function getDisplayedValue($value) return ''; } - public function getFilters($source) + public function getFilters(string $source): array { $parentFilters = parent::getFilters($source); @@ -175,101 +179,103 @@ public function getStyle() return $this->style; } - public function setLocale($locale) + public function setLocale(string $locale): self { $this->locale = $locale; return $this; } - public function getLocale() + public function getLocale(): string { return $this->locale; } - public function setPrecision($precision) + public function setPrecision(?int $precision): self { $this->precision = $precision; return $this; } - public function getPrecision() + public function getPrecision(): ?int { return $this->precision; } - public function setGrouping($grouping) + public function setGrouping(int|bool $grouping): self { $this->grouping = $grouping; return $this; } - public function getGrouping() + public function getGrouping(): int|bool { return $this->grouping; } - public function setRoundingMode($roundingMode) + public function setRoundingMode(int $roundingMode): self { $this->roundingMode = $roundingMode; return $this; } - public function getRoundingMode() + public function getRoundingMode(): int { return $this->roundingMode; } - public function setRuleSet($ruleSet) + public function setRuleSet(string|int $ruleSet): self { $this->ruleSet = $ruleSet; return $this; } - public function getRuleSet() + public function getRuleSet(): int|string|null { return $this->ruleSet; } - public function setCurrencyCode($currencyCode) + public function setCurrencyCode(string $currencyCode): self { $this->currencyCode = $currencyCode; return $this; } - public function getCurrencyCode() + public function getCurrencyCode(): ?string { return $this->currencyCode; } - public function setFractional($fractional) + public function setFractional(bool $fractional): self { $this->fractional = $fractional; return $this; } - public function getFractional() + public function getFractional(): bool { return $this->fractional; } - public function setMaxFractionDigits($maxFractionDigits) + public function setMaxFractionDigits(?int $maxFractionDigits): self { $this->maxFractionDigits = $maxFractionDigits; + + return $this; } - public function getMaxFractionDigits() + public function getMaxFractionDigits(): ?int { return $this->maxFractionDigits; } - public function getType() + public function getType(): string { return 'number'; } diff --git a/src/Grid/Column/RankColumn.php b/src/Grid/Column/RankColumn.php index 4da3b3d..38a948f 100644 --- a/src/Grid/Column/RankColumn.php +++ b/src/Grid/Column/RankColumn.php @@ -12,11 +12,14 @@ namespace APY\DataGridBundle\Grid\Column; +use APY\DataGridBundle\Grid\Row; +use Symfony\Component\Routing\RouterInterface; + class RankColumn extends BlankColumn { - protected $rank = 1; + private int $rank = 1; - public function __initialize(array $params) + public function __initialize(array $params): void { parent::__initialize($params); @@ -26,12 +29,12 @@ public function __initialize(array $params) $this->setAlign($this->getParam('align', 'center')); } - public function renderCell($value, $row, $router) + public function renderCell(mixed $value, Row $row, RouterInterface $router): int { return $this->rank++; } - public function getType() + public function getType(): string { return 'rank'; } diff --git a/src/Grid/Column/SimpleArrayColumn.php b/src/Grid/Column/SimpleArrayColumn.php index 2e4f00c..7c215b4 100644 --- a/src/Grid/Column/SimpleArrayColumn.php +++ b/src/Grid/Column/SimpleArrayColumn.php @@ -13,10 +13,12 @@ namespace APY\DataGridBundle\Grid\Column; use APY\DataGridBundle\Grid\Filter; +use APY\DataGridBundle\Grid\Row; +use Symfony\Component\Routing\RouterInterface; class SimpleArrayColumn extends Column { - public function __initialize(array $params) + public function __initialize(array $params): void { parent::__initialize($params); @@ -31,7 +33,7 @@ public function __initialize(array $params) $this->setDefaultOperator($this->getParam('defaultOperator', self::OPERATOR_LIKE)); } - public function getFilters($source) + public function getFilters(string $source): array { $parentFilters = parent::getFilters($source); @@ -65,7 +67,7 @@ public function getFilters($source) return $filters; } - public function renderCell($value, $row, $router) + public function renderCell(mixed $value, Row $row, RouterInterface $router): mixed { if (is_callable($this->callback)) { return call_user_func($this->callback, $value, $row, $router); @@ -86,7 +88,7 @@ public function renderCell($value, $row, $router) return $return; } - public function getType() + public function getType(): string { return 'simple_array'; } diff --git a/src/Grid/Column/TextColumn.php b/src/Grid/Column/TextColumn.php index 852a015..47c570b 100644 --- a/src/Grid/Column/TextColumn.php +++ b/src/Grid/Column/TextColumn.php @@ -16,14 +16,14 @@ class TextColumn extends Column { - public function isQueryValid($query) + public function isQueryValid(mixed $query): bool { $result = array_filter((array) $query, 'is_string'); return !empty($result); } - public function getFilters($source) + public function getFilters(string $source): array { $parentFilters = parent::getFilters($source); @@ -47,7 +47,7 @@ public function getFilters($source) return $filters; } - public function getType() + public function getType(): string { return 'text'; } diff --git a/src/Grid/Column/TimeColumn.php b/src/Grid/Column/TimeColumn.php index 6d68b5f..6f96a9e 100644 --- a/src/Grid/Column/TimeColumn.php +++ b/src/Grid/Column/TimeColumn.php @@ -14,11 +14,11 @@ class TimeColumn extends DateTimeColumn { - protected $dateFormat = \IntlDateFormatter::NONE; + protected int $dateFormat = \IntlDateFormatter::NONE; - protected $fallbackFormat = 'H:i:s'; + protected string $fallbackFormat = 'H:i:s'; - public function getType() + public function getType(): string { return 'time'; } diff --git a/src/Grid/Column/UntypedColumn.php b/src/Grid/Column/UntypedColumn.php index 8ec76aa..7def493 100644 --- a/src/Grid/Column/UntypedColumn.php +++ b/src/Grid/Column/UntypedColumn.php @@ -14,20 +14,22 @@ class UntypedColumn extends Column { - protected $type = null; + protected ?string $type = null; - public function getParams() + public function getParams(): ?array { return $this->params; } - public function getType() + public function getType(): ?string { return $this->type; } - public function setType($type) + public function setType(string $type): self { $this->type = $type; + + return $this; } } diff --git a/src/Grid/Columns.php b/src/Grid/Columns.php index ba745aa..2ba7519 100644 --- a/src/Grid/Columns.php +++ b/src/Grid/Columns.php @@ -19,45 +19,27 @@ class Columns implements \IteratorAggregate, \Countable { - protected $columns = []; - protected $extensions = []; + private array $columns = []; - const MISSING_COLUMN_EX_MSG = 'Column with id "%s" doesn\'t exists'; + private array $extensions = []; - /** - * @var AuthorizationCheckerInterface - */ - protected $authorizationChecker; + public const MISSING_COLUMN_EX_MSG = 'Column with id "%s" doesn\'t exists'; + + protected AuthorizationCheckerInterface $authorizationChecker; - /** - * @param AuthorizationCheckerInterface $authorizationChecker - */ public function __construct(AuthorizationCheckerInterface $authorizationChecker) { $this->authorizationChecker = $authorizationChecker; } - /** - * @param bool $showOnlySourceColumns - * - * @return ColumnsIterator - */ - public function getIterator($showOnlySourceColumns = false): \Traversable + public function getIterator(bool $showOnlySourceColumns = false): \Traversable { return new ColumnsIterator(new \ArrayIterator($this->columns), $showOnlySourceColumns); } - /** - * Add column. - * - * @param Column $column - * @param int $position - * - * @return Columns - */ - public function addColumn(Column $column, $position = 0) + public function addColumn(Column $column, int $position = 0): self { - $position = (int)$position; + $position = $position; $column->setAuthorizationChecker($this->authorizationChecker); if ($position == 0) { @@ -69,22 +51,15 @@ public function addColumn(Column $column, $position = 0) $position = max(0, count($this->columns) + $position); } - $head = array_slice($this->columns, 0, $position); - $tail = array_slice($this->columns, $position); + $head = array_slice($this->columns, 0, $position); + $tail = array_slice($this->columns, $position); $this->columns = array_merge($head, [$column], $tail); } return $this; } - /** - * @param $columnId - * - * @throws \InvalidArgumentException - * - * @return Column - */ - public function getColumnById($columnId) + public function getColumnById(int|string $columnId): Column { if (($column = $this->hasColumnById($columnId, true)) === false) { throw new \InvalidArgumentException(sprintf(self::MISSING_COLUMN_EX_MSG, $columnId)); @@ -93,13 +68,7 @@ public function getColumnById($columnId) return $column; } - /** - * @param $columnId - * @param bool $returnColumn - * - * @return bool|Column|ActionsColumn - */ - public function hasColumnById($columnId, $returnColumn = false) + public function hasColumnById(int|string $columnId, bool $returnColumn = false): bool|Column { foreach ($this->columns as $column) { if ($column->getId() == $columnId) { @@ -110,12 +79,7 @@ public function hasColumnById($columnId, $returnColumn = false) return false; } - /** - * @throws \InvalidArgumentException - * - * @return Column - */ - public function getPrimaryColumn() + public function getPrimaryColumn(): Column { foreach ($this->columns as $column) { if ($column->isPrimary()) { @@ -134,43 +98,25 @@ public function count(): int return count($this->columns); } - /** - * @param $extension - * - * @return Columns - */ - public function addExtension($extension) + public function addExtension(Column $extension): self { $this->extensions[strtolower($extension->getType())] = $extension; return $this; } - /** - * @param $type - * - * @return bool - */ - public function hasExtensionForColumnType($type) + public function hasExtensionForColumnType(string $type): bool { return isset($this->extensions[$type]); } - /** - * @param $type - * - * @return mixed - */ - public function getExtensionForColumnType($type) + public function getExtensionForColumnType(string $type): bool { // @todo: should not index be checked? return $this->extensions[$type]; } - /** - * @return string - */ - public function getHash() + public function getHash(): string { $hash = ''; foreach ($this->columns as $column) { @@ -180,19 +126,9 @@ public function getHash() return $hash; } - /** - * Sets order of Columns passing an array of column ids - * If the list of ids is uncomplete, the remaining columns will be - * placed after if keepOtherColumns is true. - * - * @param array $columnIds - * @param bool $keepOtherColumns - * - * @return Columns - */ - public function setColumnsOrder(array $columnIds, $keepOtherColumns = true) + public function setColumnsOrder(array $columnIds, bool $keepOtherColumns = true): self { - $reorderedColumns = []; + $reorderedColumns = []; $columnsIndexedByIds = []; foreach ($this->columns as $column) { diff --git a/src/Grid/Exception/ColumnAlreadyExistsException.php b/src/Grid/Exception/ColumnAlreadyExistsException.php index 77fa585..45d9a6a 100644 --- a/src/Grid/Exception/ColumnAlreadyExistsException.php +++ b/src/Grid/Exception/ColumnAlreadyExistsException.php @@ -9,12 +9,7 @@ */ class ColumnAlreadyExistsException extends \InvalidArgumentException { - /** - * Constructor. - * - * @param string $name The column name - */ - public function __construct($name) + public function __construct(string $name) { parent::__construct(sprintf('The type of column "%s" already exists.', $name)); } diff --git a/src/Grid/Exception/ColumnNotFoundException.php b/src/Grid/Exception/ColumnNotFoundException.php index 7d04745..d44f6dd 100644 --- a/src/Grid/Exception/ColumnNotFoundException.php +++ b/src/Grid/Exception/ColumnNotFoundException.php @@ -9,12 +9,7 @@ */ class ColumnNotFoundException extends \InvalidArgumentException { - /** - * Constructor. - * - * @param string $name The column name not found - */ - public function __construct($name) + public function __construct(string $name) { parent::__construct(sprintf('The type of column "%s" not found', $name)); } diff --git a/src/Grid/Exception/TypeAlreadyExistsException.php b/src/Grid/Exception/TypeAlreadyExistsException.php index efd6e3a..5dc45d7 100644 --- a/src/Grid/Exception/TypeAlreadyExistsException.php +++ b/src/Grid/Exception/TypeAlreadyExistsException.php @@ -9,12 +9,7 @@ */ class TypeAlreadyExistsException extends \InvalidArgumentException { - /** - * Constructor. - * - * @param string $name The name of type - */ - public function __construct($name) + public function __construct(string $name) { parent::__construct(sprintf('The type of grid "%s" already exists.', $name)); } diff --git a/src/Grid/Exception/TypeNotFoundException.php b/src/Grid/Exception/TypeNotFoundException.php index 66b0ad3..7f5e8e2 100644 --- a/src/Grid/Exception/TypeNotFoundException.php +++ b/src/Grid/Exception/TypeNotFoundException.php @@ -9,12 +9,7 @@ */ class TypeNotFoundException extends \InvalidArgumentException { - /** - * Constructor. - * - * @param string $name The name of type - */ - public function __construct($name) + public function __construct(string $name) { parent::__construct(sprintf('The type of grid "%s" not found', $name)); } diff --git a/src/Grid/Exception/UnexpectedTypeException.php b/src/Grid/Exception/UnexpectedTypeException.php index d292b3a..47073c0 100644 --- a/src/Grid/Exception/UnexpectedTypeException.php +++ b/src/Grid/Exception/UnexpectedTypeException.php @@ -9,15 +9,14 @@ */ class UnexpectedTypeException extends \InvalidArgumentException { - /** - * Constructor. - * - * @param string $value - * @param int $expectedType - */ - public function __construct($value, $expectedType) + public function __construct(string $value, int $expectedType) { - parent::__construct(sprintf('Expected argument of type "%s", "%s" given', $expectedType, - is_object($value) ? get_class($value) : gettype($value))); + parent::__construct( + sprintf( + 'Expected argument of type "%s", "%s" given', + $expectedType, + is_object($value) ? get_class($value) : gettype($value) + ) + ); } } diff --git a/src/Grid/Export/CSVExport.php b/src/Grid/Export/CSVExport.php index ff9e659..1b690aa 100644 --- a/src/Grid/Export/CSVExport.php +++ b/src/Grid/Export/CSVExport.php @@ -17,9 +17,9 @@ */ class CSVExport extends DSVExport { - protected $fileExtension = 'csv'; + protected ?string $fileExtension = 'csv'; - protected $mimeType = 'text/comma-separated-values'; + protected string $mimeType = 'text/comma-separated-values'; - protected $delimiter = ','; + protected string $delimiter = ','; } diff --git a/src/Grid/Export/DSVExport.php b/src/Grid/Export/DSVExport.php index f8229a1..546c954 100644 --- a/src/Grid/Export/DSVExport.php +++ b/src/Grid/Export/DSVExport.php @@ -17,15 +17,15 @@ */ class DSVExport extends Export { - protected $fileExtension = null; + protected ?string $fileExtension = null; - protected $mimeType = 'application/octet-stream'; + protected string $mimeType = 'application/octet-stream'; - protected $delimiter = ''; + protected string $delimiter = ''; - protected $withBOM = true; + protected bool $withBOM = true; - public function __construct($title, $fileName = 'export', $params = [], $charset = 'UTF-8') + public function __construct(string $title, $fileName = 'export', $params = [], $charset = 'UTF-8') { $this->delimiter = isset($params['delimiter']) ? $params['delimiter'] : $this->delimiter; $this->withBOM = isset($params['withBOM']) ? $params['withBOM'] : $this->withBOM; diff --git a/src/Grid/Export/ExcelExport.php b/src/Grid/Export/ExcelExport.php index d8db8f1..2390203 100644 --- a/src/Grid/Export/ExcelExport.php +++ b/src/Grid/Export/ExcelExport.php @@ -12,16 +12,18 @@ namespace APY\DataGridBundle\Grid\Export; +use APY\DataGridBundle\Grid\Grid; + /** * Excel (This export produces a warning with new Office Excel). */ class ExcelExport extends Export { - protected $fileExtension = 'xls'; + protected ?string $fileExtension = 'xls'; - protected $mimeType = 'application/vnd.ms-excel'; + protected string $mimeType = 'application/vnd.ms-excel'; - public function computeData($grid) + public function computeData(Grid $grid): void { $data = $this->getGridData($grid); diff --git a/src/Grid/Export/Export.php b/src/Grid/Export/Export.php index 9a3ed26..1ebb298 100644 --- a/src/Grid/Export/Export.php +++ b/src/Grid/Export/Export.php @@ -13,28 +13,32 @@ namespace APY\DataGridBundle\Grid\Export; use APY\DataGridBundle\Grid\Column\ArrayColumn; +use APY\DataGridBundle\Grid\Column\Column; +use APY\DataGridBundle\Grid\Grid; +use APY\DataGridBundle\Grid\Row; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; +use Twig\TemplateWrapper; abstract class Export implements ExportInterface { - const DEFAULT_TEMPLATE = '@APYDataGrid/blocks.html.twig'; + public const DEFAULT_TEMPLATE = '@APYDataGrid/blocks.html.twig'; - protected $title; + private string $title; - protected $fileName; + private string $fileName; - protected $fileExtension = null; + protected ?string $fileExtension = null; - protected $mimeType = 'application/octet-stream'; + protected string $mimeType = 'application/octet-stream'; - protected $parameters = []; + private array $parameters = []; - protected $templates; + private array $templates; - protected $twig; + private Environment $twig; private TranslatorInterface $translator; @@ -42,29 +46,23 @@ abstract class Export implements ExportInterface private string $kernelCharset; - protected $grid; + private Grid $grid; - protected $params = []; + private array $params = []; - protected $content; + private string $content; - protected $charset; + private string $charset; - protected $role; + private ?string $role; - /** - * Default Export constructor. - * - * @param string $title Title of the export - * @param string $fileName FileName of the export - * @param array $params Additionnal parameters for the export - * @param string $charset Charset of the exported data - * @param string $role Security role - * - * @return \APY\DataGridBundle\Grid\Export\Export - */ - public function __construct($title, $fileName = 'export', $params = [], $charset = 'UTF-8', $role = null) - { + public function __construct( + string $title, + string $fileName = 'export', + array $params = [], + string $charset = 'UTF-8', + ?string $role = null + ) { $this->title = $title; $this->fileName = $fileName; $this->params = $params; @@ -100,12 +98,7 @@ public function setKernelCharset(string $kernelCharset): self return $this; } - /** - * gets the export Response. - * - * @return Response - */ - public function getResponse() + public function getResponse(): Response { // Response $kernelCharset = $this->kernelCharset; @@ -134,55 +127,19 @@ public function getResponse() return $response; } - /** - * sets the Content of the export. - * - * @param string $content - * - * @return self - */ - public function setContent($content = '') + public function setContent(string $content = ''): self { $this->content = $content; return $this; } - /** - * gets the Content of the export. - * - * @return string - */ - public function getContent() + public function getContent(): string { return $this->content; } - /** - * Get data form the grid. - * - * @param Grid $grid - * - * @return array - * - * array( - * 'titles' => array( - * 'column_id_1' => 'column_title_1', - * 'column_id_2' => 'column_title_2' - * ), - * 'rows' =>array( - * array( - * 'column_id_1' => 'cell_value_1_1', - * 'column_id_2' => 'cell_value_1_2' - * ), - * array( - * 'column_id_1' => 'cell_value_2_1', - * 'column_id_2' => 'cell_value_2_2' - * ) - * ) - * ) - */ - protected function getGridData($grid) + protected function getGridData(Grid $grid): array { $result = []; @@ -197,7 +154,7 @@ protected function getGridData($grid) return $result; } - protected function getRawGridData($grid) + protected function getRawGridData(Grid $grid): array { $result = []; $this->grid = $grid; @@ -211,29 +168,7 @@ protected function getRawGridData($grid) return $result; } - /** - * Get data form the grid in a flat array. - * - * @param Grid $grid - * - * @return array - * - * array( - * '0' => array( - * 'column_id_1' => 'column_title_1', - * 'column_id_2' => 'column_title_2' - * ), - * '1' => array( - * 'column_id_1' => 'cell_value_1_1', - * 'column_id_2' => 'cell_value_1_2' - * ), - * '2' => array( - * 'column_id_1' => 'cell_value_2_1', - * 'column_id_2' => 'cell_value_2_2' - * ) - * ) - */ - protected function getFlatGridData($grid) + protected function getFlatGridData(Grid $grid): array { $data = $this->getGridData($grid); @@ -245,7 +180,7 @@ protected function getFlatGridData($grid) return array_merge($flatData, $data['rows']); } - protected function getFlatRawGridData($grid) + protected function getFlatRawGridData(Grid $grid): array { $data = $this->getRawGridData($grid); @@ -257,7 +192,7 @@ protected function getFlatRawGridData($grid) return array_merge($flatData, $data['rows']); } - protected function getGridTitles() + protected function getGridTitles(): array { $titlesHTML = $this->renderBlock('grid_titles', ['grid' => $this->grid]); @@ -288,7 +223,7 @@ protected function getGridTitles() return $titles; } - protected function getRawGridTitles() + protected function getRawGridTitles(): array { $translator = $this->translator; @@ -302,7 +237,7 @@ protected function getRawGridTitles() return $titles; } - protected function getGridRows() + protected function getGridRows(): array { $rows = []; foreach ($this->grid->getRows() as $i => $row) { @@ -317,7 +252,7 @@ protected function getGridRows() return $rows; } - protected function getRawGridRows() + protected function getRawGridRows(): array { $rows = []; foreach ($this->grid->getRows() as $i => $row) { @@ -331,7 +266,7 @@ protected function getRawGridRows() return $rows; } - protected function getGridCell($column, $row) + protected function getGridCell(Column $column, Row $row): string { $values = $row->getField($column->getId()); @@ -381,14 +316,7 @@ protected function getGridCell($column, $row) return $value; } - /** - * Has block. - * - * @param $name string - * - * @return bool - */ - protected function hasBlock($name) + protected function hasBlock(string $name): bool { foreach ($this->getTemplates() as $template) { if ($template->hasBlock($name, [])) { @@ -399,15 +327,7 @@ protected function hasBlock($name) return false; } - /** - * Render block. - * - * @param $name string - * @param $parameters string - * - * @return string - */ - protected function renderBlock($name, $parameters) + protected function renderBlock(string $name, array $parameters): string { foreach ($this->getTemplates() as $template) { if ($template->hasBlock($name, [])) { @@ -418,14 +338,7 @@ protected function renderBlock($name, $parameters) throw new \InvalidArgumentException(sprintf('Block "%s" doesn\'t exist in grid template "%s".', $name, 'ee')); } - /** - * Template Loader. - * - * @return \Twig\TemplateWrapper[] - * @throws \Exception - * - */ - protected function getTemplates() + protected function getTemplates(): array { if (empty($this->templates)) { $this->setTemplate($this->grid->getTemplate()); @@ -434,16 +347,7 @@ protected function getTemplates() return $this->templates; } - /** - * set template. - * - * @param \Twig\TemplateWrapper|string $template - * - * @return \APY\DataGridBundle\Grid\Export\Export - * @throws \Exception - * - */ - public function setTemplate($template) + public function setTemplate(\Twig\TemplateWrapper|string $template): self { if (is_string($template)) { if (substr($template, 0, 8) === '__SELF__') { @@ -461,7 +365,7 @@ public function setTemplate($template) return $this; } - protected function getTemplatesFromString($theme) + protected function getTemplatesFromString(string|TemplateWrapper $theme): array { $templates = []; @@ -474,7 +378,7 @@ protected function getTemplatesFromString($theme) return $templates; } - protected function cleanHTML($value) + protected function cleanHTML(array|string $value): string { // Handle image $value = preg_replace('#]*title="([^"]*)"[^>]*?/>#isU', '\1', $value); @@ -500,191 +404,96 @@ protected function cleanHTML($value) return $value; } - /** - * set title. - * - * @param string $title - * - * @return self - */ - public function setTitle($title) + public function setTitle(string $title): self { $this->title = $title; return $this; } - /** - * get title. - * - * @return string - */ - public function getTitle() + public function getTitle(): string { return $this->title; } - /** - * set file name. - * - * @param string $fileName - * - * @return self - */ - public function setFileName($fileName) + public function setFileName(string $fileName): self { $this->fileName = $fileName; return $this; } - /** - * get file name. - * - * @return string - */ - public function getFileName() + public function getFileName(): string { return $this->fileName; } - /** - * set file extension. - * - * @param string $fileExtension - * - * @return self - */ - public function setFileExtension($fileExtension) + public function setFileExtension(string $fileExtension): self { $this->fileExtension = $fileExtension; return $this; } - /** - * get file extension. - * - * @return string - */ - public function getFileExtension() + public function getFileExtension(): string { return $this->fileExtension; } - /** - * get base name. - * - * @return string - */ - public function getBaseName() + public function getBaseName(): string { return $this->fileName . (isset($this->fileExtension) ? ".$this->fileExtension" : ''); } - /** - * set response mime type. - * - * @param string $mimeType - * - * @return self - */ - public function setMimeType($mimeType) + public function setMimeType(string $mimeType): self { $this->mimeType = $mimeType; return $this; } - /** - * get response mime type. - * - * @return string - */ - public function getMimeType() + public function getMimeType(): string { return $this->mimeType; } - /** - * set response charset. - * - * @param string $charset - * - * @return self - */ - public function setCharset($charset) + public function setCharset(string $charset): self { $this->charset = $charset; return $this; } - /** - * get response charset. - * - * @return string - */ - public function getCharset() + public function getCharset(): string { return $this->charset; } - /** - * set parameters. - * - * @param array $parameters - * - * @return self - */ - public function setParameters(array $parameters) + public function setParameters(array $parameters): self { $this->parameters = $parameters; return $this; } - /** - * get parameters. - * - * @return array - */ - public function getParameters() + public function getParameters(): array { return $this->parameters; } - /** - * has parameter. - * - * @return mixed - */ - public function hasParameter($name) + public function hasParameter(string $name): bool { return array_key_exists($name, $this->parameters); } - /** - * add parameter. - * - * @param $name - * @param $value - * - * @return \APY\DataGridBundle\Grid\Export\Export - */ - public function addParameter($name, $value) + public function addParameter(string $name, string $value): self { $this->parameters[$name] = $value; return $this; } - /** - * get parameter. - * - * @return mixed - */ - public function getParameter($name) + public function getParameter(string $name): string { if (!$this->hasParameter($name)) { throw new \InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); @@ -693,26 +502,14 @@ public function getParameter($name) return $this->parameters[$name]; } - /** - * set role. - * - * @param mixed $role - * - * @return self - */ - public function setRole($role) + public function setRole(?string $role): self { $this->role = $role; return $this; } - /** - * Get role. - * - * @return mixed - */ - public function getRole() + public function getRole(): ?string { return $this->role; } diff --git a/src/Grid/Export/ExportInterface.php b/src/Grid/Export/ExportInterface.php index 364c164..2f8d3cc 100644 --- a/src/Grid/Export/ExportInterface.php +++ b/src/Grid/Export/ExportInterface.php @@ -12,6 +12,9 @@ namespace APY\DataGridBundle\Grid\Export; +use APY\DataGridBundle\Grid\Grid; +use Symfony\Component\HttpFoundation\Response; + interface ExportInterface { /** @@ -19,26 +22,26 @@ interface ExportInterface * * @param Grid $grid The grid */ - public function computeData($grid); + public function computeData(Grid $grid): void; /** * Get the export Response. * * @return Response */ - public function getResponse(); + public function getResponse(): Response; /** * Get the export title. * * @return string */ - public function getTitle(); + public function getTitle(): string; /** * Get the export role. * * @return mixed */ - public function getRole(); + public function getRole(): ?string; } diff --git a/src/Grid/Export/JSONExport.php b/src/Grid/Export/JSONExport.php index 4f69ad2..42e96c4 100644 --- a/src/Grid/Export/JSONExport.php +++ b/src/Grid/Export/JSONExport.php @@ -12,14 +12,16 @@ namespace APY\DataGridBundle\Grid\Export; +use APY\DataGridBundle\Grid\Grid; + /** * JSON. */ class JSONExport extends Export { - protected $fileExtension = 'json'; + protected ?string $fileExtension = 'json'; - public function computeData($grid) + public function computeData(Grid $grid): void { $this->content = json_encode($this->getGridData($grid)); } diff --git a/src/Grid/Export/PHPExcel2003Export.php b/src/Grid/Export/PHPExcel2003Export.php index 2f5d580..710fd70 100644 --- a/src/Grid/Export/PHPExcel2003Export.php +++ b/src/Grid/Export/PHPExcel2003Export.php @@ -17,7 +17,7 @@ */ class PHPExcel2003Export extends PHPExcel2007Export { - protected function getWriter() + protected function getWriter(): \PHPExcel_Writer_Excel2007 { $writer = parent::getWriter(); $writer->setOffice2003Compatibility(true); diff --git a/src/Grid/Export/PHPExcel2007Export.php b/src/Grid/Export/PHPExcel2007Export.php index eafea08..f81f0d4 100644 --- a/src/Grid/Export/PHPExcel2007Export.php +++ b/src/Grid/Export/PHPExcel2007Export.php @@ -21,7 +21,7 @@ class PHPExcel2007Export extends PHPExcel5Export protected $mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; - protected function getWriter() + protected function getWriter(): \PHPExcel_Writer_Excel2007 { $writer = new \PHPExcel_Writer_Excel2007($this->objPHPExcel); $writer->setPreCalculateFormulas(false); diff --git a/src/Grid/Export/PHPExcel5Export.php b/src/Grid/Export/PHPExcel5Export.php index c742a33..1f02595 100644 --- a/src/Grid/Export/PHPExcel5Export.php +++ b/src/Grid/Export/PHPExcel5Export.php @@ -12,26 +12,32 @@ namespace APY\DataGridBundle\Grid\Export; +use APY\DataGridBundle\Grid\Grid; + /** * PHPExcel 5 Export (97-2003) (.xls) * 52 columns maximum. */ class PHPExcel5Export extends Export { - protected $fileExtension = 'xls'; + protected ?string $fileExtension = 'xls'; - protected $mimeType = 'application/vnd.ms-excel'; + protected string $mimeType = 'application/vnd.ms-excel'; - public $objPHPExcel; + public \PHPExcel $objPHPExcel; - public function __construct($tilte, $fileName = 'export', $params = [], $charset = 'UTF-8') - { + public function __construct( + string $title, + string $fileName = 'export', + array $params = [], + string $charset = 'UTF-8' + ) { $this->objPHPExcel = new \PHPExcel(); - parent::__construct($tilte, $fileName, $params, $charset); + parent::__construct($title, $fileName, $params, $charset); } - public function computeData($grid) + public function computeData(Grid $grid): void { $data = $this->getFlatGridData($grid); @@ -57,7 +63,7 @@ public function computeData($grid) ob_end_clean(); } - protected function getWriter() + protected function getWriter(): mixed { return new \PHPExcel_Writer_Excel5($this->objPHPExcel); } diff --git a/src/Grid/Export/PHPExcelHTMLExport.php b/src/Grid/Export/PHPExcelHTMLExport.php index 911e181..e8efc15 100644 --- a/src/Grid/Export/PHPExcelHTMLExport.php +++ b/src/Grid/Export/PHPExcelHTMLExport.php @@ -17,11 +17,11 @@ */ class PHPExcelHTMLExport extends PHPExcel5Export { - protected $fileExtension = 'html'; + protected ?string $fileExtension = 'html'; - protected $mimeType = 'text/html'; + protected string $mimeType = 'text/html'; - protected function getWriter() + protected function getWriter(): \PHPExcel_Writer_HTML { $writer = new \PHPExcel_Writer_HTML($this->objPHPExcel); $writer->setPreCalculateFormulas(false); diff --git a/src/Grid/Export/PHPExcelPDFExport.php b/src/Grid/Export/PHPExcelPDFExport.php index c71017d..6f9ac44 100644 --- a/src/Grid/Export/PHPExcelPDFExport.php +++ b/src/Grid/Export/PHPExcelPDFExport.php @@ -17,11 +17,11 @@ */ class PHPExcelPDFExport extends PHPExcel5Export { - protected $fileExtension = 'pdf'; + protected ?string $fileExtension = 'pdf'; - protected $mimeType = 'application/pdf'; + protected string $mimeType = 'application/pdf'; - protected function getWriter() + protected function getWriter(): \PHPExcel_Writer_PDF { //$this->objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(\PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); //$this->objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(\PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4); diff --git a/src/Grid/Export/SCSVExport.php b/src/Grid/Export/SCSVExport.php index b068526..b7de64c 100644 --- a/src/Grid/Export/SCSVExport.php +++ b/src/Grid/Export/SCSVExport.php @@ -17,5 +17,5 @@ */ class SCSVExport extends CSVExport { - protected $delimiter = ';'; + protected string $delimiter = ';'; } diff --git a/src/Grid/Export/TSVExport.php b/src/Grid/Export/TSVExport.php index 463d3c8..0134d2d 100644 --- a/src/Grid/Export/TSVExport.php +++ b/src/Grid/Export/TSVExport.php @@ -17,9 +17,9 @@ */ class TSVExport extends DSVExport { - protected $fileExtension = 'tsv'; + protected ?string $fileExtension = 'tsv'; - protected $mimeType = 'text/tab-separated-values'; + protected string $mimeType = 'text/tab-separated-values'; - protected $delimiter = "\t"; + protected string $delimiter = "\t"; } diff --git a/src/Grid/Export/XMLExport.php b/src/Grid/Export/XMLExport.php index 0a8e8ef..b049b13 100644 --- a/src/Grid/Export/XMLExport.php +++ b/src/Grid/Export/XMLExport.php @@ -12,6 +12,7 @@ namespace APY\DataGridBundle\Grid\Export; +use APY\DataGridBundle\Grid\Grid; use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; use Symfony\Component\Serializer\Serializer; @@ -21,11 +22,11 @@ */ class XMLExport extends Export { - protected $fileExtension = 'xml'; + protected ?string $fileExtension = 'xml'; - protected $mimeType = 'application/xml'; + protected string $mimeType = 'application/xml'; - public function computeData($grid) + public function computeData(Grid $grid): void { $xmlEncoder = new XmlEncoder(); $xmlEncoder->setRootNodeName('grid'); @@ -33,7 +34,7 @@ public function computeData($grid) $data = $this->getGridData($grid); - $convertData['titles'] = $data['titles']; + $convertData['titles'] = $data['titles']; $convertData['rows']['row'] = $data['rows']; $this->content = $serializer->serialize($convertData, 'xml'); diff --git a/src/Grid/Filter.php b/src/Grid/Filter.php index 5f189c3..8a583b6 100644 --- a/src/Grid/Filter.php +++ b/src/Grid/Filter.php @@ -14,86 +14,64 @@ class Filter { - protected $value; - protected $operator; - protected $columnName; + private mixed $value; + + private string $operator; + + private ?string $columnName; /** * @param string $operator * @param mixed|null $value * @param string|null $columnName */ - public function __construct($operator, $value = null, $columnName = null) - { - $this->value = $value; - $this->operator = $operator; + public function __construct( + string $operator, + mixed $value = null, + ?string $columnName = null + ) { + $this->value = $value; + $this->operator = $operator; $this->columnName = $columnName; } - /** - * @param string $operator - * - * @return Filter - */ - public function setOperator($operator) + public function setOperator(string $operator): self { $this->operator = $operator; return $this; } - /** - * @return string - */ - public function getOperator() + public function getOperator(): string { return $this->operator; } - /** - * @param mixed $value - * - * @return Filter - */ - public function setValue($value) + public function setValue(mixed $value): self { $this->value = $value; return $this; } - /** - * @return mixed|null - */ - public function getValue() + public function getValue(): mixed { return $this->value; } - /** - * @return bool - */ - public function hasColumnName() + public function hasColumnName(): bool { return $this->columnName !== null; } - /** - * @param string $columnName - * - * @return Filter - */ - public function setColumnName($columnName) + public function setColumnName(string $columnName): self { $this->columnName = $columnName; return $this; } - /** - * @return string|null - */ - public function getColumnName() + public function getColumnName(): ?string { return $this->columnName; } diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index 19ee1e8..93db2f9 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -38,46 +38,46 @@ class Grid implements GridInterface { - const REQUEST_QUERY_MASS_ACTION_ALL_KEYS_SELECTED = '__action_all_keys'; - const REQUEST_QUERY_MASS_ACTION = '__action_id'; - const REQUEST_QUERY_EXPORT = '__export_id'; - const REQUEST_QUERY_TWEAK = '__tweak_id'; - const REQUEST_QUERY_PAGE = '_page'; - const REQUEST_QUERY_LIMIT = '_limit'; - const REQUEST_QUERY_ORDER = '_order'; - const REQUEST_QUERY_TEMPLATE = '_template'; - const REQUEST_QUERY_RESET = '_reset'; - - const SOURCE_ALREADY_SETTED_EX_MSG = 'The source of the grid is already set.'; - const SOURCE_NOT_SETTED_EX_MSG = 'The source of the grid must be set.'; - const TWEAK_MALFORMED_ID_EX_MSG = 'Tweak id "%s" is malformed. The id have to match this regex ^[0-9a-zA-Z_\+-]+'; - const TWIG_TEMPLATE_LOAD_EX_MSG = 'Unable to load template'; - const NOT_VALID_LIMIT_EX_MSG = 'Limit has to be array or integer'; - const NOT_VALID_PAGE_NUMBER_EX_MSG = 'Page must be a positive number'; - const NOT_VALID_MAX_RESULT_EX_MSG = 'Max results must be a positive number.'; - const MASS_ACTION_NOT_DEFINED_EX_MSG = 'Action %s is not defined.'; - const MASS_ACTION_CALLBACK_NOT_VALID_EX_MSG = 'Callback %s is not callable or Controller action'; - const EXPORT_NOT_DEFINED_EX_MSG = 'Export %s is not defined.'; - const PAGE_NOT_VALID_EX_MSG = 'Page must be a positive number'; - const COLUMN_ORDER_NOT_VALID_EX_MSG = '%s is not a valid order.'; - const DEFAULT_LIMIT_NOT_VALID_EX_MSG = 'Limit must be a positive number'; - const LIMIT_NOT_DEFINED_EX_MSG = 'Limit %s is not defined in limits.'; - const NO_ROWS_RETURNED_EX_MSG = 'Source have to return Rows object.'; - const INVALID_TOTAL_COUNT_EX_MSG = 'Source function getTotalCount need to return integer result, returned: %s'; - const NOT_VALID_TWEAK_ID_EX_MSG = 'Tweak with id "%s" doesn\'t exists'; - const GET_FILTERS_NO_REQUEST_HANDLED_EX_MSG = 'getFilters method is only available in the manipulate callback function or after the call of the method isRedirected of the grid.'; - const HAS_FILTER_NO_REQUEST_HANDLED_EX_MSG = 'hasFilters method is only available in the manipulate callback function or after the call of the method isRedirected of the grid.'; - const TWEAK_NOT_DEFINED_EX_MSG = 'Tweak %s is not defined.'; + public const REQUEST_QUERY_MASS_ACTION_ALL_KEYS_SELECTED = '__action_all_keys'; + public const REQUEST_QUERY_MASS_ACTION = '__action_id'; + public const REQUEST_QUERY_EXPORT = '__export_id'; + public const REQUEST_QUERY_TWEAK = '__tweak_id'; + public const REQUEST_QUERY_PAGE = '_page'; + public const REQUEST_QUERY_LIMIT = '_limit'; + public const REQUEST_QUERY_ORDER = '_order'; + public const REQUEST_QUERY_TEMPLATE = '_template'; + public const REQUEST_QUERY_RESET = '_reset'; + + public const SOURCE_ALREADY_SETTED_EX_MSG = 'The source of the grid is already set.'; + public const SOURCE_NOT_SETTED_EX_MSG = 'The source of the grid must be set.'; + public const TWEAK_MALFORMED_ID_EX_MSG = 'Tweak id "%s" is malformed. The id have to match this regex ^[0-9a-zA-Z_\+-]+'; + public const TWIG_TEMPLATE_LOAD_EX_MSG = 'Unable to load template'; + public const NOT_VALID_LIMIT_EX_MSG = 'Limit has to be array or integer'; + public const NOT_VALID_PAGE_NUMBER_EX_MSG = 'Page must be a positive number'; + public const NOT_VALID_MAX_RESULT_EX_MSG = 'Max results must be a positive number.'; + public const MASS_ACTION_NOT_DEFINED_EX_MSG = 'Action %s is not defined.'; + public const MASS_ACTION_CALLBACK_NOT_VALID_EX_MSG = 'Callback %s is not callable or Controller action'; + public const EXPORT_NOT_DEFINED_EX_MSG = 'Export %s is not defined.'; + public const PAGE_NOT_VALID_EX_MSG = 'Page must be a positive number'; + public const COLUMN_ORDER_NOT_VALID_EX_MSG = '%s is not a valid order.'; + public const DEFAULT_LIMIT_NOT_VALID_EX_MSG = 'Limit must be a positive number'; + public const LIMIT_NOT_DEFINED_EX_MSG = 'Limit %s is not defined in limits.'; + public const NO_ROWS_RETURNED_EX_MSG = 'Source have to return Rows object.'; + public const INVALID_TOTAL_COUNT_EX_MSG = 'Source function getTotalCount need to return integer result, returned: %s'; + public const NOT_VALID_TWEAK_ID_EX_MSG = 'Tweak with id "%s" doesn\'t exists'; + public const GET_FILTERS_NO_REQUEST_HANDLED_EX_MSG = 'getFilters method is only available in the manipulate callback function or after the call of the method isRedirected of the grid.'; + public const HAS_FILTER_NO_REQUEST_HANDLED_EX_MSG = 'hasFilters method is only available in the manipulate callback function or after the call of the method isRedirected of the grid.'; + public const TWEAK_NOT_DEFINED_EX_MSG = 'Tweak %s is not defined.'; /** * @var \Symfony\Component\DependencyInjection\Container */ - protected $container; + private $container; /** * @var \Symfony\Component\Routing\Router */ - protected $router; + private $router; private Environment $twig; @@ -94,17 +94,17 @@ class Grid implements GridInterface /** * @var null|\Symfony\Component\HttpFoundation\Session\Session; */ - protected $session; + private $session; /** * @var \Symfony\Component\HttpFoundation\Request */ - protected $request; + private $request; /** * @var \Symfony\Component\Security\Core\Authorization\AuthorizationChecker */ - protected $securityContext; + private $securityContext; /** * @var string @@ -119,221 +119,221 @@ class Grid implements GridInterface /** * @var string */ - protected $routeUrl; + private $routeUrl; /** * @var array */ - protected $routeParameters; + private $routeParameters; /** * @var \APY\DataGridBundle\Grid\Source\Source */ - protected $source; + private $source; /** * @var bool */ - protected $prepared = false; + private $prepared = false; /** * @var int */ - protected $totalCount; + private $totalCount; /** * @var int */ - protected $page = 0; + private $page = 0; /** * @var int */ - protected $limit; + private $limit; /** * @var array */ - protected $limits = []; + private $limits = []; /** * @var \APY\DataGridBundle\Grid\Columns|\APY\DataGridBundle\Grid\Column\Column[] */ - protected $columns; + private $columns; /** * @var \APY\DataGridBundle\Grid\Rows */ - protected $rows; + private $rows; /** * @var \APY\DataGridBundle\Grid\Action\MassAction[] */ - protected $massActions = []; + private $massActions = []; /** * @var \APY\DataGridBundle\Grid\Action\RowAction[] */ - protected $rowActions = []; + private $rowActions = []; /** * @var bool */ - protected $showFilters = true; + private $showFilters = true; /** * @var bool */ - protected $showTitles = true; + private $showTitles = true; /** * @var array|object request */ - protected $requestData; + private $requestData; /** * @var array|object session */ - protected $sessionData = []; + private $sessionData = []; /** * @var string */ - protected $prefixTitle = ''; + private $prefixTitle = ''; /** * @var bool */ - protected $persistence = false; + private $persistence = false; /** * @var bool */ - protected $newSession = false; + private $newSession = false; /** * @var string */ - protected $noDataMessage; + private $noDataMessage; /** * @var string */ - protected $noResultMessage; + private $noResultMessage; /** * @var \APY\DataGridBundle\Grid\Export\Export[] */ - protected $exports = []; + private $exports = []; /** * @var bool */ - protected $redirect = null; + private $redirect = null; /** * @var bool */ - protected $isReadyForExport = false; + private $isReadyForExport = false; /** * @var Response */ - protected $exportResponse; + private $exportResponse; /** * @var Response */ - protected $massActionResponse; + private $massActionResponse; /** * @var int */ - protected $maxResults; + private $maxResults; /** * @var array */ - protected $items = []; + private $items = []; /** * Data junction of the grid. * * @var int */ - protected $dataJunction = Column::DATA_CONJUNCTION; + private $dataJunction = Column::DATA_CONJUNCTION; /** * Permanent filters. * * @var array */ - protected $permanentFilters = []; + private $permanentFilters = []; /** * Default filters. * * @var array */ - protected $defaultFilters = []; + private $defaultFilters = []; /** * Default order (e.g. my_column_id|asc). * * @var string */ - protected $defaultOrder; + private $defaultOrder; /** * Default limit. * * @var int */ - protected $defaultLimit; + private $defaultLimit; /** * Default page. * * @var int */ - protected $defaultPage; + private $defaultPage; /** * Tweaks. * * @var array */ - protected $tweaks = []; + private $tweaks = []; /** * Default Tweak. * * @var string */ - protected $defaultTweak; + private $defaultTweak; /** * Filters in session. * * @var array */ - protected $sessionFilters; + private $sessionFilters; // Lazy parameters - protected $lazyAddColumn = []; + private $lazyAddColumn = []; - protected $lazyHiddenColumns = []; + private $lazyHiddenColumns = []; - protected $lazyVisibleColumns = []; + private $lazyVisibleColumns = []; - protected $lazyHideShowColumns = []; + private $lazyHideShowColumns = []; // Lazy parameters for the action column - protected $actionsColumnSize; + private $actionsColumnSize; - protected $actionsColumnTitle; + private $actionsColumnTitle; - protected $massActionsInNewTab; + private $massActionsInNewTab; /** * The grid configuration. @@ -397,7 +397,7 @@ public function __construct( /** * {@inheritdoc} */ - public function initialize() + public function initialize(): self { $config = $this->config; @@ -482,7 +482,7 @@ public function initialize() /** * {@inheritdoc} */ - public function handleRequest(Request $request) + public function handleRequest(Request $request): self { if (null === $this->source) { throw new \LogicException(self::SOURCE_NOT_SETTED_EX_MSG); diff --git a/src/Grid/GridBuilder.php b/src/Grid/GridBuilder.php index 6a75ebf..34f9e87 100644 --- a/src/Grid/GridBuilder.php +++ b/src/Grid/GridBuilder.php @@ -41,28 +41,10 @@ class GridBuilder extends GridConfigBuilder implements GridBuilderInterface private TranslatorInterface $translator; - /** - * The factory. - * - * @var GridFactoryInterface - */ - private $factory; + private GridFactoryInterface $factory; - /** - * Columns of the grid builder. - * - * @var Column[] - */ - private $columns = []; + private array $columns = []; - /** - * Constructor. - * - * @param Container $container The service container - * @param GridFactoryInterface $factory The grid factory - * @param string $name The name of the grid - * @param array $options The options of the grid - */ public function __construct( AuthorizationCheckerInterface $authorizationChecker, RouterInterface $router, @@ -74,7 +56,7 @@ public function __construct( KernelInterface $kernel, TranslatorInterface $translator, GridFactoryInterface $factory, - $name, + string $name, array $options = [] ) { parent::__construct($name, $options); @@ -94,7 +76,7 @@ public function __construct( /** * {@inheritdoc} */ - public function add($name, $type, array $options = []) + public function add(string $name, string|Column $type, array $options = []): self { if (!$type instanceof Column) { if (!is_string($type)) { @@ -112,7 +94,7 @@ public function add($name, $type, array $options = []) /** * {@inheritdoc} */ - public function get($name) + public function get(string $name): Column { if (!$this->has($name)) { throw new InvalidArgumentException(sprintf('The column with the name "%s" does not exist.', $name)); @@ -126,7 +108,7 @@ public function get($name) /** * {@inheritdoc} */ - public function has($name) + public function has(string $name): bool { return isset($this->columns[$name]); } @@ -134,7 +116,7 @@ public function has($name) /** * {@inheritdoc} */ - public function remove($name) + public function remove(string $name): self { unset($this->columns[$name]); @@ -144,7 +126,7 @@ public function remove($name) /** * {@inheritdoc} */ - public function getGrid() + public function getGrid(): Grid { $config = $this->getGridConfig(); diff --git a/src/Grid/GridBuilderInterface.php b/src/Grid/GridBuilderInterface.php index 1cf1ce7..36e8671 100644 --- a/src/Grid/GridBuilderInterface.php +++ b/src/Grid/GridBuilderInterface.php @@ -20,7 +20,7 @@ interface GridBuilderInterface * * @return GridBuilderInterface */ - public function add($name, $type, array $options = []); + public function add(string $name, string|Column $type, array $options = []): self; /** * Returns a column. @@ -29,7 +29,7 @@ public function add($name, $type, array $options = []); * * @return Column */ - public function get($name); + public function get(string $name): Column; /** * Removes the column with the given name. @@ -38,7 +38,7 @@ public function get($name); * * @return GridBuilderInterface */ - public function remove($name); + public function remove(string $name): self; /** * Returns whether a column with the given name exists. @@ -47,12 +47,12 @@ public function remove($name); * * @return bool */ - public function has($name); + public function has(string $name): bool; /** * Creates the grid. * * @return Grid The grid */ - public function getGrid(); + public function getGrid(): Grid; } diff --git a/src/Grid/GridConfigBuilder.php b/src/Grid/GridConfigBuilder.php index d809a82..bea4e14 100644 --- a/src/Grid/GridConfigBuilder.php +++ b/src/Grid/GridConfigBuilder.php @@ -12,98 +12,41 @@ */ class GridConfigBuilder implements GridConfigBuilderInterface { - /** - * @var string - */ - protected $name; + private string $name; - /** - * @var GridTypeInterface - */ - protected $type; + private GridTypeInterface $type; - /** - * @var Source - */ - protected $source; + private Source $source; - /** - * @var string - */ - protected $route; + private string $route; - /** - * @var array - */ - protected $routeParameters = []; + private array $routeParameters = []; - /** - * @var bool - */ - protected $persistence; + private bool $persistence; - /** - * @var int - */ - protected $page = 0; + private int $page = 0; - /** - * @var int - */ - protected $limit; + private int $limit; - /** - * @var int - */ - protected $maxResults; + private int $maxResults; - /** - * @var bool - */ - protected $filterable = true; + private bool $filterable = true; - /** - * @var bool - */ - protected $sortable = true; + private bool $sortable = true; - /** - * @var string - */ - protected $sortBy; + private string $sortBy; - /** - * @var string - */ - protected $order = 'asc'; + private string $order = 'asc'; - /** - * @var string|array - */ - protected $groupBy; + private string|array $groupBy; - /** - * @var bool - */ - protected $massActionsInNewTab; + private bool $massActionsInNewTab; - /** - * @var array - */ - protected $actions; + private array $actions; - /** - * @var array - */ - protected $options; + private array $options; - /** - * Constructor. - * - * @param string $name The grid name - * @param array $options The grid options - */ - public function __construct($name, array $options = []) + public function __construct(string $name, array $options = []) { $this->name = $name; $this->options = $options; @@ -112,7 +55,7 @@ public function __construct($name, array $options = []) /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return $this->name; } @@ -120,19 +63,12 @@ public function getName() /** * {@inheritdoc} */ - public function getSource() + public function getSource(): Source { return $this->source; } - /** - * Set Source. - * - * @param Source $source - * - * @return $this - */ - public function setSource(Source $source) + public function setSource(Source $source): self { $this->source = $source; @@ -142,19 +78,12 @@ public function setSource(Source $source) /** * {@inheritdoc} */ - public function getType() + public function getType(): GridTypeInterface { return $this->type; } - /** - * Set Type. - * - * @param GridTypeInterface $type - * - * @return $this - */ - public function setType(GridTypeInterface $type) + public function setType(GridTypeInterface $type): self { $this->type = $type; @@ -164,19 +93,12 @@ public function setType(GridTypeInterface $type) /** * {@inheritdoc} */ - public function getRoute() + public function getRoute(): string { return $this->route; } - /** - * Set Route. - * - * @param mixed $route - * - * @return $this - */ - public function setRoute($route) + public function setRoute(string $route): self { $this->route = $route; @@ -186,19 +108,12 @@ public function setRoute($route) /** * {@inheritdoc} */ - public function getRouteParameters() + public function getRouteParameters(): array { return $this->routeParameters; } - /** - * Set RouteParameters. - * - * @param array $routeParameters - * - * @return $this - */ - public function setRouteParameters(array $routeParameters) + public function setRouteParameters(array $routeParameters): self { $this->routeParameters = $routeParameters; @@ -208,19 +123,12 @@ public function setRouteParameters(array $routeParameters) /** * {@inheritdoc} */ - public function isPersisted() + public function isPersisted(): bool { return $this->persistence; } - /** - * Set Persistence. - * - * @param mixed $persistence - * - * @return $this - */ - public function setPersistence($persistence) + public function setPersistence(bool $persistence): self { $this->persistence = $persistence; @@ -230,19 +138,12 @@ public function setPersistence($persistence) /** * {@inheritdoc} */ - public function getPage() + public function getPage(): int { return $this->page; } - /** - * Set Page. - * - * @param int $page - * - * @return $this - */ - public function setPage($page) + public function setPage(int $page): self { $this->page = $page; @@ -252,7 +153,7 @@ public function setPage($page) /** * {@inheritdoc} */ - public function getOptions() + public function getOptions(): array { return $this->options; } @@ -260,7 +161,7 @@ public function getOptions() /** * {@inheritdoc} */ - public function hasOption($name) + public function hasOption(string $name): bool { return array_key_exists($name, $this->options); } @@ -268,7 +169,7 @@ public function hasOption($name) /** * {@inheritdoc} */ - public function getOption($name, $default = null) + public function getOption(string $name, mixed $default = null): mixed { return array_key_exists($name, $this->options) ? $this->options[$name] : $default; } @@ -276,43 +177,24 @@ public function getOption($name, $default = null) /** * {@inheritdoc} */ - public function getMaxPerPage() + public function getMaxPerPage(): int { return $this->limit; } - /** - * Set Limit. - * - * @param int $limit - * - * @return $this - */ - public function setMaxPerPage($limit) + public function setMaxPerPage(int $limit): self { $this->limit = $limit; return $this; } - /** - * Get MaxResults. - * - * @return int - */ - public function getMaxResults() + public function getMaxResults(): int { return $this->maxResults; } - /** - * Set MaxResults. - * - * @param int $maxResults - * - * @return $this - */ - public function setMaxResults($maxResults) + public function setMaxResults(int $maxResults): self { $this->maxResults = $maxResults; @@ -322,41 +204,24 @@ public function setMaxResults($maxResults) /** * {@inheritdoc} */ - public function isSortable() + public function isSortable(): bool { return $this->sortable; } - /** - * Set Sortable. - * - * @param bool $sortable - * - * @return $this - */ - public function setSortable($sortable) + public function setSortable(bool $sortable): self { $this->sortable = $sortable; return $this; } - /** - * {@inheritdoc} - */ - public function isFilterable() + public function isFilterable(): bool { return $this->filterable; } - /** - * Set Filterable. - * - * @param bool $filterable - * - * @return $this - */ - public function setFilterable($filterable) + public function setFilterable(bool $filterable): self { $this->filterable = $filterable; @@ -366,19 +231,12 @@ public function setFilterable($filterable) /** * {@inheritdoc} */ - public function getOrder() + public function getOrder(): int { return $this->order; } - /** - * Set Order. - * - * @param string $order - * - * @return $this - */ - public function setOrder($order) + public function setOrder(int $order): self { $this->order = $order; @@ -388,19 +246,12 @@ public function setOrder($order) /** * {@inheritdoc} */ - public function getSortBy() + public function getSortBy(): string { return $this->sortBy; } - /** - * Set SortBy. - * - * @param string $sortBy - * - * @return $this - */ - public function setSortBy($sortBy) + public function setSortBy(string $sortBy): self { $this->sortBy = $sortBy; @@ -410,51 +261,31 @@ public function setSortBy($sortBy) /** * {@inheritdoc} */ - public function getGroupBy() + public function getGroupBy(): array|string { return $this->groupBy; } - /** - * Set GroupBy. - * - * @param array|string $groupBy - * - * @return $this - */ - public function setGroupBy($groupBy) + public function setGroupBy(array|string $groupBy): self { $this->groupBy = $groupBy; return $this; } - /** - * @param $massActionsInNewTab - * - * @return $this - */ - public function setMassActionsInNewTab($massActionsInNewTab) + public function setMassActionsInNewTab(bool $massActionsInNewTab): self { - $this->massActionsInNewTab = (bool)$massActionsInNewTab; + $this->massActionsInNewTab = $massActionsInNewTab; return $this; } - /** - * @return bool - */ - public function getMassActionsInNewTab() + public function getMassActionsInNewTab(): bool { - return (bool)$this->massActionsInNewTab; + return $this->massActionsInNewTab; } - /** - * @param RowActionInterface $action - * - * @return $this - */ - public function addAction(RowActionInterface $action) + public function addAction(RowActionInterface $action): self { $this->actions[$action->getColumn()][] = $action; @@ -469,7 +300,7 @@ public function getActions(): array /** * {@inheritdoc} */ - public function getGridConfig() + public function getGridConfig(): GridConfigInterface { $config = clone $this; diff --git a/src/Grid/GridConfigBuilderInterface.php b/src/Grid/GridConfigBuilderInterface.php index 39e14d8..38a7e21 100644 --- a/src/Grid/GridConfigBuilderInterface.php +++ b/src/Grid/GridConfigBuilderInterface.php @@ -14,5 +14,5 @@ interface GridConfigBuilderInterface extends GridConfigInterface * * @return GridConfigInterface */ - public function getGridConfig(); + public function getGridConfig(): GridConfigInterface; } diff --git a/src/Grid/GridConfigInterface.php b/src/Grid/GridConfigInterface.php index 4ce5466..b95265e 100644 --- a/src/Grid/GridConfigInterface.php +++ b/src/Grid/GridConfigInterface.php @@ -16,56 +16,56 @@ interface GridConfigInterface * * @return string The grid name */ - public function getName(); + public function getName(): string; /** * Returns the source of the grid. * * @return Source The source of the grid. */ - public function getSource(); + public function getSource(): Source; /** * Returns the grid type used to construct the grid. * * @return GridTypeInterface The grid's type. */ - public function getType(); + public function getType(): GridTypeInterface; /** * Returns the route of the grid. * * @return string The route of the grid. */ - public function getRoute(); + public function getRoute(): string; /** * Returns the route parameters of the grid. * * @return array The route parameters. */ - public function getRouteParameters(); + public function getRouteParameters(): array; /** * Returns whether the grid is persisted. * * @return bool Whether the grid is persisted. */ - public function isPersisted(); + public function isPersisted(): bool; /** * Returns the default page. * * @return int The default page. */ - public function getPage(); + public function getPage(): int; /** * Returns all options passed during the construction of grid. * * @return array */ - public function getOptions(); + public function getOptions(): array; /** * Returns whether a specific option exists. @@ -74,7 +74,7 @@ public function getOptions(); * * @return bool */ - public function hasOption($name); + public function hasOption(string $name): bool; /** * Returns the value of a specific option. @@ -84,61 +84,61 @@ public function hasOption($name); * * @return mixed The option value */ - public function getOption($name, $default = null); + public function getOption(string $name, mixed $default = null): mixed; /** * Returns whether the grid is filterable. * * @return bool Whether the grid is filterable. */ - public function isFilterable(); + public function isFilterable(): bool; /** * Returns whether the grid is sortable. * * @return bool Whether the grid is sortable. */ - public function isSortable(); + public function isSortable(): bool; /** * Returns the maximum number of results of the grid. * * @return int The maximum number of results of the grid. */ - public function getMaxResults(); + public function getMaxResults(): int; /** * Returns the maximum number of items per page. * * @return int The maximum number of items per page. */ - public function getMaxPerPage(); + public function getMaxPerPage(): int; /** * Returns the default order. * * @return string The default order. */ - public function getOrder(); + public function getOrder(): string; /** * Returns the default sort field. * * @return string The default sort field. */ - public function getSortBy(); + public function getSortBy(): string; /** * Returns the default group field. * * @return string|array */ - public function getGroupBy(); + public function getGroupBy(): string|array; /** * Returns whether or not mass actions should be opened in a new tab. * * @return bool */ - public function getMassActionsInNewTab(); + public function getMassActionsInNewTab(): bool; } diff --git a/src/Grid/GridFactory.php b/src/Grid/GridFactory.php index af6207b..160816c 100644 --- a/src/Grid/GridFactory.php +++ b/src/Grid/GridFactory.php @@ -23,10 +23,7 @@ */ class GridFactory implements GridFactoryInterface { - /** - * @var GridRegistryInterface - */ - private $registry; + private GridRegistryInterface $registry; private AuthorizationCheckerInterface $authorizationChecker; @@ -73,7 +70,7 @@ public function __construct( /** * {@inheritdoc} */ - public function create($type = null, Source $source = null, array $options = []) + public function create(string|GridTypeInterface|null $type = null, ?Source $source = null, array $options = []): Grid { return $this->createBuilder($type, $source, $options)->getGrid(); } @@ -81,7 +78,7 @@ public function create($type = null, Source $source = null, array $options = []) /** * {@inheritdoc} */ - public function createBuilder($type = 'grid', Source $source = null, array $options = []) + public function createBuilder(string|GridTypeInterface|null $type = 'grid', ?Source $source = null, array $options = []): GridBuilder { $type = $this->resolveType($type); $options = $this->resolveOptions($type, $source, $options); @@ -111,7 +108,7 @@ public function createBuilder($type = 'grid', Source $source = null, array $opti /** * {@inheritdoc} */ - public function createColumn($name, $type, array $options = []) + public function createColumn(string $name, string|Column $type, array $options = []): Column { if (!$type instanceof Column) { if (!is_string($type)) { @@ -139,14 +136,7 @@ public function createColumn($name, $type, array $options = []) return $column; } - /** - * Returns an instance of type. - * - * @param string|GridTypeInterface $type The type of the grid - * - * @return GridTypeInterface - */ - private function resolveType($type) + private function resolveType(string|GridTypeInterface $type): GridTypeInterface { if (!$type instanceof GridTypeInterface) { if (!is_string($type)) { @@ -159,16 +149,7 @@ private function resolveType($type) return $type; } - /** - * Returns the options resolved. - * - * @param GridTypeInterface $type - * @param Source $source - * @param array $options - * - * @return array - */ - private function resolveOptions(GridTypeInterface $type, Source $source = null, array $options = []) + private function resolveOptions(GridTypeInterface $type, ?Source $source = null, array $options = []): array { $resolver = new OptionsResolver(); diff --git a/src/Grid/GridFactoryInterface.php b/src/Grid/GridFactoryInterface.php index 29fba47..d0e3ae1 100644 --- a/src/Grid/GridFactoryInterface.php +++ b/src/Grid/GridFactoryInterface.php @@ -21,7 +21,7 @@ interface GridFactoryInterface * * @return Grid */ - public function create($type = null, Source $source = null, array $options = []); + public function create(string|GridTypeInterface|null $type = null, ?Source $source = null, array $options = []): Grid; /** * Returns a grid builder. @@ -32,7 +32,7 @@ public function create($type = null, Source $source = null, array $options = []) * * @return GridBuilder */ - public function createBuilder($type = null, Source $source = null, array $options = []); + public function createBuilder(string|GridTypeInterface|null $type = null, ?Source $source = null, array $options = []): GridBuilder; /** * Returns a column. @@ -43,5 +43,5 @@ public function createBuilder($type = null, Source $source = null, array $option * * @return Column */ - public function createColumn($name, $type, array $options = []); + public function createColumn(string $name, string|Column $type, array $options = []): Column; } diff --git a/src/Grid/GridInterface.php b/src/Grid/GridInterface.php index 075a894..496877a 100644 --- a/src/Grid/GridInterface.php +++ b/src/Grid/GridInterface.php @@ -16,12 +16,12 @@ interface GridInterface * * @return $this */ - public function initialize(); + public function initialize(): self; /** * Handles filters, sorts, exports, ... . * * @param Request $request The request */ - public function handleRequest(Request $request); + public function handleRequest(Request $request): self; } diff --git a/src/Grid/GridManager.php b/src/Grid/GridManager.php index 45a5253..034f7d9 100644 --- a/src/Grid/GridManager.php +++ b/src/Grid/GridManager.php @@ -12,29 +12,30 @@ namespace APY\DataGridBundle\Grid; +use Psr\Container\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; class GridManager implements \IteratorAggregate, \Countable { - protected $container; + private ContainerInterface $container; - protected $grids; + private \SplObjectStorage $grids; - protected $routeUrl = null; + private ?string $routeUrl = null; - protected $exportGrid = null; + private ?Grid $exportGrid = null; - protected $massActionGrid = null; + private ?Grid $massActionGrid = null; - const NO_GRID_EX_MSG = 'No grid has been added to the manager.'; + public const NO_GRID_EX_MSG = 'No grid has been added to the manager.'; - const SAME_GRID_HASH_EX_MSG = 'Some grids seem similar. Please set an Indentifier for your grids.'; + public const SAME_GRID_HASH_EX_MSG = 'Some grids seem similar. Please set an Indentifier for your grids.'; public function __construct($container) { $this->container = $container; - $this->grids = new \SplObjectStorage(); + $this->grids = new \SplObjectStorage(); } public function getIterator(): \Traversable @@ -47,12 +48,7 @@ public function count(): int return $this->grids->count(); } - /** - * @param mixed $id - * - * @return Grid - */ - public function createGrid($id = null) + public function createGrid(int|string $id = null): Grid { $grid = $this->container->get('grid'); @@ -65,7 +61,7 @@ public function createGrid($id = null) return $grid; } - public function isReadyForRedirect() + public function isReadyForRedirect(): bool { if ($this->grids->count() == 0) { throw new \RuntimeException(self::NO_GRID_EX_MSG); @@ -78,7 +74,7 @@ public function isReadyForRedirect() // Route url is the same for all grids if ($this->routeUrl === null) { - $grid = $this->grids->current(); + $grid = $this->grids->current(); $this->routeUrl = $grid->getRouteUrl(); } @@ -101,7 +97,7 @@ public function isReadyForRedirect() return $isReadyForRedirect; } - public function isReadyForExport() + public function isReadyForExport(): bool { if ($this->grids->count() == 0) { throw new \RuntimeException(self::NO_GRID_EX_MSG); @@ -131,7 +127,7 @@ public function isReadyForExport() return false; } - public function isMassActionRedirect() + public function isMassActionRedirect(): bool { $this->grids->rewind(); while ($this->grids->valid()) { @@ -149,16 +145,7 @@ public function isMassActionRedirect() return false; } - /** - * Renders a view. - * - * @param string|array|null $param1 The view name or an array of parameters to pass to the view - * @param string|array|null $param2 The view name or an array of parameters to pass to the view - * @param Response|null $response A response instance - * - * @return Response|array A Response instance - */ - public function getGridManagerResponse($param1 = null, $param2 = null, Response $response = null) + public function getGridManagerResponse(string|array|null $param1 = null, string|array|null $param2 = null, Response $response = null): Response|array { $isReadyForRedirect = $this->isReadyForRedirect(); @@ -174,11 +161,11 @@ public function getGridManagerResponse($param1 = null, $param2 = null, Response return new RedirectResponse($this->getRouteUrl()); } else { if (is_array($param1) || $param1 === null) { - $parameters = (array) $param1; - $view = $param2; + $parameters = (array)$param1; + $view = $param2; } else { - $parameters = (array) $param2; - $view = $param1; + $parameters = (array)$param2; + $view = $param1; } $i = 1; @@ -203,13 +190,15 @@ public function getGridManagerResponse($param1 = null, $param2 = null, Response } } - public function getRouteUrl() + public function getRouteUrl(): string { return $this->routeUrl; } - public function setRouteUrl($routeUrl) + public function setRouteUrl(string $routeUrl): self { $this->routeUrl = $routeUrl; + + return $this; } } diff --git a/src/Grid/GridRegistry.php b/src/Grid/GridRegistry.php index d25b9a8..868282c 100644 --- a/src/Grid/GridRegistry.php +++ b/src/Grid/GridRegistry.php @@ -16,27 +16,16 @@ class GridRegistry implements GridRegistryInterface { /** - * List of types. - * * @var GridTypeInterface[] */ - private $types = []; + private array $types = []; /** - * List of columns. - * * @var Column[] */ - private $columns = []; + private array $columns = []; - /** - * Add a grid type. - * - * @param GridTypeInterface $type - * - * @return $this - */ - public function addType(GridTypeInterface $type) + public function addType(GridTypeInterface $type): self { $name = $type->getName(); @@ -52,7 +41,7 @@ public function addType(GridTypeInterface $type) /** * {@inheritdoc} */ - public function getType($name) + public function getType(string $name): GridTypeInterface { if (!$this->hasType($name)) { throw new TypeNotFoundException($name); @@ -66,7 +55,7 @@ public function getType($name) /** * {@inheritdoc} */ - public function hasType($name) + public function hasType(string $name): bool { if (isset($this->types[$name])) { return true; @@ -75,14 +64,7 @@ public function hasType($name) return false; } - /** - * Add a column type. - * - * @param Column $column - * - * @return $this - */ - public function addColumn(Column $column) + public function addColumn(Column $column): self { $type = $column->getType(); @@ -98,7 +80,7 @@ public function addColumn(Column $column) /** * {@inheritdoc} */ - public function getColumn($type) + public function getColumn(string $type): Column { if (!$this->hasColumn($type)) { throw new ColumnNotFoundException($type); @@ -112,7 +94,7 @@ public function getColumn($type) /** * {@inheritdoc} */ - public function hasColumn($type) + public function hasColumn(string $type): bool { if (isset($this->columns[$type])) { return true; diff --git a/src/Grid/GridRegistryInterface.php b/src/Grid/GridRegistryInterface.php index fcbd971..46eadfe 100644 --- a/src/Grid/GridRegistryInterface.php +++ b/src/Grid/GridRegistryInterface.php @@ -18,7 +18,7 @@ interface GridRegistryInterface * * @return GridTypeInterface The type */ - public function getType($name); + public function getType(string $name): GridTypeInterface; /** * Returns whether the given grid type is supported. @@ -27,7 +27,7 @@ public function getType($name); * * @return bool Whether the type is supported. */ - public function hasType($name); + public function hasType(string $name): bool; /** * Returns a column by type. @@ -36,7 +36,7 @@ public function hasType($name); * * @return Column The column */ - public function getColumn($type); + public function getColumn(string $type): Column; /** * Returns whether the given column type is supported. @@ -45,5 +45,5 @@ public function getColumn($type); * * @return bool */ - public function hasColumn($type); + public function hasColumn(string $type): bool; } diff --git a/src/Grid/GridTypeInterface.php b/src/Grid/GridTypeInterface.php index ae68566..66c3eb0 100644 --- a/src/Grid/GridTypeInterface.php +++ b/src/Grid/GridTypeInterface.php @@ -17,19 +17,19 @@ interface GridTypeInterface * @param GridBuilder $builder The grid builder * @param array $options The options */ - public function buildGrid(GridBuilder $builder, array $options = []); + public function buildGrid(GridBuilder $builder, array $options = []): void; /** * Configures the options for this type. * * @param OptionsResolver $resolver The resolver for the options */ - public function configureOptions(OptionsResolver $resolver); + public function configureOptions(OptionsResolver $resolver): void; /** * Returns the name of this type. * * @return string The name of this type. */ - public function getName(); + public function getName(): string; } diff --git a/src/Grid/Helper/ColumnsIterator.php b/src/Grid/Helper/ColumnsIterator.php index a541bde..22f35ee 100644 --- a/src/Grid/Helper/ColumnsIterator.php +++ b/src/Grid/Helper/ColumnsIterator.php @@ -14,14 +14,9 @@ class ColumnsIterator extends \FilterIterator { - /** @var bool */ - protected $showOnlySourceColumns; + private bool $showOnlySourceColumns; - /** - * @param \Iterator $iterator - * @param $showOnlySourceColumns - */ - public function __construct(\Iterator $iterator, $showOnlySourceColumns) + public function __construct(\Iterator $iterator, bool $showOnlySourceColumns) { parent::__construct($iterator); diff --git a/src/Grid/Helper/ORMCountWalker.php b/src/Grid/Helper/ORMCountWalker.php index 9bfc3a9..103b6d1 100644 --- a/src/Grid/Helper/ORMCountWalker.php +++ b/src/Grid/Helper/ORMCountWalker.php @@ -31,10 +31,7 @@ */ class ORMCountWalker extends TreeWalkerAdapter { - /** - * Distinct mode hint name. - */ - const HINT_DISTINCT = 'doctrine_paginator.distinct'; + public const HINT_DISTINCT = 'doctrine_paginator.distinct'; /** * Walks down a SelectStatement AST node, modifying it to retrieve a COUNT. @@ -43,10 +40,10 @@ class ORMCountWalker extends TreeWalkerAdapter * * @throws \RuntimeException */ - public function walkSelectStatement(SelectStatement $AST) + public function walkSelectStatement(SelectStatement $AST): void { $rootComponents = []; - foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) { + foreach ($this->getQueryComponents() as $dqlAlias => $qComp) { if (array_key_exists('parent', $qComp) && $qComp['parent'] === null && $qComp['nestingLevel'] == 0) { $rootComponents[] = [$dqlAlias => $qComp]; } diff --git a/src/Grid/Mapping/Column.php b/src/Grid/Mapping/Column.php index 6420343..dc8a88d 100644 --- a/src/Grid/Mapping/Column.php +++ b/src/Grid/Mapping/Column.php @@ -17,21 +17,22 @@ */ class Column { - protected $metadata; - protected $groups; + private array|string $metadata; - public function __construct($metadata) + private array $groups; + + public function __construct(array|string $metadata) { $this->metadata = $metadata; - $this->groups = isset($metadata['groups']) ? (array) $metadata['groups'] : ['default']; + $this->groups = isset($metadata['groups']) ? (array)$metadata['groups'] : ['default']; } - public function getMetadata() + public function getMetadata(): array|string { return $this->metadata; } - public function getGroups() + public function getGroups(): array { return $this->groups; } diff --git a/src/Grid/Mapping/Driver/Annotation.php b/src/Grid/Mapping/Driver/Annotation.php index a414e09..32a6810 100644 --- a/src/Grid/Mapping/Driver/Annotation.php +++ b/src/Grid/Mapping/Driver/Annotation.php @@ -14,44 +14,51 @@ use APY\DataGridBundle\Grid\Mapping\Column as Column; use APY\DataGridBundle\Grid\Mapping\Source as Source; +use Doctrine\Common\Annotations\AnnotationReader; class Annotation implements DriverInterface { - protected $columns; - protected $filterable; - protected $sortable; - protected $fields; - protected $loaded; - protected $groupBy; + private array $columns; - protected $reader; + private array $filterable; - public function __construct($reader) - { - $this->reader = $reader; + private array $sortable; + + private array $fields; + + private array $loaded; + + private array $groupBy; + + private AnnotationReader $reader; + + public function __construct( + AnnotationReader $reader + ) { + $this->reader = $reader; $this->columns = $this->fields = $this->loaded = $this->groupBy = $this->filterable = $this->sortable = []; } - public function getClassColumns($class, $group = 'default') + public function getClassColumns(string $class, string $group = 'default'): array { $this->loadMetadataFromReader($class, $group); return $this->columns[$class][$group]; } - public function getFieldsMetadata($class, $group = 'default') + public function getFieldsMetadata(string $class, string $group = 'default'): array { $this->loadMetadataFromReader($class, $group); return $this->fields[$class][$group]; } - public function getGroupBy($class, $group = 'default') + public function getGroupBy(string $class, string $group = 'default'): array { return isset($this->groupBy[$class][$group]) ? $this->groupBy[$class][$group] : []; } - protected function loadMetadataFromReader($className, $group = 'default') + protected function loadMetadataFromReader($className, $group = 'default'): void { if (isset($this->loaded[$className][$group])) { return; @@ -99,7 +106,7 @@ protected function loadMetadataFromReader($className, $group = 'default') $this->loaded[$className][$group] = true; } - protected function getMetadataFromClassProperty($className, $class, $name = null, $group = 'default') + protected function getMetadataFromClassProperty(string $className, Column|Source $class, ?string $name = null, string $group = 'default'): void { if ($class instanceof Column) { $metadata = $class->getMetadata(); @@ -110,7 +117,7 @@ protected function getMetadataFromClassProperty($className, $class, $name = null if ($name === null) { // Class Column annotation if (isset($metadata['id'])) { - $metadata['source'] = false; + $metadata['source'] = false; $this->fields[$className][$group][$metadata['id']] = []; } else { throw new \Exception(sprintf('Missing parameter `id` in annotations for extra column of class %s', $className)); @@ -130,7 +137,7 @@ protected function getMetadataFromClassProperty($className, $class, $name = null } // Check the group of the annotation and don't override if an annotation with the group have already been defined - if (isset($metadata['groups']) && !in_array($group, (array) $metadata['groups']) + if (isset($metadata['groups']) && !in_array($group, (array)$metadata['groups']) || isset($this->fields[$className][$group][$metadata['id']]['groups'])) { return; } @@ -155,14 +162,14 @@ protected function getMetadataFromClassProperty($className, $class, $name = null } } - protected function getMetadataFromClass($className, $class, $group) + protected function getMetadataFromClass(string $className, Column|Source $class, string $group): void { if ($class instanceof Source) { foreach ($class->getGroups() as $sourceGroup) { - $this->columns[$className][$sourceGroup] = $class->getColumns(); + $this->columns[$className][$sourceGroup] = $class->getColumns(); $this->filterable[$className][$sourceGroup] = $class->isFilterable(); - $this->sortable[$className][$sourceGroup] = $class->isSortable(); - $this->groupBy[$className][$sourceGroup] = $class->getGroupBy(); + $this->sortable[$className][$sourceGroup] = $class->isSortable(); + $this->groupBy[$className][$sourceGroup] = $class->getGroupBy(); } } elseif ($class instanceof Column) { $this->getMetadataFromClassProperty($className, $class, null, $group); diff --git a/src/Grid/Mapping/Driver/DriverInterface.php b/src/Grid/Mapping/Driver/DriverInterface.php index 07c8e12..21e285f 100644 --- a/src/Grid/Mapping/Driver/DriverInterface.php +++ b/src/Grid/Mapping/Driver/DriverInterface.php @@ -14,9 +14,9 @@ interface DriverInterface { - public function getClassColumns($class, $group = 'default'); + public function getClassColumns(string $class, string $group = 'default'): array; - public function getFieldsMetadata($class, $group = 'default'); + public function getFieldsMetadata(string $class, string $group = 'default'): array; - public function getGroupBy($class, $group = 'default'); + public function getGroupBy(string $class, string $group = 'default'): array; } diff --git a/src/Grid/Mapping/Metadata/DriverHeap.php b/src/Grid/Mapping/Metadata/DriverHeap.php index 10d3764..6fc1913 100644 --- a/src/Grid/Mapping/Metadata/DriverHeap.php +++ b/src/Grid/Mapping/Metadata/DriverHeap.php @@ -21,7 +21,7 @@ class DriverHeap extends \SplPriorityQueue * * @see SplPriorityQueue::compare() */ - public function compare($priority1, $priority2): int + public function compare(mixed $priority1, mixed $priority2): int { if ($priority1 === $priority2) { return 0; diff --git a/src/Grid/Mapping/Metadata/Manager.php b/src/Grid/Mapping/Metadata/Manager.php index 491127a..34f5473 100644 --- a/src/Grid/Mapping/Metadata/Manager.php +++ b/src/Grid/Mapping/Metadata/Manager.php @@ -14,43 +14,40 @@ namespace APY\DataGridBundle\Grid\Mapping\Metadata; +use APY\DataGridBundle\Grid\Mapping\Driver\DriverInterface; + class Manager { /** * @var \APY\DataGridBundle\Grid\Mapping\Driver\DriverInterface[] */ - protected $drivers; + private DriverHeap $drivers; public function __construct() { $this->drivers = new DriverHeap(); } - public function addDriver($driver, $priority) + public function addDriver(DriverInterface $driver, int $priority) { $this->drivers->insert($driver, $priority); } - /** - * @todo remove this hack - * - * @return \APY\DataGridBundle\Grid\Mapping\Metadata\DriverHeap - */ - public function getDrivers() + public function getDrivers(): DriverHeap { return clone $this->drivers; } - public function getMetadata($className, $group = 'default') + public function getMetadata(string $className, string $group = 'default'): Metadata { $metadata = new Metadata(); $columns = $fieldsMetadata = $groupBy = []; foreach ($this->getDrivers() as $driver) { - $columns = array_merge($columns, $driver->getClassColumns($className, $group)); + $columns = array_merge($columns, $driver->getClassColumns($className, $group)); $fieldsMetadata[] = $driver->getFieldsMetadata($className, $group); - $groupBy = array_merge($groupBy, $driver->getGroupBy($className, $group)); + $groupBy = array_merge($groupBy, $driver->getGroupBy($className, $group)); } $mappings = $cols = []; @@ -59,14 +56,14 @@ public function getMetadata($className, $group = 'default') $map = []; foreach ($fieldsMetadata as $field) { - if (isset($field[$fieldName]) && (!isset($field[$fieldName]['groups']) || in_array($group, (array) $field[$fieldName]['groups']))) { + if (isset($field[$fieldName]) && (!isset($field[$fieldName]['groups']) || in_array($group, (array)$field[$fieldName]['groups']))) { $map = array_merge($map, $field[$fieldName]); } } if (!empty($map)) { $mappings[$fieldName] = $map; - $cols[] = $fieldName; + $cols[] = $fieldName; } } diff --git a/src/Grid/Mapping/Metadata/Metadata.php b/src/Grid/Mapping/Metadata/Metadata.php index b0270e8..235c285 100644 --- a/src/Grid/Mapping/Metadata/Metadata.php +++ b/src/Grid/Mapping/Metadata/Metadata.php @@ -12,39 +12,43 @@ namespace APY\DataGridBundle\Grid\Mapping\Metadata; +use APY\DataGridBundle\Grid\Columns; + class Metadata { - protected $name; + private string $name; - protected $fields; + private array $fields; - protected $fieldsMappings; + private array $fieldsMappings; - protected $groupBy; + private array|string $groupBy; - public function setFields($fields) + public function setFields(array $fields): self { $this->fields = $fields; + + return $this; } - public function getFields() + public function getFields(): array { return $this->fields; } - public function setFieldsMappings($fieldsMappings) + public function setFieldsMappings(array $fieldsMappings): self { $this->fieldsMappings = $fieldsMappings; return $this; } - public function hasFieldMapping($field) + public function hasFieldMapping(string $field): bool { return isset($this->fieldsMappings[$field]); } - public function getFieldMapping($field) + public function getFieldMapping(string $field): mixed { return $this->fieldsMappings[$field]; } @@ -54,45 +58,36 @@ public function getFieldsMappings(): array return $this->fieldsMappings; } - public function getFieldMappingType($field) + public function getFieldMappingType(string $field): string { return (isset($this->fieldsMappings[$field]['type'])) ? $this->fieldsMappings[$field]['type'] : 'text'; } - public function setGroupBy($groupBy) + public function setGroupBy(array|string $groupBy): self { $this->groupBy = $groupBy; return $this; } - public function getGroupBy() + public function getGroupBy(): array|string { return $this->groupBy; } - public function setName($name) + public function setName(string $name): self { $this->name = $name; return $this; } - public function getName() + public function getName(): string { return $this->name; } - /** - * @param $columnExtensions - * - * @return \SplObjectStorage - * @throws \Exception - * - * @todo move to another place - * - */ - public function getColumnsFromMapping($columnExtensions) + public function getColumnsFromMapping(Columns $columnExtensions): \SplObjectStorage { $columns = new \SplObjectStorage(); diff --git a/src/Grid/Mapping/Source.php b/src/Grid/Mapping/Source.php index 0f8cd8d..4679408 100644 --- a/src/Grid/Mapping/Source.php +++ b/src/Grid/Mapping/Source.php @@ -17,47 +17,52 @@ */ class Source { - protected $columns; - protected $filterable; - protected $sortable; - protected $groups; - protected $groupBy; + private array $columns; - public function __construct($metadata = []) - { - $this->columns = (isset($metadata['columns']) && $metadata['columns'] != '') ? array_map('trim', explode(',', $metadata['columns'])) : []; + private bool $filterable; + + private bool $sortable; + + private array $groups; + + private array $groupBy; + + public function __construct( + array $metadata = [] + ) { + $this->columns = (isset($metadata['columns']) && $metadata['columns'] != '') ? array_map('trim', explode(',', $metadata['columns'])) : []; $this->filterable = isset($metadata['filterable']) ? $metadata['filterable'] : true; - $this->sortable = isset($metadata['sortable']) ? $metadata['sortable'] : true; - $this->groups = (isset($metadata['groups']) && $metadata['groups'] != '') ? (array) $metadata['groups'] : ['default']; - $this->groupBy = (isset($metadata['groupBy']) && $metadata['groupBy'] != '') ? (array) $metadata['groupBy'] : []; + $this->sortable = isset($metadata['sortable']) ? $metadata['sortable'] : true; + $this->groups = (isset($metadata['groups']) && $metadata['groups'] != '') ? (array)$metadata['groups'] : ['default']; + $this->groupBy = (isset($metadata['groupBy']) && $metadata['groupBy'] != '') ? (array)$metadata['groupBy'] : []; } - public function getColumns() + public function getColumns(): array { return $this->columns; } - public function hasColumns() + public function hasColumns(): bool { return !empty($this->columns); } - public function isFilterable() + public function isFilterable(): bool { return $this->filterable; } - public function isSortable() + public function isSortable(): bool { return $this->sortable; } - public function getGroups() + public function getGroups(): array { return $this->groups; } - public function getGroupBy() + public function getGroupBy(): array { return $this->groupBy; } diff --git a/src/Grid/Row.php b/src/Grid/Row.php index 1408330..de9bef8 100644 --- a/src/Grid/Row.php +++ b/src/Grid/Row.php @@ -16,26 +16,17 @@ class Row { - /** @var array */ - protected $fields; + private array $fields; - /** @var string */ - protected $class; + private string $class; - /** @var string */ - protected $color; + private string $color; - /** @var string|null */ - protected $legend; + private ?string $legend; - /** @var mixed */ - protected $primaryField; + private string $primaryField; - /** @var mixed */ - protected $entity; - - /** @var EntityRepository */ - protected $repository; + private ?EntityRepository $repository; public function __construct() { @@ -43,32 +34,26 @@ public function __construct() $this->color = ''; } - /** - * @param EntityRepository $repository - */ - public function setRepository(EntityRepository $repository) + public function setRepository(EntityRepository $repository): self { $this->repository = $repository; + + return $this; } - public function getRepository(): ?EntityRepository { + public function getRepository(): ?EntityRepository + { return $this->repository; } - /** - * @return null|object - */ - public function getEntity() + public function getEntity(): ?object { $primaryKeyValue = current($this->getPrimaryKeyValue()); return $this->repository->find($primaryKeyValue); } - /** - * @return array - */ - public function getPrimaryKeyValue() + public function getPrimaryKeyValue(): array { $primaryFieldValue = $this->getPrimaryFieldValue(); @@ -80,12 +65,7 @@ public function getPrimaryKeyValue() return ['id' => $primaryFieldValue]; } - /** - * @return array|mixed - * @throws \InvalidArgumentException - * - */ - public function getPrimaryFieldValue() + public function getPrimaryFieldValue(): mixed { if (null === $this->primaryField) { throw new \InvalidArgumentException('Primary column must be defined'); @@ -102,12 +82,7 @@ public function getPrimaryFieldValue() return $this->fields[$this->primaryField]; } - /** - * @param mixed $primaryField - * - * @return $this - */ - public function setPrimaryField($primaryField) + public function setPrimaryField(string $primaryField): self { $this->primaryField = $primaryField; @@ -117,30 +92,25 @@ public function setPrimaryField($primaryField) /** * @return mixed */ - public function getPrimaryField() + public function getPrimaryField(): string { return $this->primaryField; } /** - * @param mixed $columnId - * @param mixed $value + * @param string|int $columnId + * @param mixed $value * * @return $this */ - public function setField($columnId, $value) + public function setField(string|int $columnId, mixed $value): self { $this->fields[$columnId] = $value; return $this; } - /** - * @param mixed $columnId - * - * @return mixed - */ - public function getField($columnId) + public function getField(string|int $columnId): mixed { return isset($this->fields[$columnId]) ? $this->fields[$columnId] : ''; } @@ -150,62 +120,38 @@ public function getFields(): array return $this->fields; } - /** - * @param string $class - * - * @return $this - */ - public function setClass($class) + public function setClass(string $class): self { $this->class = $class; return $this; } - /** - * @return string - */ - public function getClass() + public function getClass(): string { return $this->class; } - /** - * @param string $color - * - * @return $this - */ - public function setColor($color) + public function setColor(string $color): self { $this->color = $color; return $this; } - /** - * @return string - */ - public function getColor() + public function getColor(): string { return $this->color; } - /** - * @param string $legend - * - * @return $this - */ - public function setLegend($legend) + public function setLegend(string $legend): self { $this->legend = $legend; return $this; } - /** - * @return string|null - */ - public function getLegend() + public function getLegend(): ?string { return $this->legend; } diff --git a/src/Grid/Rows.php b/src/Grid/Rows.php index fbc88dc..d1d85fb 100644 --- a/src/Grid/Rows.php +++ b/src/Grid/Rows.php @@ -14,12 +14,8 @@ class Rows implements \IteratorAggregate, \Countable { - /** @var \SplObjectStorage */ - protected $rows; + protected \SplObjectStorage $rows; - /** - * @param array $rows - */ public function __construct(array $rows = []) { $this->rows = new \SplObjectStorage(); @@ -39,14 +35,7 @@ public function getIterator(): \Traversable return $this->rows; } - /** - * Add row. - * - * @param Row $row - * - * @return Rows - */ - public function addRow(Row $row) + public function addRow(Row $row): self { $this->rows->attach($row); @@ -63,12 +52,7 @@ public function count(): int return $this->rows->count(); } - /** - * Returns the iterator as an array. - * - * @return array - */ - public function toArray() + public function toArray(): array { return iterator_to_array($this->getIterator(), true); } diff --git a/src/Grid/Source/Entity.php b/src/Grid/Source/Entity.php index 68c6648..389041a 100644 --- a/src/Grid/Source/Entity.php +++ b/src/Grid/Source/Entity.php @@ -15,13 +15,19 @@ use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Column\JoinColumn; +use APY\DataGridBundle\Grid\Columns; +use APY\DataGridBundle\Grid\Helper\ColumnsIterator; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; +use APY\DataGridBundle\Grid\Mapping\Metadata\Metadata; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Rows; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; +use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\NoResultException; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; @@ -30,97 +36,48 @@ use Doctrine\ORM\Tools\Pagination\CountWalker; use Doctrine\ORM\Tools\Pagination\Paginator; use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Persistence\ObjectRepository; use Symfony\Component\HttpKernel\Kernel; class Entity extends Source { public const HINT_QUERY_HAS_FETCH_JOIN = 'grid.hasFetchJoin'; - const DOT_DQL_ALIAS_PH = '__dot__'; - const COLON_DQL_ALIAS_PH = '__col__'; + public const DOT_DQL_ALIAS_PH = '__dot__'; + public const COLON_DQL_ALIAS_PH = '__col__'; - /** - * @var \Doctrine\ORM\EntityManager - */ - protected $manager; + private EntityManager $manager; - /** - * @var \Doctrine\ORM\QueryBuilder - */ - protected $query; + private QueryBuilder $query; - /** - * @var \Doctrine\ORM\QueryBuilder - */ - protected $querySelectfromSource; + private QueryBuilder $querySelectfromSource; - /** - * @var string e.g Vendor\Bundle\Entity\Page - */ - protected $class; + private string $class; - /** - * @var string e.g Cms:Page - */ - protected $entityName; + private string $entityName; - /** - * @var string e.g mydatabase - */ - protected $managerName; + private string $managerName; - /** - * @var \APY\DataGridBundle\Grid\Mapping\Metadata\Metadata - */ - protected $metadata; + private Metadata $metadata; - /** - * @var \Doctrine\ORM\Mapping\ClassMetadata - */ - protected $ormMetadata; + private ClassMetadata $ormMetadata; - /** - * @var array - */ - protected $joins; + private array $joins; - /** - * @var string - */ - protected $group; + private string $group; - /** - * @var string - */ - protected $groupBy; + private array $groupBy; - /** - * @var array - */ - protected $hints; + private array $hints; - /** - * The QueryBuilder that will be used to start generating query for the DataGrid - * You can override this if the querybuilder is constructed in a business-specific way - * by an external controller/service/repository and you wish to re-use it for the datagrid. - * Typical use-case involves an external repository creating complex default restriction (i.e. multi-tenancy etc) - * which then will be expanded on by the datagrid. - * - * @var QueryBuilder - */ - protected $queryBuilder; + private QueryBuilder $queryBuilder; - /** - * The table alias that will be used in the query to fetch actual data. - * - * @var string - */ - protected $tableAlias; + private string $tableAlias; /** - * @var null + * @var callable|null */ - protected $prepareCountQueryCallback = null; + private $prepareCountQueryCallback = null; /** * Legacy way of accessing the default alias (before it became possible to change it) @@ -128,14 +85,13 @@ class Entity extends Source * * @deprecated */ - const TABLE_ALIAS = '_a'; + public const TABLE_ALIAS = '_a'; - /** - * @param string $entityName e.g Cms:Page - * @param string $managerName e.g. mydatabase - */ - public function __construct($entityName, $group = 'default', $managerName = null) - { + public function __construct( + string $entityName, + string $group = 'default', + ?string $managerName = null + ) { $this->entityName = $entityName; $this->managerName = $managerName; $this->joins = []; @@ -144,7 +100,7 @@ public function __construct($entityName, $group = 'default', $managerName = null $this->setTableAlias(self::TABLE_ALIAS); } - public function initialise(ManagerRegistry $doctrine, Manager $mapping) + public function initialise(ManagerRegistry $doctrine, Manager $mapping): void { $this->manager = version_compare(Kernel::VERSION, '2.1.0', '>=') ? $doctrine->getManager($this->managerName) : $doctrine->getEntityManager($this->managerName); $this->ormMetadata = $this->manager->getClassMetadata($this->entityName); @@ -158,12 +114,7 @@ public function initialise(ManagerRegistry $doctrine, Manager $mapping) $this->groupBy = $this->metadata->getGroupBy(); } - /** - * @param \APY\DataGridBundle\Grid\Column\Column $column - * - * @return string - */ - protected function getTranslationFieldNameWithParents($column) + protected function getTranslationFieldNameWithParents(Column $column): string { $name = $column->getField(); @@ -194,12 +145,7 @@ protected function getTranslationFieldNameWithParents($column) return $column->getField(); } - /** - * @param \APY\DataGridBundle\Grid\Column\Column $column - * - * @return string - */ - protected function getFieldName($column, $withAlias = false) + protected function getFieldName(Column $column, bool $withAlias = false): string { $name = $column->getField(); @@ -261,22 +207,12 @@ protected function getFieldName($column, $withAlias = false) return $name; } - /** - * @param string $colId - * - * @return string - */ - private function fromColIdToAlias($colId) + private function fromColIdToAlias(string $colId): string { return str_replace(['.', ':'], [self::DOT_DQL_ALIAS_PH, self::COLON_DQL_ALIAS_PH], $colId); } - /** - * @param string $fieldName - * - * @return string - */ - protected function getGroupByFieldName($fieldName) + protected function getGroupByFieldName(string $fieldName): string { if (strpos($fieldName, '.') !== false) { $previousParent = ''; @@ -300,17 +236,14 @@ protected function getGroupByFieldName($fieldName) return $name; } - /** - * @param \APY\DataGridBundle\Grid\Columns $columns - */ - public function getColumns($columns) + public function getColumns(Columns $columns): void { foreach ($this->metadata->getColumnsFromMapping($columns) as $column) { $columns->addColumn($column); } } - protected function normalizeOperator($operator) + protected function normalizeOperator(string $operator): string { switch ($operator) { //case Column::OPERATOR_REGEXP: @@ -328,7 +261,7 @@ protected function normalizeOperator($operator) } } - protected function normalizeValue($operator, $value) + protected function normalizeValue(string $operator, mixed $value): mixed { switch ($operator) { //case Column::OPERATOR_REGEXP: @@ -348,12 +281,7 @@ protected function normalizeValue($operator, $value) } } - /** - * Sets the initial QueryBuilder for this DataGrid. - * - * @param QueryBuilder $queryBuilder - */ - public function initQueryBuilder(QueryBuilder $queryBuilder) + public function initQueryBuilder(QueryBuilder $queryBuilder): void { $this->queryBuilder = clone $queryBuilder; @@ -365,10 +293,7 @@ public function initQueryBuilder(QueryBuilder $queryBuilder) } } - /** - * @return QueryBuilder - */ - protected function getQueryBuilder() + protected function getQueryBuilder(): QueryBuilder { //If a custom QB has been provided, use a copy of that one //Otherwise create our own basic one @@ -382,16 +307,13 @@ protected function getQueryBuilder() return $qb; } - /** - * @param \APY\DataGridBundle\Grid\Column\Column[] $columns - * @param int $page Page Number - * @param int $limit Rows Per Page - * @param int $gridDataJunction Grid data junction - * - * @return \APY\DataGridBundle\Grid\Rows - */ - public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION) - { + public function execute( + ColumnsIterator $columns, + int $page = 0, + int $limit = 0, + ?int $maxResults = null, + int $gridDataJunction = Column::DATA_CONJUNCTION + ): Rows { $this->query = $this->getQueryBuilder(); $this->querySelectfromSource = clone $this->query; @@ -577,17 +499,12 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr return $result; } - /** - * @param string $alias - * - * @return string - */ - private function fromAliasToColId($alias) + private function fromAliasToColId(string $alias): string { return str_replace([self::DOT_DQL_ALIAS_PH, self::COLON_DQL_ALIAS_PH], ['.', ':'], $alias); } - public function getTotalCount($maxResults = null) + public function getTotalCount(?int $maxResults = null): int { // Doctrine Bug Workaround: http://www.doctrine-project.org/jira/browse/DDC-1927 $countQueryBuilder = clone $this->query; @@ -642,7 +559,7 @@ public function getTotalCount($maxResults = null) return $count; } - public function getFieldsMetadata($class, $group = 'default') + public function getFieldsMetadata(string $class, string $group = 'default'): array { $result = []; foreach ($this->ormMetadata->getFieldNames() as $name) { @@ -694,14 +611,13 @@ public function getFieldsMetadata($class, $group = 'default') return $result; } - public function populateSelectFilters($columns, $loop = false) + public function populateSelectFilters(array $columns, bool $loop = false): void { /* @var $column Column */ foreach ($columns as $column) { $selectFrom = $column->getSelectFrom(); if ($column->getFilterType() === 'select' && ($selectFrom === 'source' || $selectFrom === 'query')) { - // For negative operators, show all values if ($selectFrom === 'query') { foreach ($column->getFilters('entity') as $filter) { @@ -781,29 +697,21 @@ public function populateSelectFilters($columns, $loop = false) } } - /** - * @param QueryBuilder $countQueryBuilder - */ - public function prepareCountQuery(QueryBuilder $countQueryBuilder) + public function prepareCountQuery(QueryBuilder $countQueryBuilder): void { if (is_callable($this->prepareCountQueryCallback)) { call_user_func($this->prepareCountQueryCallback, $countQueryBuilder); } } - /** - * @param callable $callback - * - * @return $this - */ - public function manipulateCountQuery($callback = null) + public function manipulateCountQuery(?callable $callback = null): self { $this->prepareCountQueryCallback = $callback; return $this; } - public function delete(array $ids) + public function delete(array $ids): void { $repository = $this->getRepository(); @@ -820,63 +728,49 @@ public function delete(array $ids) $this->manager->flush(); } - public function getRepository() + public function getRepository(): EntityRepository|ObjectRepository { return $this->manager->getRepository($this->entityName); } - public function getHash() + public function getHash(): string { return $this->entityName; } - public function addHint($key, $value) + public function addHint(string $key, string $value): void { $this->hints[$key] = $value; } - public function clearHints() + public function clearHints(): void { $this->hints = []; } - /** - * Set groupby column. - * - * @param string $groupBy GroupBy column - */ - public function setGroupBy($groupBy) + public function setGroupBy(array $groupBy): void { $this->groupBy = $groupBy; } - public function getEntityName() + public function getEntityName(): string { return $this->entityName; } - /** - * @param string $tableAlias - */ - public function setTableAlias($tableAlias) + public function setTableAlias(string $tableAlias): self { $this->tableAlias = $tableAlias; + + return $this; } - /** - * @return string - */ - public function getTableAlias() + public function getTableAlias(): string { return $this->tableAlias; } - /** - * @param QueryBuilder $qb - * - * @return boolean - */ - protected function checkIfQueryHasFetchJoin(QueryBuilder $qb) + protected function checkIfQueryHasFetchJoin(QueryBuilder $qb): bool { if (isset($this->hints[self::HINT_QUERY_HAS_FETCH_JOIN])) { return $this->hints[self::HINT_QUERY_HAS_FETCH_JOIN]; diff --git a/src/Grid/Source/Source.php b/src/Grid/Source/Source.php index f442990..6015506 100644 --- a/src/Grid/Source/Source.php +++ b/src/Grid/Source/Source.php @@ -13,38 +13,42 @@ namespace APY\DataGridBundle\Grid\Source; use APY\DataGridBundle\Grid\Column\Column; +use APY\DataGridBundle\Grid\Columns; use APY\DataGridBundle\Grid\Exception\PropertyAccessDeniedException; use APY\DataGridBundle\Grid\Helper\ColumnsIterator; use APY\DataGridBundle\Grid\Mapping\Driver\DriverInterface; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Rows; +use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ManagerRegistry; abstract class Source implements DriverInterface { - protected $prepareQueryCallback = null; - protected $prepareRowCallback = null; - protected $data = null; - protected $items = []; - protected $count; + /** + * @var callable|null + */ + private $prepareQueryCallback = null; /** - * @param \Doctrine\ODM\MongoDB\Query\Builder $queryBuilder + * @var callable|null */ - public function prepareQuery($queryBuilder) + private $prepareRowCallback = null; + + private array|object|null $data = null; + + private array $items = []; + + private int $count; + + public function prepareQuery(QueryBuilder $queryBuilder): void { if (is_callable($this->prepareQueryCallback)) { call_user_func($this->prepareQueryCallback, $queryBuilder); } } - /** - * @param \APY\DataGridBundle\Grid\Row $row - * - * @return \APY\DataGridBundle\Grid\Row|null - */ - public function prepareRow($row) + public function prepareRow(Row $row): ?Row { if (is_callable($this->prepareRowCallback)) { return call_user_func($this->prepareRowCallback, $row); @@ -53,138 +57,73 @@ public function prepareRow($row) return $row; } - /** - * @param callable $callback - * - * @return $this - */ - public function manipulateQuery($callback = null) + public function manipulateQuery(?callable $callback = null): self { $this->prepareQueryCallback = $callback; return $this; } - /** - * @param \Closure $callback - */ - public function manipulateRow(\Closure $callback = null) + public function manipulateRow(?\Closure $callback = null): self { $this->prepareRowCallback = $callback; return $this; } - /** - * Find data for current page. - * - * @abstract - * - * @param ColumnsIterator $columns - * @param int $page Page Number - * @param int $limit Rows Per Page - * @param int $gridDataJunction Grid data junction - * - * @return \APY\DataGridBundle\Grid\Rows - */ - // @todo: typehint? - abstract public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION); + abstract public function execute(ColumnsIterator $columns, int $page = 0, int $limit = 0, ?int $maxResults = null, int $gridDataJunction = Column::DATA_CONJUNCTION): Rows; - /** - * Get Total count of data items. - * - * @param int $maxResults - * - * @return int - */ - abstract public function getTotalCount($maxResults = null); + abstract public function getTotalCount(?int $maxResults = null): int; - abstract public function initialise(ManagerRegistry $doctrine, Manager $mapping); + abstract public function initialise(ManagerRegistry $doctrine, Manager $mapping): void; - /** - * @abstract - * - * @param $columns - */ - abstract public function getColumns($columns); + abstract public function getColumns(Columns $columns): void; - public function getClassColumns($class, $group = 'default') + public function getClassColumns(string $class, string $group = 'default'): array { return []; } - public function getFieldsMetadata($class, $group = 'default') + public function getFieldsMetadata(string $class, string $group = 'default'): array { return []; } - public function getGroupBy($class, $group = 'default') + public function getGroupBy(string $class, string $group = 'default'): array { return []; } - abstract public function populateSelectFilters($columns, $loop = false); + abstract public function populateSelectFilters(array $columns, bool $loop = false): void; - /** - * Return source hash string. - * - * @abstract - */ - abstract public function getHash(); + abstract public function getHash(): string; - /** - * Delete one or more objects. - * - * @abstract - * - * @param array $ids - */ - abstract public function delete(array $ids); + abstract public function delete(array $ids): void; - /** - * Use data instead of fetching the source. - * - * @param array|object $data - */ - public function setData($data) + public function setData(array|object $data): self { $this->data = $data; return $this; } - /** - * Get the loaded data. - * - * @return array|object - */ - public function getData() + public function getData(): array|object|null { return $this->data; } - /** - * Check if data is loaded. - * - * @return bool - */ - public function isDataLoaded() + public function isDataLoaded(): bool { return $this->data !== null; } - /** - * Gets an array of data items for rows from the set data. - * - * @return array - */ - protected function getItemsFromData($columns) + protected function getItemsFromData(Columns $columns): array { $items = []; foreach ($this->data as $key => $item) { foreach ($columns as $column) { - $fieldName = $column->getField(); + $fieldName = $column->getField(); $fieldValue = ''; if ($this instanceof Entity) { @@ -208,8 +147,8 @@ protected function getItemsFromData($columns) if (isset($itemEntity->$fieldName)) { $fieldValue = $itemEntity->$fieldName; } elseif (is_callable([$itemEntity, $fullFunctionName = 'get' . $functionName]) - || is_callable([$itemEntity, $fullFunctionName = 'has' . $functionName]) - || is_callable([$itemEntity, $fullFunctionName = 'is' . $functionName])) { + || is_callable([$itemEntity, $fullFunctionName = 'has' . $functionName]) + || is_callable([$itemEntity, $fullFunctionName = 'is' . $functionName])) { $fieldValue = call_user_func([$itemEntity, $fullFunctionName]); } else { throw new PropertyAccessDeniedException(sprintf('Property "%s" is not public or has no accessor.', $fieldName)); @@ -225,27 +164,16 @@ protected function getItemsFromData($columns) return $items; } - /** - * Find data from array|object. - * - * @param Column[] $columns - * @param int $page - * @param int $limit - * @param int $maxResults - * - * @return Rows - */ - public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = null) + public function executeFromData(Columns $columns, int $page = 0, int $limit = 0, ?int $maxResults = null): Rows { // Populate from data - $items = $this->getItemsFromData($columns); + $items = $this->getItemsFromData($columns); $serializeColumns = []; foreach ($this->data as $key => $item) { - foreach ($columns as $column) { - $fieldName = $column->getField(); - $fieldValue = $items[$key][$fieldName]; + $fieldName = $column->getField(); + $fieldValue = $items[$key][$fieldName]; $dataIsNumeric = ($column->getType() == 'number' || $column->getType() == 'boolean'); if ($column->getType() === 'array') { @@ -259,16 +187,16 @@ public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = n if ($column->getDataJunction() === Column::DATA_DISJUNCTION) { $disjunction = true; - $keep = false; + $keep = false; } else { $disjunction = false; - $keep = true; + $keep = true; } $found = false; foreach ($filters as $filter) { $operator = $filter->getOperator(); - $value = $filter->getValue(); + $value = $filter->getValue(); // Normalize value if (!$dataIsNumeric && !($value instanceof \DateTime)) { @@ -375,7 +303,7 @@ public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = n // Order foreach ($columns as $column) { if ($column->isSorted()) { - $sortType = SORT_REGULAR; + $sortType = SORT_REGULAR; $sortedItems = []; foreach ($items as $key => $item) { $value = $item[$column->getField()]; @@ -384,7 +312,7 @@ public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = n switch ($column->getType()) { case 'text': $sortedItems[$key] = strtolower($value); - $sortType = SORT_STRING; + $sortType = SORT_STRING; break; case 'datetime': case 'date': @@ -398,19 +326,19 @@ public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = n break; case 'boolean': $sortedItems[$key] = $value ? 1 : 0; - $sortType = SORT_NUMERIC; + $sortType = SORT_NUMERIC; break; case 'array': $sortedItems[$key] = json_encode($value); - $sortType = SORT_STRING; + $sortType = SORT_STRING; break; case 'number': $sortedItems[$key] = $value; - $sortType = SORT_NUMERIC; + $sortType = SORT_NUMERIC; break; default: $sortedItems[$key] = $value; - $sortType = SORT_REGULAR; + $sortType = SORT_REGULAR; } } @@ -464,14 +392,13 @@ public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = n return $rows; } - public function populateSelectFiltersFromData($columns, $loop = false) + public function populateSelectFiltersFromData(Columns $columns, bool $loop = false): void { /* @var $column Column */ foreach ($columns as $column) { $selectFrom = $column->getSelectFrom(); if ($column->getFilterType() === 'select' && ($selectFrom === 'source' || $selectFrom === 'query')) { - // For negative operators, show all values if ($selectFrom === 'query') { foreach ($column->getFilters('vector') as $filter) { @@ -496,17 +423,7 @@ public function populateSelectFiltersFromData($columns, $loop = false) case 'datetime': case 'date': case 'time': - // For document - if ($value instanceof \MongoDate || $value instanceof \MongoTimestamp) { - $value = $value->sec; - } - - // Mongodb bug ? timestamp value is on the key 'i' instead of the key 't' - if (is_array($value) && array_keys($value) == ['t', 'i']) { - $value = $value['i']; - } - - $displayedValue = $column->getDisplayedValue($value); + $displayedValue = $column->getDisplayedValue($value); $values[$displayedValue] = $displayedValue; break; case 'array': @@ -539,26 +456,12 @@ public function populateSelectFiltersFromData($columns, $loop = false) } } - /** - * Get Total count of data items. - * - * @return int - */ - public function getTotalCountFromData($maxResults = null) + public function getTotalCountFromData(?int $maxResults = null): int { return $maxResults === null ? $this->count : min($this->count, $maxResults); } - /** - * Prepares string to have almost the same behaviour as with a database, - * removing accents and latin special chars. - * - * @param mixed $inputString - * @param string $type for array type, will serialize datas - * - * @return string the input, serialized for arrays or without accents for strings - */ - protected function prepareStringForLikeCompare($input, $type = null) + protected function prepareStringForLikeCompare(string $input, ?string $type = null) { if ($type === 'array') { $outputString = str_replace(':{i:0;', ':{', serialize($input)); @@ -569,20 +472,20 @@ protected function prepareStringForLikeCompare($input, $type = null) return $outputString; } - private function removeAccents($str) + private function removeAccents(string $str): string { - $entStr = htmlentities($str, ENT_NOQUOTES, 'UTF-8'); + $entStr = htmlentities($str, ENT_NOQUOTES, 'UTF-8'); $noaccentStr = preg_replace('#&([A-za-z])(?:acute|cedil|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $entStr); return preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $noaccentStr); } - protected function prepareColumnValues(Column $column, $values) + protected function prepareColumnValues(Column $column, array $values): array { $existingValues = $column->getValues(); if (!empty($existingValues)) { $intersect = array_intersect_key($existingValues, $values); - $values = array_replace($values, $intersect); + $values = array_replace($values, $intersect); } return $values; diff --git a/src/Grid/Source/Vector.php b/src/Grid/Source/Vector.php index 47ec9c9..471090b 100644 --- a/src/Grid/Source/Vector.php +++ b/src/Grid/Source/Vector.php @@ -218,7 +218,7 @@ public function populateSelectFilters($columns, $loop = false) $this->populateSelectFiltersFromData($columns, $loop); } - public function getTotalCount($maxResults = null) + public function getTotalCount(?int $maxResults = null): int { return $this->getTotalCountFromData($maxResults); } @@ -282,7 +282,7 @@ public function setData($data) } } - public function delete(array $ids) + public function delete(array $ids): void { } diff --git a/src/Grid/Type/GridType.php b/src/Grid/Type/GridType.php index 0315c8f..0fa3fe7 100644 --- a/src/Grid/Type/GridType.php +++ b/src/Grid/Type/GridType.php @@ -16,7 +16,7 @@ class GridType extends AbstractType /** * {@inheritdoc} */ - public function buildGrid(GridBuilder $builder, array $options = []) + public function buildGrid(GridBuilder $builder, array $options = []): void { $builder ->setRoute($options['route']) @@ -40,7 +40,7 @@ public function buildGrid(GridBuilder $builder, array $options = []) /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'source' => null, @@ -87,7 +87,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'grid'; } diff --git a/src/Translation/ColumnTitleAnnotationTranslationExtractor.php b/src/Translation/ColumnTitleAnnotationTranslationExtractor.php index 486dfde..aacd942 100644 --- a/src/Translation/ColumnTitleAnnotationTranslationExtractor.php +++ b/src/Translation/ColumnTitleAnnotationTranslationExtractor.php @@ -9,22 +9,22 @@ use JMS\TranslationBundle\Model\Message; use JMS\TranslationBundle\Model\MessageCatalogue; use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; class ColumnTitleAnnotationTranslationExtractor implements FileVisitorInterface, \PHPParser_NodeVisitor { - private $annotated; - private $catalogue; - private $parsedClassName; + private bool $annotated; + + private ?MessageCatalogue $catalogue; + + private ?string $parsedClassName; public function beforeTraverse(array $nodes) { - $this->annotated = false; + $this->annotated = false; $this->parsedClassName = null; } - public function enterNode(\PHPParser_Node $node) + public function enterNode(\PHPParser_Node $node): void { if ($node instanceof \PHPParser_Node_Stmt_Namespace) { // Base namespace @@ -40,18 +40,19 @@ public function enterNode(\PHPParser_Node $node) } } - public function leaveNode(\PHPParser_Node $node) + public function leaveNode(\PHPParser_Node $node): void { } - public function afterTraverse(array $nodes) + + public function afterTraverse(array $nodes): void { } - public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue) + public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue): void { } - public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, array $ast) + public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, array $ast): void { $this->catalogue = $catalogue; @@ -63,7 +64,7 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar if ($this->annotated) { // Get annotations for the class $annotationDriver = new Annotation(new DoctrineAnnotationReader()); - $manager = new Manager(); + $manager = new Manager(); $manager->addDriver($annotationDriver, -1); $metadata = $manager->getMetadata($this->parsedClassName); @@ -72,14 +73,14 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar $mappedField = $metadata->getFieldMapping($field); if ((!isset($mappedField['visible']) || $mappedField['visible']) && isset($mappedField['title'])) { $message = new Message($mappedField['title']); - $message->addSource(new FileSource((string) $file)); + $message->addSource(new FileSource((string)$file)); $catalogue->add($message); } } } } - public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, \Twig_Node $node) + public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue): void { } } diff --git a/src/Twig/DataGridExtension.php b/src/Twig/DataGridExtension.php index 33044fb..20d5178 100644 --- a/src/Twig/DataGridExtension.php +++ b/src/Twig/DataGridExtension.php @@ -12,7 +12,9 @@ namespace APY\DataGridBundle\Twig; +use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Grid; +use APY\DataGridBundle\Grid\Row; use Pagerfanta\Adapter\NullAdapter; use Pagerfanta\Pagerfanta; use Symfony\Component\Routing\RouterInterface; @@ -32,64 +34,38 @@ */ class DataGridExtension extends AbstractExtension implements GlobalsInterface { - const DEFAULT_TEMPLATE = '@APYDataGrid/blocks.html.twig'; + public const DEFAULT_TEMPLATE = '@APYDataGrid/blocks.html.twig'; /** * @var TemplateWrapper[] */ - protected $templates = []; + private array $templates = []; - /** - * @var string - */ - protected $theme; + private ?string $theme; - /** - * @var RouterInterface - */ - protected $router; + private RouterInterface $router; - /** - * @var array - */ - protected $names; + private array $names; - /** - * @var array - */ - protected $params = []; + private array $params = []; - /** - * @var array - */ - protected $pagerFantaDefs; + private array $pagerFantaDefs; - /** - * @var string - */ - protected $defaultTemplate; + private string $defaultTemplate; - /** - * @param RouterInterface $router - * @param string $defaultTemplate - */ - public function __construct($router, $defaultTemplate) + public function __construct(RouterInterface $router, string $defaultTemplate) { - $this->router = $router; + $this->router = $router; $this->defaultTemplate = $defaultTemplate; } - /** - * @param array $def - */ - public function setPagerFanta(array $def) + public function setPagerFanta(array $def): self { $this->pagerFantaDefs = $def; + + return $this; } - /** - * @return array - */ public function getGlobals(): array { return [ @@ -104,12 +80,7 @@ public function getGlobals(): array ]; } - /** - * Returns a list of functions to add to the existing list. - * - * @return array An array of functions - */ - public function getFunctions() + public function getFunctions(): array { return [ new TwigFunction('grid', [$this, 'getGrid'], [ @@ -153,32 +124,16 @@ public function getFunctions() ]; } - /** - * @param unknown $grid - * @param unknown $theme - * @param string $id - * @param array $params - */ - public function initGrid($grid, $theme = null, $id = '', array $params = []) + public function initGrid(Grid $grid, ?string $theme = null, string|int $id = '', array $params = []): void { - $this->theme = $theme; + $this->theme = $theme; $this->templates = []; $this->names[$grid->getHash()] = ($id == '') ? $grid->getId() : $id; - $this->params = $params; + $this->params = $params; } - /** - * Render grid block. - * - * @param \Twig\Environment $environment - * @param \APY\DataGridBundle\Grid\Grid $grid - * @param string $theme - * @param string $id - * - * @return string - */ - public function getGrid(Environment $environment, $grid, $theme = null, $id = '', array $params = [], $withjs = true) + public function getGrid(Environment $environment, Grid $grid, ?string $theme = null, string|int $id = '', array $params = [], bool $withjs = true): string { $this->initGrid($grid, $theme, $id, $params); @@ -188,55 +143,22 @@ public function getGrid(Environment $environment, $grid, $theme = null, $id = '' return $this->renderBlock($environment, 'grid', ['grid' => $grid, 'withjs' => $withjs]); } - /** - * Render grid block (html only). - * - * @param \Twig\Environment $environment - * @param \APY\DataGridBundle\Grid\Grid $grid - * @param string $theme - * @param string $id - * - * @return string - */ - public function getGridHtml(Environment $environment, $grid, $theme = null, $id = '', array $params = []) + public function getGridHtml(Environment $environment, Grid $grid, ?string $theme = null, string|int $id = '', array $params = []) { return $this->getGrid($environment, $grid, $theme, $id, $params, false); } - /** - * @param \Twig\Environment $environment - * @param string $name - * @param unknown $grid - * - * @return string - */ - public function getGrid_(Environment $environment, $name, $grid) + public function getGrid_(Environment $environment, string $name, Grid $grid): string { return $this->renderBlock($environment, 'grid_' . $name, ['grid' => $grid]); } - /** - * @param \Twig\Environment $environment - * @param unknown $grid - * - * @return string - */ - public function getGridPager(Environment $environment, $grid) + public function getGridPager(Environment $environment, Grid $grid): string { return $this->renderBlock($environment, 'grid_pager', ['grid' => $grid, 'pagerfanta' => $this->pagerFantaDefs['enable']]); } - /** - * Cell Drawing override. - * - * @param \Twig\Environment $environment - * @param \APY\DataGridBundle\Grid\Column\Column $column - * @param \APY\DataGridBundle\Grid\Row $row - * @param \APY\DataGridBundle\Grid\Grid $grid - * - * @return string - */ - public function getGridCell(Environment $environment, $column, $row, $grid) + public function getGridCell(Environment $environment, Column $column, Row $row, Grid $grid): string { $value = $column->renderCell($row->getField($column->getId()), $row, $this->router); @@ -261,16 +183,7 @@ public function getGridCell(Environment $environment, $column, $row, $grid) return $this->renderBlock($environment, 'grid_column_cell', ['grid' => $grid, 'column' => $column, 'row' => $row, 'value' => $value]); } - /** - * Filter Drawing override. - * - * @param \Twig\Environment $environment - * @param \APY\DataGridBundle\Grid\Column\Column $column - * @param \APY\DataGridBundle\Grid\Grid $grid - * - * @return string - */ - public function getGridFilter(Environment $environment, $column, $grid, $submitOnChange = true) + public function getGridFilter(Environment $environment, Column $column, Grid $grid, bool $submitOnChange = true): string { $id = $this->names[$grid->getHash()]; @@ -291,16 +204,7 @@ public function getGridFilter(Environment $environment, $column, $grid, $submitO return ''; } - /** - * Column Operator Drawing override. - * - * @param \Twig\Environment $environment - * @param \APY\DataGridBundle\Grid\Column\Column $column - * @param \APY\DataGridBundle\Grid\Grid $grid - * - * @return string - */ - public function getGridColumnOperator(Environment $environment, $column, $grid, $operator, $submitOnChange = true) + public function getGridColumnOperator(Environment $environment, Column $column, Grid $grid, string $operator, bool $submitOnChange = true): string { return $this->renderBlock($environment, 'grid_column_operator', ['grid' => $grid, 'column' => $column, 'submitOnChange' => $submitOnChange, 'op' => $operator]); } @@ -312,7 +216,7 @@ public function getGridColumnOperator(Environment $environment, $column, $grid, * * @return string */ - public function getGridUrl($section, $grid, $param = null) + public function getGridUrl($section, Grid $grid, ?Column $param = null): string { $prefix = $grid->getRouteUrl() . (strpos($grid->getRouteUrl(), '?') ? '&' : '?') . $grid->getHash() . '['; @@ -334,26 +238,14 @@ public function getGridUrl($section, $grid, $param = null) } } - /** - * @param \Twig\Environment $environment - * @param unknown $grid - * @param unknown $theme - * @param string $id - * @param array $params - * - * @return string - */ - public function getGridSearch(Environment $environment, $grid, $theme = null, $id = '', array $params = []) + public function getGridSearch(Environment $environment, Grid $grid, ?string $theme = null, string|int $id = '', array $params = []): string { $this->initGrid($grid, $theme, $id, $params); return $this->renderBlock($environment, 'grid_search', ['grid' => $grid]); } - /** - * @param unknown $grid - */ - public function getPagerfanta($grid) + public function getPagerfanta(Grid $grid): string { $adapter = new NullAdapter($grid->getTotalCount()); @@ -361,7 +253,7 @@ public function getPagerfanta($grid) $pagerfanta->setMaxPerPage($grid->getLimit()); $pagerfanta->setCurrentPage($grid->getPage() + 1); - $url = $this->getGridUrl('page', $grid, ''); + $url = $this->getGridUrl('page', $grid, ''); $routeGenerator = function ($page) use ($url) { return sprintf('%s%d', $url, $page - 1); }; @@ -372,17 +264,7 @@ public function getPagerfanta($grid) return $html; } - /** - * Render block. - * - * @param \Twig\Environment $environment - * @param string $name - * @param array $parameters - * - * @return string - * @throws \InvalidArgumentException If the block could not be found - */ - protected function renderBlock(Environment $environment, $name, $parameters) + protected function renderBlock(Environment $environment, string $name, array $parameters): string { foreach ($this->getTemplates($environment) as $template) { if ($template->hasBlock($name, [])) { @@ -393,15 +275,7 @@ protected function renderBlock(Environment $environment, $name, $parameters) throw new \InvalidArgumentException(sprintf('Block "%s" doesn\'t exist in grid template "%s".', $name, $this->theme)); } - /** - * Has block. - * - * @param \Twig\Environment $environment - * @param $name string - * - * @return bool - */ - protected function hasBlock(Environment $environment, $name) + protected function hasBlock(Environment $environment, string $name): bool { foreach ($this->getTemplates($environment) as $template) { /** @var $template TemplateWrapper */ @@ -413,15 +287,7 @@ protected function hasBlock(Environment $environment, $name) return false; } - /** - * Template Loader. - * - * @param \Twig\Environment $environment - * - * @return TemplateWrapper[] - * @throws \Exception - */ - protected function getTemplates(Environment $environment) + protected function getTemplates(Environment $environment): array { if (empty($this->templates)) { if ($this->theme instanceof TemplateWrapper) { @@ -439,17 +305,11 @@ protected function getTemplates(Environment $environment) return $this->templates; } - /** - * @param \Twig\Environment $environment - * @param string $theme - * - * @return array - */ - protected function getTemplatesFromString(Environment $environment, $theme) + protected function getTemplatesFromString(Environment $environment, string $theme): array { $this->templates = []; - $template = $environment->load($theme); + $template = $environment->load($theme); $this->templates[] = $template; return $this->templates; From 0e66b4bd391d9b797c222591b128427b0b9ae6ff Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 15 Feb 2023 13:17:24 -0500 Subject: [PATCH 19/38] Various changes to make code work with existing tests --- src/Grid/Action/MassAction.php | 6 +- src/Grid/Action/MassActionInterface.php | 2 +- src/Grid/Action/RowAction.php | 2 +- src/Grid/Action/RowActionInterface.php | 2 +- src/Grid/Column/Column.php | 467 +++----- src/Grid/Column/DateTimeColumn.php | 18 +- src/Grid/Column/NumberColumn.php | 36 +- src/Grid/Columns.php | 3 +- .../Exception/UnexpectedTypeException.php | 2 +- src/Grid/Grid.php | 1020 +++-------------- src/Grid/GridBuilder.php | 3 +- src/Grid/GridConfigBuilder.php | 64 +- src/Grid/GridConfigInterface.php | 14 +- src/Grid/GridFactory.php | 8 +- src/Grid/GridFactoryInterface.php | 2 +- src/Grid/GridManager.php | 6 +- src/Grid/Row.php | 9 +- src/Grid/Source/Entity.php | 12 +- src/Grid/Source/Source.php | 14 +- src/Grid/Source/Vector.php | 89 +- src/Twig/DataGridExtension.php | 4 +- tests/Grid/Column/BooleanColumnTest.php | 16 +- tests/Grid/ColumnsTest.php | 7 +- tests/Grid/GridTest.php | 11 +- 24 files changed, 444 insertions(+), 1373 deletions(-) diff --git a/src/Grid/Action/MassAction.php b/src/Grid/Action/MassAction.php index 2182449..34ef863 100644 --- a/src/Grid/Action/MassAction.php +++ b/src/Grid/Action/MassAction.php @@ -16,7 +16,7 @@ class MassAction implements MassActionInterface { private string $title; - private ?string $callback; + private \Closure|string|null $callback; private bool $confirm; @@ -53,14 +53,14 @@ public function getTitle(): string return $this->title; } - public function setCallback(string $callback): self + public function setCallback(\Closure|string $callback): self { $this->callback = $callback; return $this; } - public function getCallback(): ?string + public function getCallback(): \Closure|string|null { return $this->callback; } diff --git a/src/Grid/Action/MassActionInterface.php b/src/Grid/Action/MassActionInterface.php index c0f2be6..f35037b 100644 --- a/src/Grid/Action/MassActionInterface.php +++ b/src/Grid/Action/MassActionInterface.php @@ -26,7 +26,7 @@ public function getTitle(): string; * * @return string */ - public function getCallback(): ?string; + public function getCallback(): \Closure|string|null; /** * get action confirm. diff --git a/src/Grid/Action/RowAction.php b/src/Grid/Action/RowAction.php index 9f7be5a..ec7c2ce 100644 --- a/src/Grid/Action/RowAction.php +++ b/src/Grid/Action/RowAction.php @@ -124,7 +124,7 @@ public function setColumn(string $column): self return $this; } - public function getColumn(): string + public function getColumn(): ?string { return $this->column; } diff --git a/src/Grid/Action/RowActionInterface.php b/src/Grid/Action/RowActionInterface.php index a937e47..ef74bf0 100644 --- a/src/Grid/Action/RowActionInterface.php +++ b/src/Grid/Action/RowActionInterface.php @@ -57,7 +57,7 @@ public function getTarget(): string; * * @return string */ - public function getColumn(): string; + public function getColumn(): ?string; /** * get route parameters. diff --git a/src/Grid/Column/Column.php b/src/Grid/Column/Column.php index 40f7809..0b9f626 100644 --- a/src/Grid/Column/Column.php +++ b/src/Grid/Column/Column.php @@ -14,7 +14,7 @@ use APY\DataGridBundle\Grid\Filter; use APY\DataGridBundle\Grid\Row; -use Doctrine\Common\Version as DoctrineVersion; +use Doctrine\ORM\Version; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -76,82 +76,79 @@ abstract class Column self::ALIGN_CENTER, ]; - /** - * Internal parameters. - */ - private $id; + protected string|int|null $id; - private $title; + protected ?string $title; - private $sortable; + protected ?bool $sortable; - private $filterable; + protected ?bool $filterable; - private $visible; + protected ?bool $visible; - private $callback; + protected ?\Closure $callback = null; - private $order; + protected ?int $order = null; - private $size; + protected ?int $size; - private $visibleForSource; + protected ?bool $visibleForSource; - private $primary; + protected ?bool $primary; - private $align; + protected ?string $align; - private $inputType; + protected ?string $inputType; - private $field; + protected ?string $field; - private $role; + protected ?string $role; - private $filterType; + protected ?string $filterType; - private $params; + protected ?array $params; - private $isSorted = false; + protected bool $isSorted = false; - private $authorizationChecker; + protected ?AuthorizationCheckerInterface $authorizationChecker = null; - private $data; + protected ?array $data; - private $operatorsVisible; + protected ?bool $operatorsVisible; - private $operators; + protected ?array $operators; - private $defaultOperator; + protected ?string $defaultOperator; - private $values = []; + protected array $values = []; - private $selectFrom; + protected ?string $selectFrom; - private $selectMulti; + protected ?bool $selectMulti; - private $selectExpanded; + protected ?bool $selectExpanded; - private $searchOnClick = false; + protected bool $searchOnClick = false; - private $safe; + protected string|bool|null $safe; - private $separator; + protected ?string $separator; - private $joinType; + protected ?string $joinType; - private $export; + protected ?bool $export; - private $class; + protected ?string $class; - private $isManualField; + protected ?bool $isManualField; - private $useHaving; + protected ?bool $useHaving; - private $isAggregate; + protected ?bool $isAggregate; - private $usePrefixTitle; + protected ?bool $usePrefixTitle; - private $translationDomain; + protected ?string $translationDomain; protected int $dataJunction = self::DATA_CONJUNCTION; @@ -225,7 +222,7 @@ public function getParams(): ?array return $this->params; } - public function getParam($id, $default = null) + public function getParam(string|int $id, mixed $default = null): mixed { return isset($this->params[$id]) ? $this->params[$id] : $default; } @@ -251,85 +248,49 @@ public function renderCell(mixed $value, Row $row, RouterInterface $router): mix * * @return self */ - public function manipulateRenderCell($callback) + public function manipulateRenderCell(\Closure $callback): self { $this->callback = $callback; return $this; } - public function getCallback(): mixed + public function getCallback(): ?\Closure { return $this->callback; } - /** - * Set column identifier. - * - * @param $id - * - * @return self - */ - public function setId($id) + public function setId(string|int|null $id): self { $this->id = $id; return $this; } - /** - * get column identifier. - * - * @return int|string - */ - public function getId() + public function getId(): string|int|null { return $this->id; } - /** - * get column render block identifier. - * - * @return int|string - */ - public function getRenderBlockId() + public function getRenderBlockId(): string|int { // For Mapping fields and aggregate dql functions return str_replace(['.', ':'], '_', $this->id); } - /** - * Set column title. - * - * @param string $title - * - * @return \APY\DataGridBundle\Grid\Column\Column - */ - public function setTitle($title) + public function setTitle(?string $title): self { $this->title = $title; return $this; } - /** - * Get column title. - * - * @return string - */ - public function getTitle() + public function getTitle(): string|bool|null { return $this->title; } - /** - * Set column visibility. - * - * @param bool $visible - * - * @return $this - */ - public function setVisible($visible) + public function setVisible(?bool $visible): self { $this->visible = $visible; @@ -347,39 +308,24 @@ public function isVisible(bool $isExported = false): bool return $visible; } - /** - * Return true if column is sorted. - * - * @return bool return true when column is sorted - */ - public function isSorted() + public function isSorted(): bool { return $this->isSorted; } - public function setSortable($sortable) + public function setSortable(?bool $sortable): self { $this->sortable = $sortable; return $this; } - /** - * column ability to sort. - * - * @return bool return true when column can be sorted - */ - public function isSortable() + public function isSortable(): bool { return $this->sortable; } - /** - * Return true if column is filtered. - * - * @return bool return true when column is filtered - */ - public function isFiltered() + public function isFiltered(): bool { if ($this->hasFromOperandFilter()) { return true; @@ -392,10 +338,7 @@ public function isFiltered() return $this->hasOperatorFilter(); } - /** - * @return bool - */ - private function hasFromOperandFilter() + private function hasFromOperandFilter(): bool { if (!isset($this->data['from'])) { return false; @@ -408,10 +351,7 @@ private function hasFromOperandFilter() return $this->data['from'] != static::DEFAULT_VALUE; } - /** - * @return bool - */ - private function hasToOperandFilter() + private function hasToOperandFilter(): bool { if (!isset($this->data['to'])) { return false; @@ -424,10 +364,7 @@ private function hasToOperandFilter() return $this->data['to'] != static::DEFAULT_VALUE; } - /** - * @return bool - */ - private function hasOperatorFilter() + private function hasOperatorFilter(): bool { if (!isset($this->data['operator'])) { return false; @@ -436,46 +373,24 @@ private function hasOperatorFilter() return $this->data['operator'] === self::OPERATOR_ISNULL || $this->data['operator'] === self::OPERATOR_ISNOTNULL; } - /** - * @param bool $filterable - * - * @return $this - */ - public function setFilterable($filterable) + public function setFilterable(?bool $filterable): self { $this->filterable = $filterable; return $this; } - /** - * column ability to filter. - * - * @return bool return true when column can be filtred - */ - public function isFilterable() + public function isFilterable(): bool { return $this->filterable; } - /** - * get default column order. - * - * @return string asc|desc - */ - public function getDefaultOrder() + public function getDefaultOrder(): string { return 'asc'; } - /** - * set column order. - * - * @param string $order asc|desc - * - * @return \APY\DataGridBundle\Grid\Column\Column - */ - public function setOrder($order) + public function setOrder(?string $order): self { if ($order !== null) { $this->order = $order; @@ -485,24 +400,12 @@ public function setOrder($order) return $this; } - /** - * get column order. - * - * @return string asc|desc - */ - public function getOrder() + public function getOrder(): ?string { return $this->order; } - /** - * Set column width. - * - * @param int $size in pixels - * - * @return \APY\DataGridBundle\Grid\Column\Column - */ - public function setSize($size) + public function setSize(?int $size): self { if ($size < -1) { throw new \InvalidArgumentException(sprintf('Unsupported column size %s, use positive value or -1 for auto resize', $size)); @@ -513,24 +416,12 @@ public function setSize($size) return $this; } - /** - * get column width. - * - * @return int column width in pixels - */ - public function getSize() + public function getSize(): ?int { return $this->size; } - /** - * set filter data from session | request. - * - * @param $data - * - * @return \APY\DataGridBundle\Grid\Column\Column - */ - public function setData($data) + public function setData(array|string|null $data): self { $this->data = ['operator' => $this->getDefaultOperator(), 'from' => static::DEFAULT_VALUE, 'to' => static::DEFAULT_VALUE]; @@ -553,12 +444,7 @@ public function setData($data) return $this; } - /** - * get filter data from session | request. - * - * @return array data - */ - public function getData() + public function getData(): array { $result = []; @@ -581,77 +467,41 @@ public function getData() return $result; } - public function getDataAttribute(): array + public function getDataAttribute(): ?array { return $this->data; } - /** - * Return true if filter value is correct (has to be overridden in each Column class that can be filtered, in order to catch wrong values). - * - * @return bool - */ public function isQueryValid(mixed $query): bool { return true; } - /** - * Set column visibility for source class. - * - * @param $visibleForSource - * - * @return \APY\DataGridBundle\Grid\Column\Column - */ - public function setVisibleForSource($visibleForSource) + public function setVisibleForSource(?bool $visibleForSource): self { $this->visibleForSource = $visibleForSource; return $this; } - /** - * Return true is column in visible for source class. - * - * @return bool - */ - public function isVisibleForSource() + public function isVisibleForSource(): bool { return $this->visibleForSource; } - /** - * Set column as primary. - * - * @param bool $primary - * - * @return $this - */ - public function setPrimary($primary) + public function setPrimary(?bool $primary): self { $this->primary = $primary; return $this; } - /** - * Return true is column in primary. - * - * @return bool - */ - public function isPrimary() + public function isPrimary(): bool { return $this->primary; } - /** - * Set column align. - * - * @param string $align left/right/center - * - * @return $this - */ - public function setAlign($align) + public function setAlign(?string $align): self { if (!in_array($align, self::$aligns)) { throw new \InvalidArgumentException(sprintf('Unsupported align %s, just left, right and center are supported', $align)); @@ -662,63 +512,55 @@ public function setAlign($align) return $this; } - /** - * get column align. - * - * @return bool - */ - public function getAlign() + public function getAlign(): ?string { return $this->align; } - public function setInputType($inputType) + public function setInputType(?string $inputType): self { $this->inputType = $inputType; return $this; } - public function getInputType() + public function getInputType(): ?string { return $this->inputType; } - public function setField($field) + public function setField(?string $field): self { $this->field = $field; return $this; } - public function getField() + public function getField(): ?string { return $this->field; } - public function setRole($role) + public function setRole(?string $role): self { $this->role = $role; return $this; } - public function getRole() + public function getRole(): ?string { return $this->role; } - /** - * Filter. - */ - public function setFilterType($filterType) + public function setFilterType(?string $filterType): self { $this->filterType = strtolower($filterType); return $this; } - public function getFilterType() + public function getFilterType(): ?string { return $this->filterType; } @@ -778,42 +620,32 @@ public function getFilters(string $source): array return $filters; } - public function setDataJunction($dataJunction) + public function setDataJunction(?int $dataJunction): self { $this->dataJunction = $dataJunction; return $this; } - /** - * get data filter junction (how column filters are connected with column data). - * - * @return bool self::DATA_CONJUNCTION | self::DATA_DISJUNCTION - */ - public function getDataJunction() + public function getDataJunction(): int { return $this->dataJunction; } - public function setOperators(array $operators) + public function setOperators(?array $operators): self { $this->operators = $operators; return $this; } - /** - * Return column filter operators. - * - * @return array $operators - */ - public function getOperators() + public function getOperators(): array { // Issue with Doctrine // ------------------- // @see http://www.doctrine-project.org/jira/browse/DDC-1857 // @see http://www.doctrine-project.org/jira/browse/DDC-1858 - if ($this->hasDQLFunction() && version_compare(DoctrineVersion::VERSION, '2.5') < 0) { + if ($this->hasDQLFunction() && version_compare(Version::VERSION, '2.5') < 0) { return array_intersect($this->operators, [ self::OPERATOR_EQ, self::OPERATOR_NEQ, @@ -829,7 +661,7 @@ public function getOperators() return $this->operators; } - public function setDefaultOperator($defaultOperator) + public function setDefaultOperator(?string $defaultOperator): self { // @todo: should this be \InvalidArgumentException? if (!$this->hasOperator($defaultOperator)) { @@ -841,94 +673,84 @@ public function setDefaultOperator($defaultOperator) return $this; } - public function getDefaultOperator() + public function getDefaultOperator(): ?string { return $this->defaultOperator; } - /** - * Return true if $operator is in $operators. - * - * @param string $operator - * - * @return bool - */ - public function hasOperator($operator) + public function hasOperator(string $operator): bool { return in_array($operator, $this->operators); } - public function setOperatorsVisible($operatorsVisible) + public function setOperatorsVisible(?bool $operatorsVisible): self { $this->operatorsVisible = $operatorsVisible; return $this; } - public function getOperatorsVisible() + public function getOperatorsVisible(): ?bool { return $this->operatorsVisible; } - public function setValues(array $values) + public function setValues(array $values): self { $this->values = $values; return $this; } - public function getValues() + public function getValues(): array { return $this->values; } - public function setSelectFrom($selectFrom) + public function setSelectFrom(?string $selectFrom): self { $this->selectFrom = $selectFrom; return $this; } - public function getSelectFrom() + public function getSelectFrom(): ?string { return $this->selectFrom; } - public function getSelectMulti() + public function getSelectMulti(): ?bool { return $this->selectMulti; } - public function setSelectMulti($selectMulti) + public function setSelectMulti(?bool $selectMulti): self { $this->selectMulti = $selectMulti; + + return $this; } - public function getSelectExpanded() + public function getSelectExpanded(): ?bool { return $this->selectExpanded; } - public function setSelectExpanded($selectExpanded) + public function setSelectExpanded(?bool $selectExpanded): self { $this->selectExpanded = $selectExpanded; + + return $this; } - public function hasDQLFunction(&$matches = null) + public function hasDQLFunction(?array &$matches = null): false|int { $regex = '/(?P(?P\w+):(?P\w+)(:)?(?P\w*))$/'; return ($matches === null) ? preg_match($regex, $this->field) : preg_match($regex, $this->field, $matches); } - /** - * Internal function. - * - * @param $authorizationChecker - * - * @return $this - */ - public function setAuthorizationChecker(AuthorizationCheckerInterface $authorizationChecker) + public function setAuthorizationChecker(?AuthorizationCheckerInterface $authorizationChecker): self { $this->authorizationChecker = $authorizationChecker; @@ -940,7 +762,7 @@ public function getAuthorizationChecker(): ?AuthorizationCheckerInterface return $this->authorizationChecker; } - public function getParentType() + public function getParentType(): string { return ''; } @@ -950,167 +772,144 @@ public function getType(): ?string return ''; } - /** - * By default all filers include a JavaScript onchange=submit block. This - * does not make sense in some cases, such as with multi-select filters. - * - * @todo Eventaully make this configurable via annotations? - */ - public function isFilterSubmitOnChange() + public function isFilterSubmitOnChange(): bool { return !$this->getSelectMulti(); } - public function setSearchOnClick($searchOnClick) + public function setSearchOnClick(?bool $searchOnClick): self { $this->searchOnClick = $searchOnClick; return $this; } - public function getSearchOnClick() + public function getSearchOnClick(): bool { return $this->searchOnClick; } - /** - * Allows to set twig escaping parameter (html, js, css, url, html_attr) - * or to display raw value if type is false. - * - * @param string|bool $safeOption can be one of false, html, js, css, url, html_attr - * - * @return \APY\DataGridBundle\Grid\Column\Column - */ - public function setSafe($safeOption) + public function setSafe(string|bool|null $safeOption): self { $this->safe = $safeOption; return $this; } - public function getSafe() + public function getSafe(): string|bool|null { return $this->safe; } - public function setSeparator($separator) + public function setSeparator(?string $separator): self { $this->separator = $separator; return $this; } - public function getSeparator() + public function getSeparator(): ?string { return $this->separator; } - public function setJoinType($type) + public function setJoinType(?string $type): self { $this->joinType = $type; return $this; } - public function getJoinType() + public function getJoinType(): ?string { return $this->joinType; } - public function setExport($export) + public function setExport(?bool $export): self { $this->export = $export; return $this; } - public function getExport() + public function getExport(): ?bool { return $this->export; } - public function setClass($class) + public function setClass(?string $class): self { $this->class = $class; return $this; } - public function getClass() + public function getClass(): ?string { return $this->class; } - public function setIsManualField($isManualField) + public function setIsManualField(?bool $isManualField): self { $this->isManualField = $isManualField; + + return $this; } - public function getIsManualField() + public function getIsManualField(): ?bool { return $this->isManualField; } - public function setUseHaving($useHaving) + public function setUseHaving(?bool $useHaving): self { $this->useHaving = $useHaving; + + return $this; } - public function getUseHaving() + public function getUseHaving(): ?bool { return $this->useHaving; } - public function setIsAggregate($isAggregate) + public function setIsAggregate(?bool $isAggregate): self { $this->isAggregate = $isAggregate; + + return $this; } - public function getIsAggregate() + public function getIsAggregate(): ?bool { return $this->isAggregate; } - public function getUsePrefixTitle() + public function getUsePrefixTitle(): ?bool { return $this->usePrefixTitle; } - public function setUsePrefixTitle($usePrefixTitle) + public function setUsePrefixTitle(?bool $usePrefixTitle): self { $this->usePrefixTitle = $usePrefixTitle; return $this; } - /** - * Get TranslationDomain. - * - * @return string - */ - public function getTranslationDomain() + public function getTranslationDomain(): ?string { return $this->translationDomain; } - /** - * Set TranslationDomain. - * - * @param string $translationDomain - * - * @return $this - */ - public function setTranslationDomain($translationDomain) + public function setTranslationDomain(?string $translationDomain): self { $this->translationDomain = $translationDomain; return $this; } - /** - * @return array - */ - public static function getAvailableOperators() + public static function getAvailableOperators(): array { return self::$availableOperators; } diff --git a/src/Grid/Column/DateTimeColumn.php b/src/Grid/Column/DateTimeColumn.php index 0138c4a..70a8846 100644 --- a/src/Grid/Column/DateTimeColumn.php +++ b/src/Grid/Column/DateTimeColumn.php @@ -22,15 +22,15 @@ class DateTimeColumn extends Column protected int $timeFormat = \IntlDateFormatter::MEDIUM; - protected string $format; + protected ?string $format; protected string $fallbackFormat = 'Y-m-d H:i:s'; - protected string $inputFormat; + protected ?string $inputFormat; protected string $fallbackInputFormat = 'Y-m-d H:i:s'; - protected string $timezone; + protected ?string $timezone; public function __initialize(array $params): void { @@ -137,36 +137,36 @@ protected function getDatetime(\Datetime|\DateTimeImmutable|string|int $data, \D return $date; } - public function setFormat(string $format): self + public function setFormat(?string $format): self { $this->format = $format; return $this; } - public function getFormat(): string + public function getFormat(): ?string { return $this->format; } - public function setInputFormat(string $inputFormat): self + public function setInputFormat(?string $inputFormat): self { $this->inputFormat = $inputFormat; return $this; } - public function getInputFormat(): string + public function getInputFormat(): ?string { return $this->inputFormat; } - public function getTimezone(): string + public function getTimezone(): ?string { return $this->timezone; } - public function setTimezone(string $timezone): self + public function setTimezone(?string $timezone): self { $this->timezone = $timezone; diff --git a/src/Grid/Column/NumberColumn.php b/src/Grid/Column/NumberColumn.php index a6c63cb..fc107fe 100644 --- a/src/Grid/Column/NumberColumn.php +++ b/src/Grid/Column/NumberColumn.php @@ -28,21 +28,21 @@ class NumberColumn extends Column 'spellout' => \NumberFormatter::SPELLOUT, ]; - private int $style; + private ?int $style = null; - private string $locale; + private ?string $locale; private ?int $precision; - private int|bool $grouping; + private int|bool|null $grouping; - private int $roundingMode; + private ?int $roundingMode; private int|string|null $ruleSet; - private string $currencyCode; + private ?string $currencyCode; - private bool $fractional; + private ?bool $fractional; private ?int $maxFractionDigits; @@ -163,7 +163,7 @@ public function getFilters(string $source): array return $filters; } - public function setStyle($style) + public function setStyle(string $style): self { if (!isset(static::$styles[$style])) { throw new \InvalidArgumentException(sprintf('Expected parameter of style "%s", "%s" given', implode('", "', array_keys(static::$styles)), $this->style)); @@ -174,19 +174,19 @@ public function setStyle($style) return $this; } - public function getStyle() + public function getStyle(): ?int { return $this->style; } - public function setLocale(string $locale): self + public function setLocale(?string $locale): self { $this->locale = $locale; return $this; } - public function getLocale(): string + public function getLocale(): ?string { return $this->locale; } @@ -203,31 +203,31 @@ public function getPrecision(): ?int return $this->precision; } - public function setGrouping(int|bool $grouping): self + public function setGrouping(int|bool|null $grouping): self { $this->grouping = $grouping; return $this; } - public function getGrouping(): int|bool + public function getGrouping(): int|bool|null { return $this->grouping; } - public function setRoundingMode(int $roundingMode): self + public function setRoundingMode(?int $roundingMode): self { $this->roundingMode = $roundingMode; return $this; } - public function getRoundingMode(): int + public function getRoundingMode(): ?int { return $this->roundingMode; } - public function setRuleSet(string|int $ruleSet): self + public function setRuleSet(string|int|null $ruleSet): self { $this->ruleSet = $ruleSet; @@ -239,7 +239,7 @@ public function getRuleSet(): int|string|null return $this->ruleSet; } - public function setCurrencyCode(string $currencyCode): self + public function setCurrencyCode(?string $currencyCode): self { $this->currencyCode = $currencyCode; @@ -251,14 +251,14 @@ public function getCurrencyCode(): ?string return $this->currencyCode; } - public function setFractional(bool $fractional): self + public function setFractional(?bool $fractional): self { $this->fractional = $fractional; return $this; } - public function getFractional(): bool + public function getFractional(): ?bool { return $this->fractional; } diff --git a/src/Grid/Columns.php b/src/Grid/Columns.php index 2ba7519..0ddf849 100644 --- a/src/Grid/Columns.php +++ b/src/Grid/Columns.php @@ -12,7 +12,6 @@ namespace APY\DataGridBundle\Grid; -use APY\DataGridBundle\Grid\Column\ActionsColumn; use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Helper\ColumnsIterator; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -110,7 +109,7 @@ public function hasExtensionForColumnType(string $type): bool return isset($this->extensions[$type]); } - public function getExtensionForColumnType(string $type): bool + public function getExtensionForColumnType(string $type): mixed { // @todo: should not index be checked? return $this->extensions[$type]; diff --git a/src/Grid/Exception/UnexpectedTypeException.php b/src/Grid/Exception/UnexpectedTypeException.php index 47073c0..2d9c526 100644 --- a/src/Grid/Exception/UnexpectedTypeException.php +++ b/src/Grid/Exception/UnexpectedTypeException.php @@ -9,7 +9,7 @@ */ class UnexpectedTypeException extends \InvalidArgumentException { - public function __construct(string $value, int $expectedType) + public function __construct(mixed $value, mixed $expectedType) { parent::__construct( sprintf( diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index 93db2f9..f1bade1 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -29,12 +29,14 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; +use Twig\TemplateWrapper; class Grid implements GridInterface { @@ -69,15 +71,7 @@ class Grid implements GridInterface public const HAS_FILTER_NO_REQUEST_HANDLED_EX_MSG = 'hasFilters method is only available in the manipulate callback function or after the call of the method isRedirected of the grid.'; public const TWEAK_NOT_DEFINED_EX_MSG = 'Tweak %s is not defined.'; - /** - * @var \Symfony\Component\DependencyInjection\Container - */ - private $container; - - /** - * @var \Symfony\Component\Routing\Router - */ - private $router; + private RouterInterface $router; private Environment $twig; @@ -91,264 +85,113 @@ class Grid implements GridInterface private string $kernelCharset; - /** - * @var null|\Symfony\Component\HttpFoundation\Session\Session; - */ - private $session; + private ?SessionInterface $session = null; - /** - * @var \Symfony\Component\HttpFoundation\Request - */ - private $request; + private ?Request $request; - /** - * @var \Symfony\Component\Security\Core\Authorization\AuthorizationChecker - */ - private $securityContext; + private AuthorizationCheckerInterface $securityContext; - /** - * @var string - */ - protected $id; + protected ?string $id; - /** - * @var string - */ - protected $hash; + protected ?string $hash = null; - /** - * @var string - */ - private $routeUrl; + private ?string $routeUrl = null; - /** - * @var array - */ - private $routeParameters; + private ?array $routeParameters; - /** - * @var \APY\DataGridBundle\Grid\Source\Source - */ - private $source; + private ?Source $source = null; - /** - * @var bool - */ - private $prepared = false; + private bool $prepared = false; - /** - * @var int - */ - private $totalCount; + private ?int $totalCount = null; - /** - * @var int - */ - private $page = 0; + private int $page = 0; - /** - * @var int - */ - private $limit; + private ?int $limit = null; - /** - * @var array - */ - private $limits = []; + private array $limits = []; - /** - * @var \APY\DataGridBundle\Grid\Columns|\APY\DataGridBundle\Grid\Column\Column[] - */ - private $columns; + private array|Columns|null $columns; - /** - * @var \APY\DataGridBundle\Grid\Rows - */ - private $rows; + private array|Rows|null $rows = null; /** * @var \APY\DataGridBundle\Grid\Action\MassAction[] */ - private $massActions = []; + private array $massActions = []; /** * @var \APY\DataGridBundle\Grid\Action\RowAction[] */ - private $rowActions = []; + private array $rowActions = []; - /** - * @var bool - */ - private $showFilters = true; + private bool $showFilters = true; - /** - * @var bool - */ - private $showTitles = true; + private bool $showTitles = true; - /** - * @var array|object request - */ - private $requestData; + private string|array|object|null $requestData; - /** - * @var array|object session - */ - private $sessionData = []; + private array|object $sessionData = []; - /** - * @var string - */ - private $prefixTitle = ''; + private string $prefixTitle = ''; - /** - * @var bool - */ - private $persistence = false; + private bool $persistence = false; - /** - * @var bool - */ - private $newSession = false; + private bool $newSession = false; - /** - * @var string - */ - private $noDataMessage; + private ?string $noDataMessage; - /** - * @var string - */ - private $noResultMessage; + private ?string $noResultMessage; /** * @var \APY\DataGridBundle\Grid\Export\Export[] */ - private $exports = []; + private array $exports = []; - /** - * @var bool - */ - private $redirect = null; + private ?bool $redirect = null; - /** - * @var bool - */ - private $isReadyForExport = false; + private bool $isReadyForExport = false; - /** - * @var Response - */ - private $exportResponse; + private ?Response $exportResponse; - /** - * @var Response - */ - private $massActionResponse; + private ?Response $massActionResponse = null; - /** - * @var int - */ - private $maxResults; + private ?int $maxResults = null; - /** - * @var array - */ - private $items = []; + private int $dataJunction = Column::DATA_CONJUNCTION; - /** - * Data junction of the grid. - * - * @var int - */ - private $dataJunction = Column::DATA_CONJUNCTION; + private array $permanentFilters = []; - /** - * Permanent filters. - * - * @var array - */ - private $permanentFilters = []; + private array $defaultFilters = []; - /** - * Default filters. - * - * @var array - */ - private $defaultFilters = []; + private ?string $defaultOrder = null; - /** - * Default order (e.g. my_column_id|asc). - * - * @var string - */ - private $defaultOrder; + private ?int $defaultLimit = null; - /** - * Default limit. - * - * @var int - */ - private $defaultLimit; + private ?int $defaultPage = null; - /** - * Default page. - * - * @var int - */ - private $defaultPage; + private array $tweaks = []; - /** - * Tweaks. - * - * @var array - */ - private $tweaks = []; + private ?string $defaultTweak = null; - /** - * Default Tweak. - * - * @var string - */ - private $defaultTweak; - - /** - * Filters in session. - * - * @var array - */ - private $sessionFilters; + private ?array $sessionFilters = null; - // Lazy parameters - private $lazyAddColumn = []; + private array $lazyAddColumn = []; - private $lazyHiddenColumns = []; + private array $lazyHiddenColumns = []; - private $lazyVisibleColumns = []; + private array $lazyVisibleColumns = []; - private $lazyHideShowColumns = []; + private array $lazyHideShowColumns = []; - // Lazy parameters for the action column - private $actionsColumnSize; + private ?int $actionsColumnSize; - private $actionsColumnTitle; + private ?string $actionsColumnTitle; - private $massActionsInNewTab; + private ?bool $massActionsInNewTab; - /** - * The grid configuration. - * - * @var GridConfigInterface - */ - private $config; + private ?GridConfigInterface $config; - /** - * Constructor. - * - * @param Container $container - * @param string $id set if you are using more then one grid inside controller - * @param GridConfigInterface|null $config The grid configuration. - */ public function __construct( AuthorizationCheckerInterface $authorizationChecker, RouterInterface $router, @@ -359,8 +202,8 @@ public function __construct( Manager $mapping, KernelInterface $kernel, TranslatorInterface $translator, - $id = '', - GridConfigInterface $config = null + ?string $id = '', + ?GridConfigInterface $config = null ) { $this->config = $config; @@ -474,7 +317,7 @@ public function initialize(): self $this ->setMaxResults($config->getMaxResults()) ->setPage($config->getPage()) - ->setMassActionsInNewTab($config->getMassActionsInNewTab()); + ->setMassActionsInNewTab((bool)$config->getMassActionsInNewTab()); return $this; } @@ -482,7 +325,7 @@ public function initialize(): self /** * {@inheritdoc} */ - public function handleRequest(Request $request): self + public function handleRequest(Request $request, $dumpRequestData = false): self { if (null === $this->source) { throw new \LogicException(self::SOURCE_NOT_SETTED_EX_MSG); @@ -520,16 +363,7 @@ public function handleRequest(Request $request): self return $this; } - /** - * Sets Source to the Grid. - * - * @param $source - * - * @return self - * @throws \InvalidArgumentException - * - */ - public function setSource(Source $source) + public function setSource(?Source $source): self { if ($this->source !== null) { throw new \InvalidArgumentException(self::SOURCE_ALREADY_SETTED_EX_MSG); @@ -545,15 +379,12 @@ public function setSource(Source $source) return $this; } - public function getSource() + public function getSource(): ?Source { return $this->source; } - /** - * Handle the grid redirection, export, etc.. - */ - public function isReadyForRedirect() + public function isReadyForRedirect(): ?bool { if ($this->source === null) { throw new \Exception(self::SOURCE_NOT_SETTED_EX_MSG); @@ -600,12 +431,12 @@ public function isReadyForRedirect() return $this->redirect; } - protected function getCurrentUri() + protected function getCurrentUri(): string { return $this->request->getScheme() . '://' . $this->request->getHttpHost() . $this->request->getBaseUrl() . $this->request->getPathInfo(); } - protected function processPersistence() + protected function processPersistence(): void { $referer = strtok($this->request->headers->get('referer'), '?'); @@ -622,7 +453,7 @@ protected function processPersistence() } } - protected function processLazyParameters() + protected function processLazyParameters(): void { // Additional columns foreach ($this->lazyAddColumn as $column) { @@ -655,7 +486,7 @@ protected function processLazyParameters() /** * Reads data from the request and write this data to the session. */ - protected function processRequestData() + protected function processRequestData(): void { $this->processMassActions($this->getFromRequest(self::REQUEST_QUERY_MASS_ACTION)); @@ -675,15 +506,7 @@ protected function processRequestData() $this->saveSession(); } - /** - * Process mass actions. - * - * @param int $actionId - * - * @throws \RuntimeException - * @throws \OutOfBoundsException - */ - protected function processMassActions($actionId) + protected function processMassActions(int|string|null $actionId): void { if ($actionId > -1 && '' !== $actionId) { if (array_key_exists($actionId, $this->massActions)) { @@ -729,16 +552,7 @@ protected function processMassActions($actionId) } } - /** - * Process exports. - * - * @param int $exportId - * - * @return bool - * @throws \OutOfBoundsException - * - */ - protected function processExports($exportId) + protected function processExports(?int $exportId): bool { if ($exportId > -1 && '' !== $exportId) { if (array_key_exists($exportId, $this->exports)) { @@ -771,16 +585,7 @@ protected function processExports($exportId) return false; } - /** - * Process tweaks. - * - * @param int $tweakId - * - * @return bool - * @throws \OutOfBoundsException - * - */ - protected function processTweaks($tweakId) + protected function processTweaks(int|string|null $tweakId): bool { if ($tweakId !== null) { if (array_key_exists($tweakId, $this->tweaks)) { @@ -880,7 +685,7 @@ protected function processTweaks($tweakId) return false; } - protected function processRequestFilters() + protected function processRequestFilters(): bool { $filtering = false; foreach ($this->columns as $column) { @@ -914,7 +719,7 @@ protected function processRequestFilters() return $filtering; } - protected function processPage($page, $filtering = false) + protected function processPage(?int $page, bool $filtering = false): void { // Set to the first page if this is a request of order, limit, mass action or filtering if ($this->getFromRequest(self::REQUEST_QUERY_ORDER) !== null @@ -927,7 +732,7 @@ protected function processPage($page, $filtering = false) } } - protected function processOrder($order) + protected function processOrder(int|string|null $order): void { if ($order !== null) { [$columnId, $columnOrder] = explode('|', $order); @@ -939,14 +744,14 @@ protected function processOrder($order) } } - protected function processLimit($limit) + protected function processLimit(?int $limit): void { if (isset($this->limits[$limit])) { $this->set(self::REQUEST_QUERY_LIMIT, $limit); } } - protected function setDefaultSessionData() + protected function setDefaultSessionData(): void { // Default filters $this->processDefaultFilters(); @@ -991,10 +796,7 @@ protected function setDefaultSessionData() $this->saveSession(); } - /** - * Store permanent filters to the session and disable the filter capability for the column if there are permanent filters. - */ - protected function processFilters($permanent = true) + protected function processFilters(bool $permanent = true): void { foreach (($permanent ? $this->permanentFilters : $this->defaultFilters) as $columnId => $value) { /* @var $column Column */ @@ -1031,21 +833,18 @@ protected function processFilters($permanent = true) } } - protected function processPermanentFilters() + protected function processPermanentFilters(): void { $this->processFilters(); $this->saveSession(); } - protected function processDefaultFilters() + protected function processDefaultFilters(): void { $this->processFilters(false); } - /** - * Configures the grid with the data read from the session. - */ - protected function processSessionData() + protected function processSessionData(): void { // Filters foreach ($this->columns as $column) { @@ -1076,14 +875,7 @@ protected function processSessionData() } } - /** - * Prepare Grid for Drawing. - * - * @return self - * @throws \Exception - * - */ - protected function prepare() + protected function prepare(): self { if ($this->prepared) { return $this; @@ -1152,13 +944,11 @@ protected function prepare() } /** - * Reads data from the request. + * @param string $key * - * @param string $key A unique key identifying the data - * - * @return mixed Data associated with the key or null if the key is not found + * @return mixed|void */ - protected function getFromRequest($key) + protected function getFromRequest(string $key) { if (isset($this->requestData[$key])) { return $this->requestData[$key]; @@ -1166,26 +956,18 @@ protected function getFromRequest($key) } /** - * Reads data from the session. - * - * @param string $key A unique key identifying your data + * @param string $key * - * @return mixed Data associated with the key or null if the key is not found + * @return mixed|void */ - protected function get($key) + protected function get(?string $key) { if (isset($this->sessionData[$key])) { return $this->sessionData[$key]; } } - /** - * Writes data to the session. - * - * @param string $key A unique key identifying the data - * @param mixed $data Data associated with the key - */ - protected function set($key, $data) + protected function set(string $key, mixed $data): void { // Only the filters values are removed from the session $fromIsEmpty = isset($data['from']) && ((is_string($data['from']) && $data['from'] === '') || (is_array($data['from']) && $data['from'][0] === '')); @@ -1199,46 +981,31 @@ protected function set($key, $data) } } - protected function saveSession() + protected function saveSession(): void { if (!empty($this->sessionData) && !empty($this->hash) && null !== $this->session) { $this->session->set($this->hash, $this->sessionData); } } - protected function createHash() + protected function createHash(): void { $this->hash = 'grid_' . (empty($this->id) ? md5($this->request->get('_controller') . $this->columns->getHash() . $this->source->getHash()) : $this->getId()); } - public function getHash() + public function getHash(): ?string { return $this->hash; } - /** - * Adds custom column to the grid. - * - * @param $column - * @param int $position - * - * @return self - */ - public function addColumn($column, $position = 0) + public function addColumn(Column $column, int $position = 0): self { $this->lazyAddColumn[] = ['column' => $column, 'position' => $position]; return $this; } - /** - * Get a column by its identifier. - * - * @param $columnId - * - * @return Column - */ - public function getColumn($columnId) + public function getColumn(string|int $columnId): ?Column { foreach ($this->lazyAddColumn as $column) { if ($column['column']->getId() == $columnId) { @@ -1249,12 +1016,7 @@ public function getColumn($columnId) return $this->columns->getColumnById($columnId); } - /** - * Returns Grid Columns. - * - * @return Column[]|Columns - */ - public function getColumns() + public function getColumns(): array|Columns|null { return $this->columns; } @@ -1264,14 +1026,7 @@ public function getLazyAddColumn(): array return $this->lazyAddColumn; } - /** - * Returns true if column exists in columns and lazyAddColumn properties. - * - * @param $columnId - * - * @return bool - */ - public function hasColumn($columnId) + public function hasColumn(string|int $columnId): bool { foreach ($this->lazyAddColumn as $column) { if ($column['column']->getId() == $columnId) { @@ -1282,45 +1037,21 @@ public function hasColumn($columnId) return $this->columns->hasColumnById($columnId); } - /** - * Sets Array of Columns to the grid. - * - * @param $columns - * - * @return self - */ - public function setColumns(Columns $columns) + public function setColumns(?Columns $columns): self { $this->columns = $columns; return $this; } - /** - * Sets order of Columns passing an array of column ids - * If the list of ids is uncomplete, the remaining columns will be - * placed after. - * - * @param array $columnIds - * @param bool $keepOtherColumns - * - * @return self - */ - public function setColumnsOrder(array $columnIds, $keepOtherColumns = true) + public function setColumnsOrder(array $columnIds, bool $keepOtherColumns = true): self { $this->columns->setColumnsOrder($columnIds, $keepOtherColumns); return $this; } - /** - * Adds Mass Action. - * - * @param Action\MassActionInterface $action - * - * @return self - */ - public function addMassAction(MassActionInterface $action) + public function addMassAction(MassActionInterface $action): self { if ($action->getRole() === null || $this->securityContext->isGranted($action->getRole())) { $this->massActions[] = $action; @@ -1329,12 +1060,7 @@ public function addMassAction(MassActionInterface $action) return $this; } - /** - * Returns Mass Actions. - * - * @return Action\MassAction[] - */ - public function getMassActions() + public function getMassActions(): array { return $this->massActions; } @@ -1349,7 +1075,7 @@ public function getMassActions() * * @return self */ - public function addTweak($title, array $tweak, $id = null, $group = null) + public function addTweak(string $title, array $tweak, ?string $id = null, ?string $group = null): self { if ($id !== null && !preg_match('/^[0-9a-zA-Z_\+-]+$/', $id)) { throw new \InvalidArgumentException(sprintf(self::TWEAK_MALFORMED_ID_EX_MSG, $id)); @@ -1365,13 +1091,7 @@ public function addTweak($title, array $tweak, $id = null, $group = null) return $this; } - /** - * Returns tweaks - * Add the url of the tweak. - * - * @return array - */ - public function getTweaks() + public function getTweaks(): array { $separator = strpos($this->getRouteUrl(), '?') ? '&' : '?'; $url = $this->getRouteUrl() . $separator . $this->getHash() . '[' . self::REQUEST_QUERY_TWEAK . ']='; @@ -1388,17 +1108,12 @@ public function getAllTweaks(): ?array return $this->tweaks; } - public function getActiveTweaks() + public function getActiveTweaks(): array { return (array)$this->get('tweaks'); } - /** - * Returns a tweak. - * - * @return array - */ - public function getTweak($id) + public function getTweak(string|int $id): array { $tweaks = $this->getTweaks(); if (isset($tweaks[$id])) { @@ -1408,12 +1123,7 @@ public function getTweak($id) throw new \InvalidArgumentException(sprintf(self::NOT_VALID_TWEAK_ID_EX_MSG, $id)); } - /** - * Returns tweaks with a specific group. - * - * @return array - */ - public function getTweaksGroup($group) + public function getTweaksGroup(string $group): array { $tweaksGroup = $this->getTweaks(); @@ -1426,21 +1136,14 @@ public function getTweaksGroup($group) return $tweaksGroup; } - public function getActiveTweakGroup($group) + public function getActiveTweakGroup(string $group): array|int|string { $tweaks = $this->getActiveTweaks(); return isset($tweaks[$group]) ? $tweaks[$group] : -1; } - /** - * Adds Row Action. - * - * @param Action\RowActionInterface $action - * - * @return self - */ - public function addRowAction(RowActionInterface $action) + public function addRowAction(RowActionInterface $action): self { if ($action->getRole() === null || $this->securityContext->isGranted($action->getRole())) { $this->rowActions[$action->getColumn()][] = $action; @@ -1449,29 +1152,15 @@ public function addRowAction(RowActionInterface $action) return $this; } - /** - * Returns Row Actions. - * - * @return Action\RowAction[] - */ - public function getRowActions() + public function getRowActions(): array { return $this->rowActions; } - /** - * Sets template for export. - * - * @param \Twig\TemplateWrapper|string $template - * - * @return self - * @throws \Exception - * - */ - public function setTemplate($template) + public function setTemplate(TemplateWrapper|string|bool|null $template): self { if ($template !== null) { - if ($template instanceof \Twig\TemplateWrapper) { + if ($template instanceof TemplateWrapper) { $template = '__SELF__' . $template->getTemplateName(); } elseif (!is_string($template)) { throw new \Exception(self::TWIG_TEMPLATE_LOAD_EX_MSG); @@ -1489,24 +1178,12 @@ public function setTemplate($template) return $this; } - /** - * Returns template. - * - * @return \Twig\TemplateWrapper|string - */ - public function getTemplate() + public function getTemplate(): TemplateWrapper|string|null { return $this->get(self::REQUEST_QUERY_TEMPLATE); } - /** - * Adds Export. - * - * @param ExportInterface $export - * - * @return self - */ - public function addExport(ExportInterface $export) + public function addExport(ExportInterface $export): self { if ($export->getRole() === null || $this->securityContext->isGranted($export->getRole())) { $this->exports[] = $export; @@ -1515,81 +1192,41 @@ public function addExport(ExportInterface $export) return $this; } - /** - * Returns exports. - * - * @return ExportInterface[] - */ - public function getExports() + public function getExports(): array { return $this->exports; } - /** - * Returns the export response. - * - * @return Export[] - */ - public function getExportResponse() + public function getExportResponse(): Response { return $this->exportResponse; } - /** - * Returns the mass action response. - * - * @return Export[] - */ - public function getMassActionResponse() + public function getMassActionResponse(): Response { return $this->massActionResponse; } - /** - * Sets Route Parameters. - * - * @param string $parameter - * @param mixed $value - * - * @return self - */ - public function setRouteParameter($parameter, $value) + public function setRouteParameter(string $parameter, mixed $value): self { $this->routeParameters[$parameter] = $value; return $this; } - /** - * Returns Route Parameters. - * - * @return array - */ - public function getRouteParameters() + public function getRouteParameters(): array { return $this->routeParameters; } - /** - * Sets Route URL. - * - * @param string $routeUrl - * - * @return self - */ - public function setRouteUrl($routeUrl) + public function setRouteUrl(?string $routeUrl): self { $this->routeUrl = $routeUrl; return $this; } - /** - * Returns Route URL. - * - * @return string - */ - public function getRouteUrl() + public function getRouteUrl(): ?string { if ($this->routeUrl === null) { $this->routeUrl = $this->router->generate($this->request->get('_route'), $this->getRouteParameters()); @@ -1598,25 +1235,17 @@ public function getRouteUrl() return $this->routeUrl; } - public function isReadyForExport() + public function isReadyForExport(): ?bool { return $this->isReadyForExport; } - public function isMassActionRedirect() + public function isMassActionRedirect(): bool { return $this->massActionResponse instanceof Response; } - /** - * Set value for filters. - * - * @param array $filters Hash of columnName => initValue - * @param bool $permanent filters ? - * - * @return self - */ - protected function setFilters(array $filters, $permanent = true) + protected function setFilters(array $filters, bool $permanent = true): self { foreach ($filters as $columnId => $value) { if ($permanent) { @@ -1639,38 +1268,17 @@ public function getDefaultFilters(): array return $this->defaultFilters; } - /** - * Set permanent value for filters. - * - * @param array $filters Hash of columnName => initValue - * - * @return self - */ - public function setPermanentFilters(array $filters) + public function setPermanentFilters(array $filters): self { return $this->setFilters($filters); } - /** - * Set default value for filters. - * - * @param array $filters Hash of columnName => initValue - * - * @return self - */ - public function setDefaultFilters(array $filters) + public function setDefaultFilters(array $filters): self { return $this->setFilters($filters, false); } - /** - * Set the default grid order. - * - * @param $columnId - * - * @return self - */ - public function setDefaultOrder($columnId, $order) + public function setDefaultOrder(string|int $columnId, string $order): self { $order = strtolower($order); $this->defaultOrder = "$columnId|$order"; @@ -1683,60 +1291,36 @@ public function getDefaultOrder(): ?string return $this->defaultOrder; } - /** - * Sets unique filter identification. - * - * @param $id - * - * @return self - */ - public function setId($id) + public function setId(?string $id): self { $this->id = $id; return $this; } - /** - * Returns unique filter identifier. - * - * @return string - */ - public function getId() + public function getId(): ?string { return $this->id; } - /** - * Sets persistence. - * - * @param $persistence - * - * @return self - */ - public function setPersistence($persistence) + public function setPersistence(?bool $persistence): self { - $this->persistence = $persistence; + $this->persistence = (bool)$persistence; return $this; } - /** - * Returns persistence. - * - * @return bool - */ - public function getPersistence() + public function getPersistence(): ?bool { return $this->persistence; } - public function getDataJunction() + public function getDataJunction(): ?int { return $this->dataJunction; } - public function setDataJunction($dataJunction) + public function setDataJunction(?int $dataJunction): self { $this->dataJunction = $dataJunction; @@ -1750,9 +1334,8 @@ public function setDataJunction($dataJunction) * * @return self * @throws \InvalidArgumentException - * */ - public function setLimits($limits) + public function setLimits(mixed $limits): self { if (is_array($limits)) { if ((int)key($limits) === 0) { @@ -1769,62 +1352,31 @@ public function setLimits($limits) return $this; } - /** - * Returns limits. - * - * @return array - */ - public function getLimits() + public function getLimits(): array { return $this->limits; } - /** - * Returns selected Limit (Rows Per Page). - * - * @return mixed - */ - public function getLimit() + public function getLimit(): ?int { return $this->limit; } - /** - * Sets default Limit. - * - * @param $limit - * - * @return self - */ - public function setDefaultLimit($limit) + public function setDefaultLimit(?int $limit): self { - $this->defaultLimit = (int)$limit; + $this->defaultLimit = $limit; return $this; } - /** - * Sets default Page. - * - * @param $page - * - * @return self - */ - public function setDefaultPage($page) + public function setDefaultPage(?int $page): self { - $this->defaultPage = (int)$page - 1; + $this->defaultPage = $page - 1; return $this; } - /** - * Sets default Tweak. - * - * @param $tweakId - * - * @return self - */ - public function setDefaultTweak($tweakId) + public function setDefaultTweak(?string $tweakId): self { $this->defaultTweak = $tweakId; @@ -1836,19 +1388,10 @@ public function getDefaultTweak(): ?string return $this->defaultTweak; } - /** - * Sets current Page (internal). - * - * @param $page - * - * @return self - * @throws \InvalidArgumentException - * - */ - public function setPage($page) + public function setPage(int $page): self { - if ((int)$page >= 0) { - $this->page = (int)$page; + if ($page >= 0) { + $this->page = $page; } else { throw new \InvalidArgumentException(self::PAGE_NOT_VALID_EX_MSG); } @@ -1856,32 +1399,17 @@ public function setPage($page) return $this; } - /** - * Returns current page. - * - * @return int - */ - public function getPage() + public function getPage(): int { return $this->page; } - /** - * Returnd grid display data as rows - internal helper for templates. - * - * @return mixed - */ - public function getRows() + public function getRows(): array|Rows|null { return $this->rows; } - /** - * Return count of available pages. - * - * @return float - */ - public function getPageCount() + public function getPageCount(): float { $pageCount = 1; if ($this->getLimit() > 0) { @@ -1892,26 +1420,12 @@ public function getPageCount() return $pageCount; } - /** - * Returns count of filtred rows(items) from source. - * - * @return mixed - */ - public function getTotalCount() + public function getTotalCount(): ?int { return $this->totalCount; } - /** - * Sets the max results of the grid. - * - * @param int $maxResults - * - * @return self - * @throws \InvalidArgumentException - * - */ - public function setMaxResults($maxResults = null) + public function setMaxResults(?int $maxResults = null): self { if ((is_int($maxResults) && $maxResults < 0) && $maxResults !== null) { throw new \InvalidArgumentException(self::NOT_VALID_MAX_RESULT_EX_MSG); @@ -1922,17 +1436,12 @@ public function setMaxResults($maxResults = null) return $this; } - public function getMaxResults() + public function getMaxResults(): ?int { return $this->maxResults; } - /** - * Return true if the grid is filtered. - * - * @return bool - */ - public function isFiltered() + public function isFiltered(): bool { foreach ($this->columns as $column) { if ($column->isFiltered()) { @@ -1943,12 +1452,7 @@ public function isFiltered() return false; } - /** - * Return true if if title panel is visible in template - internal helper. - * - * @return bool - */ - public function isTitleSectionVisible() + public function isTitleSectionVisible(): bool { if ($this->showTitles === true) { foreach ($this->columns as $column) { @@ -1961,12 +1465,7 @@ public function isTitleSectionVisible() return false; } - /** - * Return true if filter panel is visible in template - internal helper. - * - * @return bool - */ - public function isFilterSectionVisible() + public function isFilterSectionVisible(): bool { if ($this->showFilters === true) { foreach ($this->columns as $column) { @@ -1979,12 +1478,7 @@ public function isFilterSectionVisible() return false; } - /** - * Return true if pager panel is visible in template - internal helper. - * - * @return bool return true if pager is visible - */ - public function isPagerSectionVisible() + public function isPagerSectionVisible(): bool { $limits = $this->getLimits(); @@ -1996,12 +1490,7 @@ public function isPagerSectionVisible() return min(array_keys($limits)) < $this->totalCount; } - /** - * Hides Filters Panel. - * - * @return self - */ - public function hideFilters() + public function hideFilters(): self { $this->showFilters = false; @@ -2013,12 +1502,7 @@ public function getShowFilters(): bool return $this->showFilters; } - /** - * Hides Titles panel. - * - * @return self - */ - public function hideTitles() + public function hideTitles(): self { $this->showTitles = false; @@ -2030,100 +1514,50 @@ public function getShowTitles(): bool return $this->showTitles; } - /** - * Adds Column Extension - internal helper. - * - * @param Column $extension - * - * @return self - */ - public function addColumnExtension($extension) + public function addColumnExtension(Column $extension): self { $this->columns->addExtension($extension); return $this; } - /** - * Set a prefix title. - * - * @param $prefixTitle string - * - * @return self - */ - public function setPrefixTitle($prefixTitle) + public function setPrefixTitle(string $prefixTitle): self { $this->prefixTitle = $prefixTitle; return $this; } - /** - * Get the prefix title. - * - * @return string - */ - public function getPrefixTitle() + public function getPrefixTitle(): string { return $this->prefixTitle; } - /** - * Set the no data message. - * - * @param $noDataMessage string - * - * @return self - */ - public function setNoDataMessage($noDataMessage) + public function setNoDataMessage(?string $noDataMessage): self { $this->noDataMessage = $noDataMessage; return $this; } - /** - * Get the no data message. - * - * @return string - */ - public function getNoDataMessage() + public function getNoDataMessage(): ?string { return $this->noDataMessage; } - /** - * Set the no result message. - * - * @param $noResultMessage string - * - * @return self - */ - public function setNoResultMessage($noResultMessage) + public function setNoResultMessage(string $noResultMessage): self { $this->noResultMessage = $noResultMessage; return $this; } - /** - * Get the no result message. - * - * @return string - */ - public function getNoResultMessage() + public function getNoResultMessage(): ?string { return $this->noResultMessage; } - /** - * Sets a list of columns to hide when the grid is output. - * - * @param array $columnIds - * - * @return self - */ - public function setHiddenColumns($columnIds) + public function setHiddenColumns(string|int|array $columnIds): self { $this->lazyHiddenColumns = (array)$columnIds; @@ -2135,15 +1569,7 @@ public function getHiddenColumns(): array return $this->lazyHiddenColumns; } - /** - * Sets a list of columns to show when the grid is output - * It acts as a mask; Other columns will be set as hidden. - * - * @param array $columnIds - * - * @return self - */ - public function setVisibleColumns($columnIds) + public function setVisibleColumns(string|int|array $columnIds): self { $this->lazyVisibleColumns = (array)$columnIds; @@ -2155,14 +1581,7 @@ public function getVisibleColumns(): array return $this->lazyVisibleColumns; } - /** - * Sets on the visibility of columns. - * - * @param string|array $columnIds - * - * @return self - */ - public function showColumns($columnIds) + public function showColumns(string|int|array $columnIds): self { foreach ((array)$columnIds as $columnId) { $this->lazyHideShowColumns[$columnId] = true; @@ -2171,14 +1590,7 @@ public function showColumns($columnIds) return $this; } - /** - * Sets off the visiblilty of columns. - * - * @param string|array $columnIds - * - * @return self - */ - public function hideColumns($columnIds) + public function hideColumns(string|array $columnIds): self { foreach ((array)$columnIds as $columnId) { $this->lazyHideShowColumns[$columnId] = false; @@ -2192,14 +1604,7 @@ public function getLazyHideShowColumns(): array return $this->lazyHideShowColumns; } - /** - * Sets the size of the default action column. - * - * @param int $size - * - * @return self - */ - public function setActionsColumnSize($size) + public function setActionsColumnSize(int $size): self { $this->actionsColumnSize = $size; @@ -2216,16 +1621,9 @@ public function getNewSession(): bool return $this->newSession; } - /** - * Sets the title of the default action column. - * - * @param string $title - * - * @return self - */ - public function setActionsColumnTitle($title) + public function setActionsColumnTitle(?string $title): self { - $this->actionsColumnTitle = (string)$title; + $this->actionsColumnTitle = $title; return $this; } @@ -2235,42 +1633,24 @@ public function getActionsColumnTitle(): ?string return $this->actionsColumnTitle; } - /** - * Sets whether or not mass actions should be opened in a new tab - * - * @param $massActionsInNewTab - * - * @return $this - */ - public function setMassActionsInNewTab($massActionsInNewTab) + public function setMassActionsInNewTab(bool $massActionsInNewTab): self { - $this->massActionsInNewTab = (bool)$massActionsInNewTab; + $this->massActionsInNewTab = $massActionsInNewTab; return $this; } - /** - * @return bool - */ - public function getMassActionsInNewTab() + public function getMassActionsInNewTab(): bool { return (bool)$this->massActionsInNewTab; } - /** - * Default delete action. - * - * @param array $ids - */ - public function deleteAction(array $ids) + public function deleteAction(array $ids): void { $this->source->delete($ids); } - /** - * Get a clone of the grid. - */ - public function __clone() + public function __clone(): void { // clone all objects $this->columns = clone $this->columns; @@ -2278,16 +1658,7 @@ public function __clone() /****** HELPER ******/ - /** - * Redirects or Renders a view - helper function. - * - * @param string|array $param1 The view name or an array of parameters to pass to the view - * @param string|array $param2 The view name or an array of parameters to pass to the view - * @param Response $response A response instance - * - * @return Response A Response instance - */ - public function getGridResponse($param1 = null, $param2 = null, Response $response = null) + public function getGridResponse(string|array|null $param1 = null, string|array|null $param2 = null, Response $response = null): Response|array { $isReadyForRedirect = $this->isReadyForRedirect(); @@ -2306,15 +1677,7 @@ public function getGridResponse($param1 = null, $param2 = null, Response $respon } } - /** - * @param string|array|null $param1 - * @param string|array|null $param2 - * @param \Symfony\Component\HttpFoundation\Response|null $response - * - * @return \Symfony\Component\HttpFoundation\Response|array - * @throws \Exception - */ - public function getContentResponse($param1 = null, $param2 = null, ?Response $response = null) + public function getContentResponse(string|array|null $param1 = null, string|array|null $param2 = null, ?Response $response = null): Response|array { if (is_array($param1) || $param1 === null) { $parameters = (array)$param1; @@ -2339,15 +1702,7 @@ public function getContentResponse($param1 = null, $param2 = null, ?Response $re } } - /** - * Extract raw data of columns. - * - * @param string|array $columnNames The name of the extract columns. If null, all the columns are return. - * @param bool $namedIndexes If sets to true, named indexes will be used - * - * @return array Raw data of columns - */ - public function getRawData($columnNames = null, $namedIndexes = true) + public function getRawData(string|array|null $columnNames = null, bool $namedIndexes = true): array { if ($columnNames === null) { foreach ($this->getColumns() as $column) { @@ -2373,14 +1728,7 @@ public function getRawData($columnNames = null, $namedIndexes = true) return $result; } - /** - * Returns an array of the active filters of the grid stored in session. - * - * @return Filter[] - * @throws \Exception - * - */ - public function getFilters() + public function getFilters(): array { if ($this->hash === null) { throw new \Exception(self::GET_FILTERS_NO_REQUEST_HANDLED_EX_MSG); @@ -2425,17 +1773,7 @@ public function getFilters() return $this->sessionFilters; } - /** - * Returns the filter of a column stored in session. - * - * @param string $columnId - * Id of the column - * - * @return Filter - * @throws \Exception - * - */ - public function getFilter($columnId) + public function getFilter(string $columnId): ?Filter { if ($this->hash === null) { throw new \Exception(self::GET_FILTERS_NO_REQUEST_HANDLED_EX_MSG); @@ -2446,17 +1784,7 @@ public function getFilter($columnId) return isset($sessionFilters[$columnId]) ? $sessionFilters[$columnId] : null; } - /** - * A filter of the column is stored in session ? - * - * @param string $columnId - * Id of the column - * - * @return bool - * @throws \Exception - * - */ - public function hasFilter($columnId) + public function hasFilter(string $columnId): bool { if ($this->hash === null) { throw new \Exception(self::HAS_FILTER_NO_REQUEST_HANDLED_EX_MSG); diff --git a/src/Grid/GridBuilder.php b/src/Grid/GridBuilder.php index 34f9e87..3912f89 100644 --- a/src/Grid/GridBuilder.php +++ b/src/Grid/GridBuilder.php @@ -7,7 +7,6 @@ use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use Doctrine\Persistence\ManagerRegistry; -use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelInterface; @@ -76,7 +75,7 @@ public function __construct( /** * {@inheritdoc} */ - public function add(string $name, string|Column $type, array $options = []): self + public function add(string $name, string|array|Column $type, array $options = []): self { if (!$type instanceof Column) { if (!is_string($type)) { diff --git a/src/Grid/GridConfigBuilder.php b/src/Grid/GridConfigBuilder.php index bea4e14..640888b 100644 --- a/src/Grid/GridConfigBuilder.php +++ b/src/Grid/GridConfigBuilder.php @@ -12,39 +12,39 @@ */ class GridConfigBuilder implements GridConfigBuilderInterface { - private string $name; + protected string $name; - private GridTypeInterface $type; + protected GridTypeInterface $type; - private Source $source; + protected ?Source $source = null; - private string $route; + protected ?string $route = null; - private array $routeParameters = []; + protected array $routeParameters = []; - private bool $persistence; + protected ?bool $persistence = null; - private int $page = 0; + protected int $page = 0; - private int $limit; + protected ?int $limit = null; - private int $maxResults; + protected ?int $maxResults = null; - private bool $filterable = true; + protected bool $filterable = true; - private bool $sortable = true; + protected bool $sortable = true; - private string $sortBy; + protected ?string $sortBy = null; - private string $order = 'asc'; + protected string $order = 'asc'; - private string|array $groupBy; + protected string|array|null $groupBy = null; - private bool $massActionsInNewTab; + protected bool $massActionsInNewTab = false; - private array $actions; + protected array $actions; - private array $options; + protected array $options; public function __construct(string $name, array $options = []) { @@ -63,12 +63,12 @@ public function getName(): string /** * {@inheritdoc} */ - public function getSource(): Source + public function getSource(): ?Source { return $this->source; } - public function setSource(Source $source): self + public function setSource(?Source $source): self { $this->source = $source; @@ -93,7 +93,7 @@ public function setType(GridTypeInterface $type): self /** * {@inheritdoc} */ - public function getRoute(): string + public function getRoute(): ?string { return $this->route; } @@ -123,12 +123,12 @@ public function setRouteParameters(array $routeParameters): self /** * {@inheritdoc} */ - public function isPersisted(): bool + public function isPersisted(): ?bool { return $this->persistence; } - public function setPersistence(bool $persistence): self + public function setPersistence(?bool $persistence): self { $this->persistence = $persistence; @@ -177,24 +177,24 @@ public function getOption(string $name, mixed $default = null): mixed /** * {@inheritdoc} */ - public function getMaxPerPage(): int + public function getMaxPerPage(): ?int { return $this->limit; } - public function setMaxPerPage(int $limit): self + public function setMaxPerPage(?int $limit): self { $this->limit = $limit; return $this; } - public function getMaxResults(): int + public function getMaxResults(): ?int { return $this->maxResults; } - public function setMaxResults(int $maxResults): self + public function setMaxResults(?int $maxResults): self { $this->maxResults = $maxResults; @@ -231,12 +231,12 @@ public function setFilterable(bool $filterable): self /** * {@inheritdoc} */ - public function getOrder(): int + public function getOrder(): string { return $this->order; } - public function setOrder(int $order): self + public function setOrder(string $order): self { $this->order = $order; @@ -246,12 +246,12 @@ public function setOrder(int $order): self /** * {@inheritdoc} */ - public function getSortBy(): string + public function getSortBy(): ?string { return $this->sortBy; } - public function setSortBy(string $sortBy): self + public function setSortBy(?string $sortBy): self { $this->sortBy = $sortBy; @@ -261,12 +261,12 @@ public function setSortBy(string $sortBy): self /** * {@inheritdoc} */ - public function getGroupBy(): array|string + public function getGroupBy(): array|string|null { return $this->groupBy; } - public function setGroupBy(array|string $groupBy): self + public function setGroupBy(array|string|null $groupBy): self { $this->groupBy = $groupBy; diff --git a/src/Grid/GridConfigInterface.php b/src/Grid/GridConfigInterface.php index b95265e..164cc19 100644 --- a/src/Grid/GridConfigInterface.php +++ b/src/Grid/GridConfigInterface.php @@ -23,7 +23,7 @@ public function getName(): string; * * @return Source The source of the grid. */ - public function getSource(): Source; + public function getSource(): ?Source; /** * Returns the grid type used to construct the grid. @@ -37,7 +37,7 @@ public function getType(): GridTypeInterface; * * @return string The route of the grid. */ - public function getRoute(): string; + public function getRoute(): ?string; /** * Returns the route parameters of the grid. @@ -51,7 +51,7 @@ public function getRouteParameters(): array; * * @return bool Whether the grid is persisted. */ - public function isPersisted(): bool; + public function isPersisted(): ?bool; /** * Returns the default page. @@ -105,14 +105,14 @@ public function isSortable(): bool; * * @return int The maximum number of results of the grid. */ - public function getMaxResults(): int; + public function getMaxResults(): ?int; /** * Returns the maximum number of items per page. * * @return int The maximum number of items per page. */ - public function getMaxPerPage(): int; + public function getMaxPerPage(): ?int; /** * Returns the default order. @@ -126,14 +126,14 @@ public function getOrder(): string; * * @return string The default sort field. */ - public function getSortBy(): string; + public function getSortBy(): ?string; /** * Returns the default group field. * * @return string|array */ - public function getGroupBy(): string|array; + public function getGroupBy(): string|array|null; /** * Returns whether or not mass actions should be opened in a new tab. diff --git a/src/Grid/GridFactory.php b/src/Grid/GridFactory.php index 160816c..be4b7a5 100644 --- a/src/Grid/GridFactory.php +++ b/src/Grid/GridFactory.php @@ -70,7 +70,7 @@ public function __construct( /** * {@inheritdoc} */ - public function create(string|GridTypeInterface|null $type = null, ?Source $source = null, array $options = []): Grid + public function create(string|array|GridTypeInterface|null $type = null, ?Source $source = null, array $options = []): Grid { return $this->createBuilder($type, $source, $options)->getGrid(); } @@ -78,7 +78,7 @@ public function create(string|GridTypeInterface|null $type = null, ?Source $sour /** * {@inheritdoc} */ - public function createBuilder(string|GridTypeInterface|null $type = 'grid', ?Source $source = null, array $options = []): GridBuilder + public function createBuilder(string|GridTypeInterface|array|null $type = 'grid', ?Source $source = null, array $options = []): GridBuilder { $type = $this->resolveType($type); $options = $this->resolveOptions($type, $source, $options); @@ -108,7 +108,7 @@ public function createBuilder(string|GridTypeInterface|null $type = 'grid', ?Sou /** * {@inheritdoc} */ - public function createColumn(string $name, string|Column $type, array $options = []): Column + public function createColumn(string $name, string|int|Column $type, array $options = []): Column { if (!$type instanceof Column) { if (!is_string($type)) { @@ -136,7 +136,7 @@ public function createColumn(string $name, string|Column $type, array $options = return $column; } - private function resolveType(string|GridTypeInterface $type): GridTypeInterface + private function resolveType(string|array|GridTypeInterface $type): GridTypeInterface { if (!$type instanceof GridTypeInterface) { if (!is_string($type)) { diff --git a/src/Grid/GridFactoryInterface.php b/src/Grid/GridFactoryInterface.php index d0e3ae1..12162b0 100644 --- a/src/Grid/GridFactoryInterface.php +++ b/src/Grid/GridFactoryInterface.php @@ -32,7 +32,7 @@ public function create(string|GridTypeInterface|null $type = null, ?Source $sour * * @return GridBuilder */ - public function createBuilder(string|GridTypeInterface|null $type = null, ?Source $source = null, array $options = []): GridBuilder; + public function createBuilder(string|array|GridTypeInterface|null $type = null, ?Source $source = null, array $options = []): GridBuilder; /** * Returns a column. diff --git a/src/Grid/GridManager.php b/src/Grid/GridManager.php index 034f7d9..35453ff 100644 --- a/src/Grid/GridManager.php +++ b/src/Grid/GridManager.php @@ -61,7 +61,7 @@ public function createGrid(int|string $id = null): Grid return $grid; } - public function isReadyForRedirect(): bool + public function isReadyForRedirect(): ?bool { if ($this->grids->count() == 0) { throw new \RuntimeException(self::NO_GRID_EX_MSG); @@ -97,7 +97,7 @@ public function isReadyForRedirect(): bool return $isReadyForRedirect; } - public function isReadyForExport(): bool + public function isReadyForExport(): ?bool { if ($this->grids->count() == 0) { throw new \RuntimeException(self::NO_GRID_EX_MSG); @@ -190,7 +190,7 @@ public function getGridManagerResponse(string|array|null $param1 = null, string| } } - public function getRouteUrl(): string + public function getRouteUrl(): ?string { return $this->routeUrl; } diff --git a/src/Grid/Row.php b/src/Grid/Row.php index de9bef8..f824b5f 100644 --- a/src/Grid/Row.php +++ b/src/Grid/Row.php @@ -24,7 +24,7 @@ class Row private ?string $legend; - private string $primaryField; + private string|array|null $primaryField = null; private ?EntityRepository $repository; @@ -82,17 +82,14 @@ public function getPrimaryFieldValue(): mixed return $this->fields[$this->primaryField]; } - public function setPrimaryField(string $primaryField): self + public function setPrimaryField(string|array|null $primaryField): self { $this->primaryField = $primaryField; return $this; } - /** - * @return mixed - */ - public function getPrimaryField(): string + public function getPrimaryField(): string|array|null { return $this->primaryField; } diff --git a/src/Grid/Source/Entity.php b/src/Grid/Source/Entity.php index 389041a..05dcafc 100644 --- a/src/Grid/Source/Entity.php +++ b/src/Grid/Source/Entity.php @@ -308,9 +308,9 @@ protected function getQueryBuilder(): QueryBuilder } public function execute( - ColumnsIterator $columns, - int $page = 0, - int $limit = 0, + ColumnsIterator|Columns|array $columns, + ?int $page = 0, + ?int $limit = 0, ?int $maxResults = null, int $gridDataJunction = Column::DATA_CONJUNCTION ): Rows { @@ -504,7 +504,7 @@ private function fromAliasToColId(string $alias): string return str_replace([self::DOT_DQL_ALIAS_PH, self::COLON_DQL_ALIAS_PH], ['.', ':'], $alias); } - public function getTotalCount(?int $maxResults = null): int + public function getTotalCount(?int $maxResults = null): ?int { // Doctrine Bug Workaround: http://www.doctrine-project.org/jira/browse/DDC-1927 $countQueryBuilder = clone $this->query; @@ -611,7 +611,7 @@ public function getFieldsMetadata(string $class, string $group = 'default'): arr return $result; } - public function populateSelectFilters(array $columns, bool $loop = false): void + public function populateSelectFilters(Columns|array $columns, bool $loop = false): void { /* @var $column Column */ foreach ($columns as $column) { @@ -733,7 +733,7 @@ public function getRepository(): EntityRepository|ObjectRepository return $this->manager->getRepository($this->entityName); } - public function getHash(): string + public function getHash(): ?string { return $this->entityName; } diff --git a/src/Grid/Source/Source.php b/src/Grid/Source/Source.php index 6015506..9b7b862 100644 --- a/src/Grid/Source/Source.php +++ b/src/Grid/Source/Source.php @@ -71,9 +71,9 @@ public function manipulateRow(?\Closure $callback = null): self return $this; } - abstract public function execute(ColumnsIterator $columns, int $page = 0, int $limit = 0, ?int $maxResults = null, int $gridDataJunction = Column::DATA_CONJUNCTION): Rows; + abstract public function execute(ColumnsIterator|Columns|array $columns, ?int $page = 0, ?int $limit = 0, ?int $maxResults = null, int $gridDataJunction = Column::DATA_CONJUNCTION): Rows|array; - abstract public function getTotalCount(?int $maxResults = null): int; + abstract public function getTotalCount(?int $maxResults = null): ?int; abstract public function initialise(ManagerRegistry $doctrine, Manager $mapping): void; @@ -94,9 +94,9 @@ public function getGroupBy(string $class, string $group = 'default'): array return []; } - abstract public function populateSelectFilters(array $columns, bool $loop = false): void; + abstract public function populateSelectFilters(Columns|array $columns, bool $loop = false): void; - abstract public function getHash(): string; + abstract public function getHash(): ?string; abstract public function delete(array $ids): void; @@ -164,7 +164,7 @@ protected function getItemsFromData(Columns $columns): array return $items; } - public function executeFromData(Columns $columns, int $page = 0, int $limit = 0, ?int $maxResults = null): Rows + public function executeFromData(Columns|ColumnsIterator|array $columns, ?int $page = 0, ?int $limit = 0, ?int $maxResults = null): Rows|array { // Populate from data $items = $this->getItemsFromData($columns); @@ -456,12 +456,12 @@ public function populateSelectFiltersFromData(Columns $columns, bool $loop = fal } } - public function getTotalCountFromData(?int $maxResults = null): int + public function getTotalCountFromData(?int $maxResults = null): ?int { return $maxResults === null ? $this->count : min($this->count, $maxResults); } - protected function prepareStringForLikeCompare(string $input, ?string $type = null) + protected function prepareStringForLikeCompare(string $input, ?string $type = null): string { if ($type === 'array') { $outputString = str_replace(':{i:0;', ':{', serialize($input)); diff --git a/src/Grid/Source/Vector.php b/src/Grid/Source/Vector.php index 471090b..4eb1818 100644 --- a/src/Grid/Source/Vector.php +++ b/src/Grid/Source/Vector.php @@ -20,6 +20,8 @@ use APY\DataGridBundle\Grid\Column\NumberColumn; use APY\DataGridBundle\Grid\Column\TextColumn; use APY\DataGridBundle\Grid\Column\UntypedColumn; +use APY\DataGridBundle\Grid\Columns; +use APY\DataGridBundle\Grid\Helper\ColumnsIterator; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Rows; use Doctrine\Persistence\ManagerRegistry; @@ -31,32 +33,12 @@ */ class Vector extends Source { - /** - * @var array - */ - protected $data = []; - - /** - * either a column name as a string - * or an array of names of columns. - * - * @var mixed - */ - protected $id = null; - - /** - * Array of columns. - * - * @var Column[] - */ - protected $columns; - - /** - * Creates the Vector and sets its data. - * - * @param array $data - * @param array $columns - */ + protected array $data = []; + + protected string|array|null $id = null; + + protected array|Columns|ColumnsIterator $columns; + public function __construct(array $data, array $columns = []) { if (!empty($data)) { @@ -66,14 +48,14 @@ public function __construct(array $data, array $columns = []) $this->setColumns($columns); } - public function initialise(ManagerRegistry $doctrine, Manager $mapping) + public function initialise(ManagerRegistry $doctrine, Manager $mapping): void { if (!empty($this->data)) { $this->guessColumns(); } } - protected function guessColumns() + protected function guessColumns(): void { $guessedColumns = []; $dataColumnIds = array_keys(reset($this->data)); @@ -155,10 +137,7 @@ protected function guessColumns() } } - /** - * @param \APY\DataGridBundle\Grid\Columns $columns - */ - public function getColumns($columns) + public function getColumns(Columns $columns): void { $token = empty($this->id); //makes the first column primary by default @@ -199,31 +178,22 @@ public function getColumns($columns) } } - /** - * @param \APY\DataGridBundle\Grid\Column\Column[] $columns - * @param int $page Page Number - * @param int $limit Rows Per Page - * @param int $maxResults Max rows - * @param int $gridDataJunction Grid data junction - * - * @return Rows - */ - public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION) + public function execute(ColumnsIterator|Columns|array $columns, ?int $page = 0, ?int $limit = 0, ?int $maxResults = null, int $gridDataJunction = Column::DATA_CONJUNCTION): Rows|array { return $this->executeFromData($columns, $page, $limit, $maxResults); } - public function populateSelectFilters($columns, $loop = false) + public function populateSelectFilters(Columns|array $columns, bool $loop = false): void { $this->populateSelectFiltersFromData($columns, $loop); } - public function getTotalCount(?int $maxResults = null): int + public function getTotalCount(?int $maxResults = null): ?int { return $this->getTotalCountFromData($maxResults); } - public function getHash() + public function getHash(): ?string { return __CLASS__ . md5( implode( @@ -235,32 +205,17 @@ public function getHash() ); } - /** - * sets the primary key. - * - * @param mixed $id either a string or an array of strings - */ - public function setId($id) + public function setId(string|array $id) { $this->id = $id; } - /** - * @return mixed - */ - public function getId() + public function getId(): string|array|null { return $this->id; } - /** - * Set a two-dimentional array. - * - * @param array $data - * - * @throws \InvalidArgumentException - */ - public function setData($data) + public function setData(array|object $data): self { $this->data = $data; @@ -280,18 +235,22 @@ public function setData($data) if (!is_array($firstRaw) || empty($firstRaw)) { throw new \InvalidArgumentException('Data should be a two-dimentional array'); } + + return $this; } public function delete(array $ids): void { } - protected function setColumns($columns) + protected function setColumns(Columns|array|ColumnsIterator $columns): self { $this->columns = $columns; + + return $this; } - protected function hasColumn($id) + protected function hasColumn(string $id): bool { foreach ($this->columns as $c) { if ($id === $c->getId()) { diff --git a/src/Twig/DataGridExtension.php b/src/Twig/DataGridExtension.php index 20d5178..452c658 100644 --- a/src/Twig/DataGridExtension.php +++ b/src/Twig/DataGridExtension.php @@ -214,9 +214,9 @@ public function getGridColumnOperator(Environment $environment, Column $column, * @param \APY\DataGridBundle\Grid\Grid $grid * @param \APY\DataGridBundle\Grid\Column\Column $param * - * @return string + * @return string|void */ - public function getGridUrl($section, Grid $grid, ?Column $param = null): string + public function getGridUrl($section, Grid $grid, Column|string|int|null $param = null) { $prefix = $grid->getRouteUrl() . (strpos($grid->getRouteUrl(), '?') ? '&' : '?') . $grid->getHash() . '['; diff --git a/tests/Grid/Column/BooleanColumnTest.php b/tests/Grid/Column/BooleanColumnTest.php index 882c5cb..5b0e681 100644 --- a/tests/Grid/Column/BooleanColumnTest.php +++ b/tests/Grid/Column/BooleanColumnTest.php @@ -125,11 +125,11 @@ public function testRenderCellWithCallback() { $this->column->manipulateRenderCell( function ($value, $row, $router) { - return 'true'; + return true; } ); - $this->assertEquals( - 'true', + + $this->assertTrue( $this->column->renderCell( 0, $this->createMock(Row::class), @@ -139,11 +139,11 @@ function ($value, $row, $router) { $this->column->manipulateRenderCell( function ($value, $row, $router) { - return 'false'; + return false; } ); - $this->assertEquals( - 'false', + + $this->assertFalse( $this->column->renderCell( 1, $this->createMock(Row::class), @@ -156,8 +156,8 @@ function ($value, $row, $router) { return; } ); - $this->assertEquals( - 'false', + + $this->assertFalse( $this->column->renderCell( 1, $this->createMock(Row::class), diff --git a/tests/Grid/ColumnsTest.php b/tests/Grid/ColumnsTest.php index ffc7711..a98d751 100644 --- a/tests/Grid/ColumnsTest.php +++ b/tests/Grid/ColumnsTest.php @@ -38,16 +38,15 @@ public function testAddColumn() public function testAddColumnsOrder() { - [$column1, $column2, $column3, $column4, $column5] = $this->buildColumnMocks(5); + [$column1, $column2, $column3, $column4] = $this->buildColumnMocks(4); $this->columns ->addColumn($column1) ->addColumn($column2, 1) ->addColumn($column3, 2) - ->addColumn($column4, -1) - ->addColumn($column5, 'foo'); + ->addColumn($column4, -1); - $this->assertSame([$column2, $column3, $column4, $column1, $column5], iterator_to_array($this->columns->getIterator())); + $this->assertSame([$column2, $column3, $column4, $column1], iterator_to_array($this->columns->getIterator())); } public function testRaiseExceptionIfGetColumnByIdDoesNotExists() diff --git a/tests/Grid/GridTest.php b/tests/Grid/GridTest.php index 6c535e0..e1ab3da 100644 --- a/tests/Grid/GridTest.php +++ b/tests/Grid/GridTest.php @@ -1098,15 +1098,6 @@ public function testSetMaxResultWithInvalidValueRaiseException() $this->grid->setMaxResults(-1); } - // @todo: has this case sense? Should not raise exception? - public function testSetMaxResultWithStringValue() - { - $maxResult = 'foo'; - $this->grid->setMaxResults($maxResult); - - $this->assertSame($maxResult, $this->grid->getMaxResults()); - } - public function testSetMaxResult() { $maxResult = 1; @@ -1302,7 +1293,7 @@ public function testGetNoResultMessage() public function testSetHiddenColumnsWithIntegerId() { $id = 1; - $this->grid->setHiddenColumns($id); + $this->grid->setHiddenColumns([$id]); $this->assertSame([$id], $this->grid->getHiddenColumns()); } From db9db3197af974563e34f4128b87c05b46151aad Mon Sep 17 00:00:00 2001 From: Nate Wiebe Date: Wed, 15 Feb 2023 13:46:56 -0500 Subject: [PATCH 20/38] Allow boolean in request data --- src/Grid/Grid.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index f1bade1..de321c8 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -506,7 +506,7 @@ protected function processRequestData(): void $this->saveSession(); } - protected function processMassActions(int|string|null $actionId): void + protected function processMassActions(int|string|bool|null $actionId): void { if ($actionId > -1 && '' !== $actionId) { if (array_key_exists($actionId, $this->massActions)) { @@ -552,7 +552,7 @@ protected function processMassActions(int|string|null $actionId): void } } - protected function processExports(?int $exportId): bool + protected function processExports(int|string|bool|null $exportId): bool { if ($exportId > -1 && '' !== $exportId) { if (array_key_exists($exportId, $this->exports)) { @@ -585,7 +585,7 @@ protected function processExports(?int $exportId): bool return false; } - protected function processTweaks(int|string|null $tweakId): bool + protected function processTweaks(int|string|bool|null $tweakId): bool { if ($tweakId !== null) { if (array_key_exists($tweakId, $this->tweaks)) { From bedd5417d513443cfa507a1f44dd148b7c9080ad Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 23 Feb 2023 11:01:24 -0500 Subject: [PATCH 21/38] Add types to tests --- tests/Grid/Action/DeleteMassActionTest.php | 4 +- tests/Grid/Action/MassActionTest.php | 34 +- tests/Grid/Action/RowActionTest.php | 73 +- tests/Grid/Column/ActionsColumnTest.php | 29 +- tests/Grid/Column/ArrayColumnTest.php | 25 +- tests/Grid/Column/BlankColumnTest.php | 4 +- tests/Grid/Column/BooleanColumnTest.php | 21 +- tests/Grid/Column/ColumnTest.php | 198 ++-- tests/Grid/Column/DateColumnTest.php | 23 +- tests/Grid/Column/DateTimeColumnTest.php | 38 +- tests/Grid/Column/JoinColumnTest.php | 20 +- tests/Grid/Column/MassActionColumnTest.php | 13 +- tests/Grid/Column/NumberColumnTest.php | 47 +- tests/Grid/Column/RankColumnTest.php | 19 +- tests/Grid/Column/SimpleArrayColumnTest.php | 25 +- tests/Grid/Column/TextColumnTest.php | 15 +- tests/Grid/Column/TimeColumnTest.php | 2 +- tests/Grid/Column/UntypedColumnTest.php | 4 +- tests/Grid/ColumnsTest.php | 46 +- tests/Grid/FilterTest.php | 10 +- tests/Grid/GridBuilderTest.php | 33 +- tests/Grid/GridConfigBuilderTest.php | 45 +- tests/Grid/GridFactoryTest.php | 32 +- tests/Grid/GridManagerTest.php | 117 +-- tests/Grid/GridRegistryTest.php | 30 +- tests/Grid/GridTest.php | 859 ++++++++---------- tests/Grid/Helper/ColumnsIteratorTest.php | 23 +- tests/Grid/Mapping/ColumnTest.php | 6 +- .../Grid/Mapping/Metadata/DriverHeapTest.php | 6 +- tests/Grid/Mapping/Metadata/ManagerTest.php | 10 +- tests/Grid/Mapping/Metadata/MetadataTest.php | 16 +- tests/Grid/Mapping/SourceTest.php | 22 +- tests/Grid/RowTest.php | 33 +- tests/Grid/RowsTest.php | 14 +- tests/Grid/Source/VectorTest.php | 33 +- tests/Test.php | 2 +- tests/Twig/DataGridExtensionTest.php | 7 +- 37 files changed, 852 insertions(+), 1086 deletions(-) diff --git a/tests/Grid/Action/DeleteMassActionTest.php b/tests/Grid/Action/DeleteMassActionTest.php index 114d8a9..480e0b1 100644 --- a/tests/Grid/Action/DeleteMassActionTest.php +++ b/tests/Grid/Action/DeleteMassActionTest.php @@ -7,13 +7,13 @@ class DeleteMassActionTest extends TestCase { - public function testConstructWithConfirmation() + public function testConstructWithConfirmation(): void { $ma = new DeleteMassAction(true); $this->assertSame(true, $ma->getConfirm()); } - public function testConstructWithoutConfirmation() + public function testConstructWithoutConfirmation(): void { $ma = new DeleteMassAction(); $this->assertSame(false, $ma->getConfirm()); diff --git a/tests/Grid/Action/MassActionTest.php b/tests/Grid/Action/MassActionTest.php index 18c5765..46d4ce9 100644 --- a/tests/Grid/Action/MassActionTest.php +++ b/tests/Grid/Action/MassActionTest.php @@ -7,30 +7,24 @@ class MassActionTest extends TestCase { - /** @var MassAction */ - private $massAction; + private MassAction $massAction; - /** @var string */ - private $title = 'foo'; + private string $title = 'foo'; - /** @var string */ - private $callback = 'static::massAction'; + private string $callback = 'static::massAction'; - /** @var bool */ - private $confirm = true; + private bool $confirm = true; - /** @var array */ - private $parameters = ['foo' => 'foo', 'bar' => 'bar']; + private array $parameters = ['foo' => 'foo', 'bar' => 'bar']; - /** @var string */ - private $role = 'ROLE_FOO'; + private string $role = 'ROLE_FOO'; public function setUp(): void { $this->massAction = new MassAction($this->title, $this->callback, $this->confirm, $this->parameters, $this->role); } - public function testMassActionConstruct() + public function testMassActionConstruct(): void { $this->assertSame($this->title, $this->massAction->getTitle()); $this->assertSame($this->callback, $this->massAction->getCallback()); @@ -39,7 +33,7 @@ public function testMassActionConstruct() $this->assertSame($this->role, $this->massAction->getRole()); } - public function testGetTitle() + public function testGetTitle(): void { $title = 'foobar'; $this->massAction->setTitle($title); @@ -47,7 +41,7 @@ public function testGetTitle() $this->assertEquals($title, $this->massAction->getTitle()); } - public function testGetCallback() + public function testGetCallback(): void { $callback = 'self::barMassAction'; $this->massAction->setCallback($callback); @@ -55,7 +49,7 @@ public function testGetCallback() $this->assertEquals($callback, $this->massAction->getCallback()); } - public function testGetConfirm() + public function testGetConfirm(): void { $confirm = false; $this->massAction->setConfirm($confirm); @@ -63,12 +57,12 @@ public function testGetConfirm() $this->assertFalse($this->massAction->getConfirm()); } - public function testDefaultConfirmMessage() + public function testDefaultConfirmMessage(): void { $this->assertIsString($this->massAction->getConfirmMessage()); } - public function testGetConfirmMessage() + public function testGetConfirmMessage(): void { $message = 'A bar test message'; $this->massAction->setConfirmMessage($message); @@ -76,7 +70,7 @@ public function testGetConfirmMessage() $this->assertEquals($message, $this->massAction->getConfirmMessage()); } - public function testGetParameters() + public function testGetParameters(): void { $params = [1, 2, 3]; $this->massAction->setParameters($params); @@ -84,7 +78,7 @@ public function testGetParameters() $this->assertEquals($params, $this->massAction->getParameters()); } - public function testGetRole() + public function testGetRole(): void { $role = 'ROLE_SUPER_ADMIN'; $this->massAction->setRole($role); diff --git a/tests/Grid/Action/RowActionTest.php b/tests/Grid/Action/RowActionTest.php index 2d6cc8e..e8e76c2 100644 --- a/tests/Grid/Action/RowActionTest.php +++ b/tests/Grid/Action/RowActionTest.php @@ -4,36 +4,28 @@ use APY\DataGridBundle\Grid\Action\RowAction; use APY\DataGridBundle\Grid\Row; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class RowActionTest extends TestCase { - /** @var string */ - private $title = 'title'; + private string $title = 'title'; - /** @var string */ - private $route = 'vendor.bundle.controller.route_name'; + private string $route = 'vendor.bundle.controller.route_name'; - /** @var bool */ - private $confirm = true; + private bool $confirm = true; - /** @var string */ - private $target = '_parent'; + private string $target = '_parent'; - /** @var array */ - private $attributes = ['foo' => 'foo', 'bar' => 'bar']; + private array $attributes = ['foo' => 'foo', 'bar' => 'bar']; - /** @var string */ - private $role = 'ROLE_FOO'; + private string $role = 'ROLE_FOO'; - /** @var array */ - private $callbacks = []; + private array $callbacks = []; - /** @var RowAction */ - private $rowAction; + private RowAction $rowAction; - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $row; + private MockObject $row; protected function setUp(): void { @@ -43,7 +35,7 @@ protected function setUp(): void $this->row = $this->createMock(Row::class); } - public function testGetTitle() + public function testGetTitle(): void { $title = 'foo_title'; $this->rowAction->setTitle($title); @@ -51,7 +43,7 @@ public function testGetTitle() $this->assertEquals($title, $this->rowAction->getTitle()); } - public function testGetRoute() + public function testGetRoute(): void { $route = 'another_vendor.another_bundle.controller.route_name'; $this->rowAction->setRoute($route); @@ -59,7 +51,7 @@ public function testGetRoute() $this->assertEquals($route, $this->rowAction->getRoute()); } - public function testGetConfirmation() + public function testGetConfirmation(): void { $confirm = true; $this->rowAction->setConfirm($confirm); @@ -67,12 +59,12 @@ public function testGetConfirmation() $this->assertTrue($this->rowAction->getConfirm()); } - public function testDefaultConfirmMessage() + public function testDefaultConfirmMessage(): void { $this->assertIsString($this->rowAction->getConfirmMessage()); } - public function testGetConfirmMessage() + public function testGetConfirmMessage(): void { $message = 'A bar test message'; $this->rowAction->setConfirmMessage($message); @@ -80,7 +72,7 @@ public function testGetConfirmMessage() $this->assertEquals($message, $this->rowAction->getConfirmMessage()); } - public function testGetTarget() + public function testGetTarget(): void { $target = '_blank'; $this->rowAction->setTarget($target); @@ -88,7 +80,7 @@ public function testGetTarget() $this->assertEquals($target, $this->rowAction->getTarget()); } - public function testGetColumn() + public function testGetColumn(): void { $col = 'bar'; $this->rowAction->setColumn($col); @@ -96,7 +88,7 @@ public function testGetColumn() $this->assertEquals($col, $this->rowAction->getColumn()); } - public function testAddRouteParameters() + public function testAddRouteParameters(): void { $stringParam = 'aParam'; $this->rowAction->addRouteParameters($stringParam); @@ -116,16 +108,15 @@ public function testAddRouteParameters() ); } - public function testSetStringRouteParameters() + public function testSetStringRouteParameters(): void { $param = 'param'; $this->rowAction->setRouteParameters($param); - $this->assertSame([0 => $param], $this->rowAction->getRouteParameters()); } - public function testGetRouteParameters() + public function testGetRouteParameters(): void { $params = ['foo' => 'foo_param', 'bar' => 'bar_param']; $this->rowAction->setRouteParameters($params); @@ -133,7 +124,7 @@ public function testGetRouteParameters() $this->assertEquals($params, $this->rowAction->getRouteParameters()); } - public function testGetRouteParametersMapping() + public function testGetRouteParametersMapping(): void { $routeParamKey = 'foo.bar.city'; $routeParamValue = 'cityId'; @@ -144,7 +135,7 @@ public function testGetRouteParametersMapping() $this->assertNull($this->rowAction->getRouteParametersMapping('foo.bar.country')); } - public function testSetAttributes() + public function testSetAttributes(): void { $attr = ['foo' => 'foo_val', 'bar' => 'bar_val']; $this->rowAction->setAttributes($attr); @@ -152,7 +143,7 @@ public function testSetAttributes() $this->assertSame($attr, $this->rowAction->getAttributes()); } - public function testAddAttribute() + public function testAddAttribute(): void { $attrName = 'foo1'; $attrVal = 'foo_val1'; @@ -164,12 +155,12 @@ public function testAddAttribute() ); } - public function testGetAttributes() + public function testGetAttributes(): void { $this->assertEquals($this->attributes, $this->rowAction->getAttributes()); } - public function testGetRole() + public function testGetRole(): void { $role = 'ROLE_SUPER_ADMIN'; $this->rowAction->setRole($role); @@ -177,7 +168,7 @@ public function testGetRole() $this->assertEquals($role, $this->rowAction->getRole()); } - public function testManipulateRender() + public function testManipulateRender(): void { $callback1 = function () { return 1; @@ -192,13 +183,13 @@ public function testManipulateRender() $this->assertSame([$callback1, $callback2], $this->rowAction->getCallbacks()); } - public function testAddManipulateRender() + public function testAddManipulateRender(): void { $this->addCalbacks(); $this->assertSame($this->callbacks, $this->rowAction->getCallbacks()); } - private function addCalbacks() + private function addCalbacks(): void { $callback1 = function ($action, $row) { /** @var $row Row */ @@ -225,7 +216,7 @@ private function addCalbacks() $this->callbacks = [$callback1, $callback2]; } - public function testExecuteAllCallbacks() + public function testExecuteAllCallbacks(): void { $this->addCalbacks(); @@ -238,7 +229,7 @@ public function testExecuteAllCallbacks() $this->assertEquals($this->rowAction, $this->rowAction->render($this->row)); } - public function testStopOnFirstCallbackFailed() + public function testStopOnFirstCallbackFailed(): void { $this->addCalbacks(); @@ -251,7 +242,7 @@ public function testStopOnFirstCallbackFailed() $this->assertEquals(null, $this->rowAction->render($this->row)); } - public function testSetEnabled() + public function testSetEnabled(): void { $enabled = true; $this->rowAction->setEnabled($enabled); @@ -259,7 +250,7 @@ public function testSetEnabled() $this->assertSame($enabled, $this->rowAction->getEnabled()); } - public function testGetEnabled() + public function testGetEnabled(): void { $enabled = true; $this->rowAction->setEnabled($enabled); diff --git a/tests/Grid/Column/ActionsColumnTest.php b/tests/Grid/Column/ActionsColumnTest.php index 88155a1..a11f5eb 100644 --- a/tests/Grid/Column/ActionsColumnTest.php +++ b/tests/Grid/Column/ActionsColumnTest.php @@ -11,8 +11,7 @@ class ActionsColumnTest extends TestCase { - /** @var ActionsColumn */ - private $column; + private ActionsColumn $column; public function setUp(): void { @@ -24,7 +23,7 @@ public function setUp(): void ]); } - public function testConstructor() + public function testConstructor(): void { $columnId = 'columnId'; $columnTitle = 'columnTitle'; @@ -41,17 +40,17 @@ public function testConstructor() $this->assertTrue($column->isFilterable()); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('actions', $this->column->getType()); } - public function testGetFilterType() + public function testGetFilterType(): void { $this->assertEquals('actions', $this->column->getFilterType()); } - public function testGetActionsToRender() + public function testGetActionsToRender(): void { $row = $this->createMock(Row::class); @@ -68,7 +67,7 @@ public function testGetActionsToRender() $this->assertEquals([1 => $rowAction2], $column->getActionsToRender($row)); } - public function testGetRowActions() + public function testGetRowActions(): void { $rowAction1 = $this->createMock(RowAction::class); $rowAction2 = $this->createMock(RowAction::class); @@ -80,7 +79,7 @@ public function testGetRowActions() $this->assertEquals([$rowAction1, $rowAction2], $column->getRowActions()); } - public function testSetRowActions() + public function testSetRowActions(): void { $rowAction1 = $this->createMock(RowAction::class); $rowAction2 = $this->createMock(RowAction::class); @@ -90,24 +89,24 @@ public function testSetRowActions() $this->assertSame([$rowAction1, $rowAction2], $column->getRowActions()); } - public function testIsNotVisibleIfExported() + public function testIsNotVisibleIfExported(): void { $isExported = true; $this->assertFalse($this->column->isVisible($isExported)); } - public function testIsVisibleIfNotExportedAndNoAuthChecker() + public function testIsVisibleIfNotExportedAndNoAuthChecker(): void { $this->assertTrue($this->column->isVisible()); } - public function testIsVisibleIfNotExportedNoAuthCheckerAndNotRole() + public function testIsVisibleIfNotExportedNoAuthCheckerAndNotRole(): void { $this->column->setAuthorizationChecker($this->createMock(AuthorizationCheckerInterface::class)); $this->assertTrue($this->column->isVisible()); } - public function testIsVisibleIfAuthCheckerIsGranted() + public function testIsVisibleIfAuthCheckerIsGranted(): void { $role = $this->createMock(Role::class); $this->column->setRole($role); @@ -119,7 +118,7 @@ public function testIsVisibleIfAuthCheckerIsGranted() $this->assertTrue($this->column->isVisible()); } - public function testIsNotVisibleIfAuthCheckerIsNotGranted() + public function testIsNotVisibleIfAuthCheckerIsNotGranted(): void { $role = $this->createMock(Role::class); $this->column->setRole($role); @@ -131,7 +130,7 @@ public function testIsNotVisibleIfAuthCheckerIsNotGranted() $this->assertFalse($this->column->isVisible()); } - public function testGetPrimaryFieldAsRouteParametersIfRouteParametersNotSetted() + public function testGetPrimaryFieldAsRouteParametersIfRouteParametersNotSetted(): void { $row = $this->createMock(Row::class); $row->method('getPrimaryField')->willReturn('id'); @@ -143,7 +142,7 @@ public function testGetPrimaryFieldAsRouteParametersIfRouteParametersNotSetted() $this->assertEquals(['id' => 1], $this->column->getRouteParameters($row, $rowAction)); } - public function testGetRouteParameters() + public function testGetRouteParameters(): void { $row = $this->createMock(Row::class); $row diff --git a/tests/Grid/Column/ArrayColumnTest.php b/tests/Grid/Column/ArrayColumnTest.php index 801e156..de33e60 100644 --- a/tests/Grid/Column/ArrayColumnTest.php +++ b/tests/Grid/Column/ArrayColumnTest.php @@ -11,20 +11,19 @@ class ArrayColumnTest extends TestCase { - /** @var ArrayColumn */ - private $column; + private ArrayColumn $column; public function setUp(): void { $this->column = new ArrayColumn(); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('array', $this->column->getType()); } - public function testInitializeDefaultParams() + public function testInitializeDefaultParams(): void { $this->assertSame( [ @@ -39,7 +38,7 @@ public function testInitializeDefaultParams() ); } - public function testDocumentFilters() + public function testDocumentFilters(): void { $value = ['foo', 'bar']; @@ -51,7 +50,7 @@ public function testDocumentFilters() ); } - public function testEqualFilter() + public function testEqualFilter(): void { $value = ['foo', 'foobar']; @@ -63,7 +62,7 @@ public function testEqualFilter() ); } - public function testNotEqualFilter() + public function testNotEqualFilter(): void { $value = ['foo', 'foobar']; @@ -75,7 +74,7 @@ public function testNotEqualFilter() ); } - public function testLikeFilter() + public function testLikeFilter(): void { $value = ['foo']; @@ -87,7 +86,7 @@ public function testLikeFilter() ); } - public function testNotLikeFilter() + public function testNotLikeFilter(): void { $value = ['foo']; @@ -99,7 +98,7 @@ public function testNotLikeFilter() ); } - public function testIsNullFilter() + public function testIsNullFilter(): void { $this->column->setData(['operator' => Column::OPERATOR_ISNULL]); @@ -114,7 +113,7 @@ public function testIsNullFilter() $this->assertSame(Column::DATA_DISJUNCTION, $this->column->getDataJunction()); } - public function testIsNotNullFilter() + public function testIsNotNullFilter(): void { $this->column->setData(['operator' => Column::OPERATOR_ISNOTNULL]); @@ -127,7 +126,7 @@ public function testIsNotNullFilter() ); } - public function testRenderCellWithoutCallback() + public function testRenderCellWithoutCallback(): void { $values = ['foo' => 'a', 'bar' => 'b', 'foobar' => ['c', 'd']]; @@ -141,7 +140,7 @@ public function testRenderCellWithoutCallback() $this->assertEquals($result, $values); } - public function testRenderCellWithCallback() + public function testRenderCellWithCallback(): void { $values = ['foo' => 'a', 'bar' => 'b', 'foobar' => ['c', 'd']]; $this->column->manipulateRenderCell(function ($value, $row, $router) { diff --git a/tests/Grid/Column/BlankColumnTest.php b/tests/Grid/Column/BlankColumnTest.php index 5269453..82cc8f3 100644 --- a/tests/Grid/Column/BlankColumnTest.php +++ b/tests/Grid/Column/BlankColumnTest.php @@ -7,14 +7,14 @@ class BlankColumnTest extends TestCase { - public function testGetType() + public function testGetType(): void { $column = new BlankColumn(); $this->assertEquals('blank', $column->getType()); } - public function testInitialize() + public function testInitialize(): void { $params = [ 'filterable' => true, diff --git a/tests/Grid/Column/BooleanColumnTest.php b/tests/Grid/Column/BooleanColumnTest.php index 5b0e681..ee8d447 100644 --- a/tests/Grid/Column/BooleanColumnTest.php +++ b/tests/Grid/Column/BooleanColumnTest.php @@ -10,27 +10,26 @@ class BooleanColumnTest extends TestCase { - /** @var BooleanColumn */ - private $column; + private BooleanColumn $column; public function setUp(): void { $this->column = new BooleanColumn(); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('boolean', $this->column->getType()); } - public function testGetDisplayedValue() + public function testGetDisplayedValue(): void { $this->assertEquals(1, $this->column->getDisplayedValue(true)); $this->assertEquals(0, $this->column->getDisplayedValue(false)); $this->assertEquals('foo', $this->column->getDisplayedValue('foo')); } - public function testInitialize() + public function testInitialize(): void { $params = [ 'filter' => 'foo', @@ -55,7 +54,7 @@ public function testInitialize() ); } - public function testInitializeAlignment() + public function testInitializeAlignment(): void { $this->assertEquals(Column::ALIGN_CENTER, $this->column->getAlign()); @@ -63,7 +62,7 @@ public function testInitializeAlignment() $this->assertEquals(Column::ALIGN_LEFT, $column->getAlign()); } - public function testInitializeSize() + public function testInitializeSize(): void { $this->assertEquals(30, $this->column->getSize()); @@ -71,7 +70,7 @@ public function testInitializeSize() $this->assertEquals(40, $column->getSize()); } - public function testInitializeValues() + public function testInitializeValues(): void { $this->assertEquals([1 => 'true', 0 => 'false'], $this->column->getValues()); @@ -81,7 +80,7 @@ public function testInitializeValues() $this->assertEquals($values, $column->getValues()); } - public function testIsQueryValid() + public function testIsQueryValid(): void { // It seems that's no way for this to return false @@ -91,7 +90,7 @@ public function testIsQueryValid() $this->assertTrue($this->column->isQueryValid(0)); } - public function testRenderCell() + public function testRenderCell(): void { $this->assertEquals( 'true', @@ -121,7 +120,7 @@ public function testRenderCell() ); } - public function testRenderCellWithCallback() + public function testRenderCellWithCallback(): void { $this->column->manipulateRenderCell( function ($value, $row, $router) { diff --git a/tests/Grid/Column/ColumnTest.php b/tests/Grid/Column/ColumnTest.php index cf3cc34..5278067 100644 --- a/tests/Grid/Column/ColumnTest.php +++ b/tests/Grid/Column/ColumnTest.php @@ -12,7 +12,7 @@ class ColumnTest extends TestCase { - public function testInitializeDefaultValues() + public function testInitializeDefaultValues(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -45,7 +45,7 @@ public function testInitializeDefaultValues() $this->assertEquals('
', $mock->getSeparator()); } - public function testInitialize() + public function testInitialize(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -151,7 +151,7 @@ public function testInitialize() $this->assertEquals($translationDomain, $mock->getTranslationDomain()); } - public function testRenderCellWithCallback() + public function testRenderCellWithCallback(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -166,7 +166,7 @@ public function testRenderCellWithCallback() $this->assertEquals(1, $mock->renderCell($value, $row, $router)); } - public function testRenderCellWithBoolValue() + public function testRenderCellWithBoolValue(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -180,7 +180,7 @@ public function testRenderCellWithBoolValue() $this->assertEquals('bar', $mock->renderCell('1', $row, $router)); } - public function testRenderCell() + public function testRenderCell(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -191,7 +191,7 @@ public function testRenderCell() $this->assertEquals('bar', $mock->renderCell('foo', $row, $router)); } - public function testManipulateRenderCell() + public function testManipulateRenderCell(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -207,7 +207,7 @@ public function testManipulateRenderCell() $this->assertEquals($callback, $mock->getCallback()); } - public function testGetId() + public function testGetId(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setId(1); @@ -215,7 +215,7 @@ public function testGetId() $this->assertEquals(1, $mock->getId()); } - public function testGetRenderBlockId() + public function testGetRenderBlockId(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setId('foo.bar:foobar'); @@ -223,7 +223,7 @@ public function testGetRenderBlockId() $this->assertEquals('foo_bar_foobar', $mock->getRenderBlockId()); } - public function testGetTitle() + public function testGetTitle(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -233,7 +233,7 @@ public function testGetTitle() $this->assertEquals($title, $mock->getTitle()); } - public function testSetVisible() + public function testSetVisible(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -243,7 +243,7 @@ public function testSetVisible() $this->assertTrue($mock->isVisible()); } - public function testItIsNotVisibleWhenNotExported() + public function testItIsNotVisibleWhenNotExported(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -254,7 +254,7 @@ public function testItIsNotVisibleWhenNotExported() $this->assertFalse($mock->isVisible($exported)); } - public function testItIsVisibleIfNotExported() + public function testItIsVisibleIfNotExported(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -265,7 +265,7 @@ public function testItIsVisibleIfNotExported() $this->assertTrue($mock->isVisible($exported)); } - public function testItIsVisibleIfNotExportedAndRoleNotSetted() + public function testItIsVisibleIfNotExportedAndRoleNotSetted(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -277,7 +277,7 @@ public function testItIsVisibleIfNotExportedAndRoleNotSetted() $this->assertTrue($mock->isVisible($exported)); } - public function testItIsVisibleIfNotExportedAndGranted() + public function testItIsVisibleIfNotExportedAndGranted(): void { $mock = $this->getMockForAbstractClass(Column::class); $role = $this->createMock(Role::class); @@ -293,7 +293,7 @@ public function testItIsVisibleIfNotExportedAndGranted() $this->assertTrue($mock->isVisible($exported)); } - public function testItIsNotVisibleIfNotExportedButNotGranted() + public function testItIsNotVisibleIfNotExportedButNotGranted(): void { $mock = $this->getMockForAbstractClass(Column::class); $role = $this->createMock(Role::class); @@ -309,7 +309,7 @@ public function testItIsNotVisibleIfNotExportedButNotGranted() $this->assertFalse($mock->isVisible($exported)); } - public function testItIsNotVisibleWhenExported() + public function testItIsNotVisibleWhenExported(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -320,7 +320,7 @@ public function testItIsNotVisibleWhenExported() $this->assertFalse($mock->isVisible($exported)); } - public function testItIsVisibleIfExported() + public function testItIsVisibleIfExported(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -331,7 +331,7 @@ public function testItIsVisibleIfExported() $this->assertTrue($mock->isVisible($exported)); } - public function testItIsVisibleIfExportedAndRoleNotSetted() + public function testItIsVisibleIfExportedAndRoleNotSetted(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -343,7 +343,7 @@ public function testItIsVisibleIfExportedAndRoleNotSetted() $this->assertTrue($mock->isVisible($exported)); } - public function testItIsVisibleIfExportedAndGranted() + public function testItIsVisibleIfExportedAndGranted(): void { $mock = $this->getMockForAbstractClass(Column::class); $role = $this->createMock(Role::class); @@ -359,7 +359,7 @@ public function testItIsVisibleIfExportedAndGranted() $this->assertTrue($mock->isVisible($exported)); } - public function testItIsNotVisibleIfExportedButNotGranted() + public function testItIsNotVisibleIfExportedButNotGranted(): void { $mock = $this->getMockForAbstractClass(Column::class); $role = $this->createMock(Role::class); @@ -375,14 +375,14 @@ public function testItIsNotVisibleIfExportedButNotGranted() $this->assertFalse($mock->isVisible($exported)); } - public function testIsNotSortedWhenNotOrdered() + public function testIsNotSortedWhenNotOrdered(): void { $mock = $this->getMockForAbstractClass(Column::class); $this->assertFalse($mock->isSorted()); } - public function testIsSortedWhenOrdered() + public function testIsSortedWhenOrdered(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setOrder(1); @@ -390,7 +390,7 @@ public function testIsSortedWhenOrdered() $this->assertTrue($mock->isSorted()); } - public function testSetSortable() + public function testSetSortable(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSortable(true); @@ -398,7 +398,7 @@ public function testSetSortable() $this->assertTrue($mock->isSortable()); } - public function testIsSortable() + public function testIsSortable(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSortable(true); @@ -406,14 +406,14 @@ public function testIsSortable() $this->assertTrue(true, $mock->isSortable()); } - public function testIsNotFilteredIfNeitherOperatorNorOperandsSetted() + public function testIsNotFilteredIfNeitherOperatorNorOperandsSetted(): void { $mock = $this->getMockForAbstractClass(Column::class); $this->assertFalse($mock->isFiltered()); } - public function testIsNotFilteredIfFromOperandHasDefaultValue() + public function testIsNotFilteredIfFromOperandHasDefaultValue(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['from' => Column::DEFAULT_VALUE]); @@ -421,7 +421,7 @@ public function testIsNotFilteredIfFromOperandHasDefaultValue() $this->assertFalse($mock->isFiltered()); } - public function testIsNotFilteredIfToOperandHasDefaultValue() + public function testIsNotFilteredIfToOperandHasDefaultValue(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['to' => Column::DEFAULT_VALUE]); @@ -429,7 +429,7 @@ public function testIsNotFilteredIfToOperandHasDefaultValue() $this->assertFalse($mock->isFiltered()); } - public function testIsNotFilteredIfOperatorNeitherIsIsNullNorIsNotNull() + public function testIsNotFilteredIfOperatorNeitherIsIsNullNorIsNotNull(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_LIKE]); @@ -437,7 +437,7 @@ public function testIsNotFilteredIfOperatorNeitherIsIsNullNorIsNotNull() $this->assertFalse($mock->isFiltered()); } - public function testIsFilteredIfFromOperandHasValueDifferentThanDefault() + public function testIsFilteredIfFromOperandHasValueDifferentThanDefault(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['from' => 1]); @@ -445,7 +445,7 @@ public function testIsFilteredIfFromOperandHasValueDifferentThanDefault() $this->assertTrue($mock->isFiltered()); } - public function testIsFilteredIfToOperandHasValueDifferentThanDefault() + public function testIsFilteredIfToOperandHasValueDifferentThanDefault(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['to' => 1]); @@ -453,7 +453,7 @@ public function testIsFilteredIfToOperandHasValueDifferentThanDefault() $this->assertTrue($mock->isFiltered()); } - public function testIsFilteredIfOperatorIsNull() + public function testIsFilteredIfOperatorIsNull(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_ISNULL]); @@ -461,7 +461,7 @@ public function testIsFilteredIfOperatorIsNull() $this->assertTrue($mock->isFiltered()); } - public function testIsFilteredIfOperatorIsNotNull() + public function testIsFilteredIfOperatorIsNotNull(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_ISNOTNULL]); @@ -469,7 +469,7 @@ public function testIsFilteredIfOperatorIsNotNull() $this->assertTrue($mock->isFiltered()); } - public function testIsFilterable() + public function testIsFilterable(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setFilterable(true); @@ -477,7 +477,7 @@ public function testIsFilterable() $this->assertTrue($mock->isFilterable()); } - public function testItDoesNotSetOrderIfOrderIsNull() + public function testItDoesNotSetOrderIfOrderIsNull(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setOrder(null); @@ -486,7 +486,7 @@ public function testItDoesNotSetOrderIfOrderIsNull() $this->assertFalse($mock->isSorted()); } - public function testItDoesSetOrderIfZero() + public function testItDoesSetOrderIfZero(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setOrder(0); @@ -495,7 +495,7 @@ public function testItDoesSetOrderIfZero() $this->assertTrue($mock->isSorted()); } - public function testItDoesSetOrder() + public function testItDoesSetOrder(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setOrder(1); @@ -504,7 +504,7 @@ public function testItDoesSetOrder() $this->assertTrue($mock->isSorted()); } - public function testGetOrder() + public function testGetOrder(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setOrder(1); @@ -512,7 +512,7 @@ public function testGetOrder() $this->assertEquals(1, $mock->getOrder()); } - public function testRaiseExceptionIfSizeNotAllowed() + public function testRaiseExceptionIfSizeNotAllowed(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -521,7 +521,7 @@ public function testRaiseExceptionIfSizeNotAllowed() $mock->setSize(-2); } - public function testAutoResize() + public function testAutoResize(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSize(-1); @@ -529,7 +529,7 @@ public function testAutoResize() $this->assertEquals(-1, $mock->getSize()); } - public function testGetSize() + public function testGetSize(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSize(3); @@ -537,7 +537,7 @@ public function testGetSize() $this->assertEquals(3, $mock->getSize()); } - public function testDataDefaultIfNoDataSetted() + public function testDataDefaultIfNoDataSetted(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData([]); @@ -552,7 +552,7 @@ public function testDataDefaultIfNoDataSetted() ); } - public function testSetNullOperatorWithoutFromToValues() + public function testSetNullOperatorWithoutFromToValues(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_ISNULL]); @@ -567,7 +567,7 @@ public function testSetNullOperatorWithoutFromToValues() ); } - public function testSetNotNullOperatorWithoutFromToValues() + public function testSetNotNullOperatorWithoutFromToValues(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_ISNOTNULL]); @@ -582,7 +582,7 @@ public function testSetNotNullOperatorWithoutFromToValues() ); } - public function testDoesNotSetDataIfOperatorNotNotNullOrNullNoFromToValues() + public function testDoesNotSetDataIfOperatorNotNotNullOrNullNoFromToValues(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -604,7 +604,7 @@ public function testDoesNotSetDataIfOperatorNotNotNullOrNullNoFromToValues() } } - public function testItSetsData() + public function testItSetsData(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -626,7 +626,7 @@ public function testItSetsData() } } - public function testGetDataNullOpearatorWithoutValues() + public function testGetDataNullOpearatorWithoutValues(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_ISNULL]); @@ -639,7 +639,7 @@ public function testGetDataNullOpearatorWithoutValues() ); } - public function testGetDataNotNullOpearatorWithoutValues() + public function testGetDataNotNullOpearatorWithoutValues(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -653,7 +653,7 @@ public function testGetDataNotNullOpearatorWithoutValues() ); } - public function testGetEmptyDataIfOperatorNotNotNullOrNullNoFromToValues() + public function testGetEmptyDataIfOperatorNotNotNullOrNullNoFromToValues(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -668,7 +668,7 @@ public function testGetEmptyDataIfOperatorNotNotNullOrNullNoFromToValues() } } - public function testGetData() + public function testGetData(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -690,14 +690,14 @@ public function testGetData() } } - public function testQueryIsAlwaysValid() + public function testQueryIsAlwaysValid(): void { $mock = $this->getMockForAbstractClass(Column::class); $this->assertTrue($mock->isQueryValid('foo')); } - public function testIsVisibleForSource() + public function testIsVisibleForSource(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setVisibleForSource(true); @@ -705,7 +705,7 @@ public function testIsVisibleForSource() $this->assertTrue($mock->isVisibleForSource()); } - public function testIsPrimary() + public function testIsPrimary(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setPrimary(true); @@ -713,7 +713,7 @@ public function testIsPrimary() $this->assertTrue($mock->isPrimary()); } - public function testItThrowsExceptionIfSetAnAlignNotAllowed() + public function testItThrowsExceptionIfSetAnAlignNotAllowed(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -722,7 +722,7 @@ public function testItThrowsExceptionIfSetAnAlignNotAllowed() $mock->setAlign('foo'); } - public function testGetAlign() + public function testGetAlign(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setAlign(Column::ALIGN_RIGHT); @@ -730,7 +730,7 @@ public function testGetAlign() $this->assertEquals(Column::ALIGN_RIGHT, $mock->getAlign()); } - public function testGetInputType() + public function testGetInputType(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setInputType('string'); @@ -738,7 +738,7 @@ public function testGetInputType() $this->assertEquals('string', $mock->getInputType()); } - public function testGetField() + public function testGetField(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setField('foo'); @@ -746,7 +746,7 @@ public function testGetField() $this->assertEquals('foo', $mock->getField()); } - public function testGetRole() + public function testGetRole(): void { $role = $this->createMock(Role::class); $mock = $this->getMockForAbstractClass(Column::class); @@ -755,7 +755,7 @@ public function testGetRole() $this->assertEquals($role, $mock->getRole()); } - public function testGetFilterType() + public function testGetFilterType(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setFilterType('TEXTBOX'); @@ -763,7 +763,7 @@ public function testGetFilterType() $this->assertEquals('textbox', $mock->getFilterType()); } - public function testGetDataJunction() + public function testGetDataJunction(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setDataJunction(Column::DATA_DISJUNCTION); @@ -771,7 +771,7 @@ public function testGetDataJunction() $this->assertEquals(Column::DATA_DISJUNCTION, $mock->getDataJunction()); } - public function testItThrowsExceptionIfSetDefaultOperatorWithOperatorNotAllowed() + public function testItThrowsExceptionIfSetDefaultOperatorWithOperatorNotAllowed(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -780,7 +780,7 @@ public function testItThrowsExceptionIfSetDefaultOperatorWithOperatorNotAllowed( $mock->setDefaultOperator('foo'); } - public function testGetDefaultOperator() + public function testGetDefaultOperator(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setDefaultOperator(Column::OPERATOR_LTE); @@ -788,7 +788,7 @@ public function testGetDefaultOperator() $this->assertEquals(Column::OPERATOR_LTE, $mock->getDefaultOperator()); } - public function testHasOperator() + public function testHasOperator(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -796,7 +796,7 @@ public function testHasOperator() $this->assertFalse($mock->hasOperator('foo')); } - public function testGetOperatorsVisible() + public function testGetOperatorsVisible(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setOperatorsVisible(false); @@ -804,7 +804,7 @@ public function testGetOperatorsVisible() $this->assertFalse($mock->getOperatorsVisible()); } - public function testGetValues() + public function testGetValues(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -814,7 +814,7 @@ public function testGetValues() $this->assertEquals($values, $mock->getValues()); } - public function testGetSelectFrom() + public function testGetSelectFrom(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSelectFrom('source'); @@ -822,7 +822,7 @@ public function testGetSelectFrom() $this->assertEquals('source', $mock->getSelectFrom()); } - public function testGetSelectMulti() + public function testGetSelectMulti(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSelectMulti(true); @@ -830,7 +830,7 @@ public function testGetSelectMulti() $this->assertTrue($mock->getSelectMulti()); } - public function testGetSelectExpanded() + public function testGetSelectExpanded(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSelectExpanded(true); @@ -838,7 +838,7 @@ public function testGetSelectExpanded() $this->assertTrue($mock->getSelectExpanded()); } - public function testSetAuthChecker() + public function testSetAuthChecker(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -848,21 +848,21 @@ public function testSetAuthChecker() $this->assertEquals($authChecker, $mock->getAuthorizationChecker()); } - public function testNoParentType() + public function testNoParentType(): void { $mock = $this->getMockForAbstractClass(Column::class); $this->assertEmpty($mock->getParentType()); } - public function testNoType() + public function testNoType(): void { $mock = $this->getMockForAbstractClass(Column::class); $this->assertEmpty($mock->getType()); } - public function testIsFilterSubmitOnChange() + public function testIsFilterSubmitOnChange(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSelectMulti(true); @@ -875,7 +875,7 @@ public function testIsFilterSubmitOnChange() $this->assertTrue($mock->isFilterSubmitOnChange()); } - public function testGetSearchOnClick() + public function testGetSearchOnClick(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSearchOnClick(false); @@ -883,7 +883,7 @@ public function testGetSearchOnClick() $this->assertFalse($mock->getSearchOnClick()); } - public function testGetSafe() + public function testGetSafe(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSafe('html'); @@ -891,7 +891,7 @@ public function testGetSafe() $this->assertEquals('html', $mock->getSafe()); } - public function testGetSeparator() + public function testGetSeparator(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSeparator(';'); @@ -899,7 +899,7 @@ public function testGetSeparator() $this->assertEquals(';', $mock->getSeparator()); } - public function testGetJoinType() + public function testGetJoinType(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setJoinType('left'); @@ -907,7 +907,7 @@ public function testGetJoinType() $this->assertEquals('left', $mock->getJoinType()); } - public function testGetExport() + public function testGetExport(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setExport(true); @@ -915,7 +915,7 @@ public function testGetExport() $this->assertTrue($mock->getExport()); } - public function testGetClass() + public function testGetClass(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setClass('aClass'); @@ -923,7 +923,7 @@ public function testGetClass() $this->assertEquals('aClass', $mock->getClass()); } - public function testGetIsManualField() + public function testGetIsManualField(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setIsManualField(true); @@ -931,7 +931,7 @@ public function testGetIsManualField() $this->assertTrue($mock->getIsManualField()); } - public function testGetIsAggregate() + public function testGetIsAggregate(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setIsAggregate(true); @@ -939,7 +939,7 @@ public function testGetIsAggregate() $this->assertTrue($mock->getIsAggregate()); } - public function testGetUsePrefixTitle() + public function testGetUsePrefixTitle(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setUsePrefixTitle(false); @@ -947,7 +947,7 @@ public function testGetUsePrefixTitle() $this->assertFalse($mock->getUsePrefixTitle()); } - public function testGetTranslationDomain() + public function testGetTranslationDomain(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setTranslationDomain('it'); @@ -955,14 +955,14 @@ public function testGetTranslationDomain() $this->assertEquals('it', $mock->getTranslationDomain()); } - public function testGetFiltersWithoutOperator() + public function testGetFiltersWithoutOperator(): void { $mock = $this->getMockForAbstractClass(Column::class); $this->assertEmpty($mock->getFilters('aSource')); } - public function testGetFiltersBtwWithoutFrom() + public function testGetFiltersBtwWithoutFrom(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_BTW, 'to' => 10]); @@ -975,7 +975,7 @@ public function testGetFiltersBtwWithoutFrom() ); } - public function testGetFiltersBtwWithoutTo() + public function testGetFiltersBtwWithoutTo(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_BTW, 'from' => 1]); @@ -988,7 +988,7 @@ public function testGetFiltersBtwWithoutTo() ); } - public function testGetFiltersBtw() + public function testGetFiltersBtw(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_BTW, 'from' => 1, 'to' => 10]); @@ -1002,7 +1002,7 @@ public function testGetFiltersBtw() ); } - public function testGetFiltersBtweWithoutFrom() + public function testGetFiltersBtweWithoutFrom(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_BTWE, 'to' => 10]); @@ -1012,7 +1012,7 @@ public function testGetFiltersBtweWithoutFrom() ], $mock->getFilters('aSource')); } - public function testGetFiltersBtweWithoutTo() + public function testGetFiltersBtweWithoutTo(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_BTWE, 'from' => 1]); @@ -1025,7 +1025,7 @@ public function testGetFiltersBtweWithoutTo() ); } - public function testGetFiltersBtwe() + public function testGetFiltersBtwe(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_BTWE, 'from' => 1, 'to' => 10]); @@ -1036,7 +1036,7 @@ public function testGetFiltersBtwe() ], $mock->getFilters('aSource')); } - public function testGetFiltersNullNoNull() + public function testGetFiltersNullNoNull(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -1047,7 +1047,7 @@ public function testGetFiltersNullNoNull() $this->assertEquals([new Filter(Column::OPERATOR_ISNOTNULL)], $mock->getFilters('aSource')); } - public function testGetFiltersLikeCombinationsNoMulti() + public function testGetFiltersLikeCombinationsNoMulti(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -1068,7 +1068,7 @@ public function testGetFiltersLikeCombinationsNoMulti() } } - public function testGetFiltersLikeCombinationsMulti() + public function testGetFiltersLikeCombinationsMulti(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setSelectMulti(true); @@ -1090,7 +1090,7 @@ public function testGetFiltersLikeCombinationsMulti() } } - public function testGetFiltersNotLikeCombination() + public function testGetFiltersNotLikeCombination(): void { $mock = $this->getMockForAbstractClass(Column::class); @@ -1113,7 +1113,7 @@ public function testGetFiltersNotLikeCombination() } } - public function testGetFiltersWithNotHandledOperator() + public function testGetFiltersWithNotHandledOperator(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => 'foo', 'from' => 'bar']); @@ -1126,7 +1126,7 @@ public function testGetFiltersWithNotHandledOperator() ); } - public function testSetOperators() + public function testSetOperators(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setOperators( @@ -1145,14 +1145,14 @@ public function testSetOperators() ); } - public function testGetOperators() + public function testGetOperators(): void { $mock = $this->getMockForAbstractClass(Column::class); $this->assertEquals(Column::getAvailableOperators(), $mock->getOperators()); } - public function testItHasDqlFunctionWithoutMatchesResultArray() + public function testItHasDqlFunctionWithoutMatchesResultArray(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setField('foo:bar:foobar'); @@ -1160,7 +1160,7 @@ public function testItHasDqlFunctionWithoutMatchesResultArray() $this->assertEquals(1, $mock->hasDQLFunction()); } - public function testItHasDqlFunctionWithMatchesResultArray() + public function testItHasDqlFunctionWithMatchesResultArray(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setField('foo:bar:foobar'); @@ -1184,7 +1184,7 @@ public function testItHasDqlFunctionWithMatchesResultArray() ); } - public function testItHasNotDqlFunctionWithoutMatchesResultArray() + public function testItHasNotDqlFunctionWithoutMatchesResultArray(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setField('foo'); @@ -1192,7 +1192,7 @@ public function testItHasNotDqlFunctionWithoutMatchesResultArray() $this->assertEquals(0, $mock->hasDQLFunction()); } - public function testItHasNotDqlFunctionWithMatchesResultArray() + public function testItHasNotDqlFunctionWithMatchesResultArray(): void { $mock = $this->getMockForAbstractClass(Column::class); $mock->setField('foo'); diff --git a/tests/Grid/Column/DateColumnTest.php b/tests/Grid/Column/DateColumnTest.php index 5cba7ba..4690d0a 100644 --- a/tests/Grid/Column/DateColumnTest.php +++ b/tests/Grid/Column/DateColumnTest.php @@ -9,20 +9,19 @@ class DateColumnTest extends TestCase { - /** @var DateColumn */ - private $column; + private DateColumn $column; public function setUp(): void { $this->column = new DateColumn(); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('date', $this->column->getType()); } - public function testGetFiltersWithoutValue() + public function testGetFiltersWithoutValue(): void { $operators = array_flip(Column::getAvailableOperators()); unset($operators[Column::OPERATOR_ISNOTNULL]); @@ -34,14 +33,14 @@ public function testGetFiltersWithoutValue() } } - public function testGetFiltersWithNotNullOperator() + public function testGetFiltersWithNotNullOperator(): void { $this->column->setData(['operator' => Column::OPERATOR_ISNOTNULL]); $this->assertEquals([new Filter(Column::OPERATOR_ISNOTNULL)], $this->column->getFilters('asource')); } - public function testGetFiltersWithIsNullOperator() + public function testGetFiltersWithIsNullOperator(): void { $this->column->setData(['operator' => Column::OPERATOR_ISNULL]); $filters = $this->column->getFilters('asource'); @@ -49,7 +48,7 @@ public function testGetFiltersWithIsNullOperator() $this->assertEquals([new Filter(Column::OPERATOR_ISNULL)], $filters); } - public function testGetFiltersOperatorEq() + public function testGetFiltersOperatorEq(): void { $from = '2017-03-18'; $to = '2017-03-20'; @@ -65,7 +64,7 @@ public function testGetFiltersOperatorEq() ); } - public function testGetFiltersOperatorNeq() + public function testGetFiltersOperatorNeq(): void { $from = '2017-03-18'; $to = '2017-03-20'; @@ -83,7 +82,7 @@ public function testGetFiltersOperatorNeq() $this->assertSame(Column::DATA_DISJUNCTION, $this->column->getDataJunction()); } - public function testGetFiltersOperatorLt() + public function testGetFiltersOperatorLt(): void { $value = '2017-03-18'; @@ -95,7 +94,7 @@ public function testGetFiltersOperatorLt() ); } - public function testGetFiltersOperatorGte() + public function testGetFiltersOperatorGte(): void { $value = '2017-03-18'; @@ -107,7 +106,7 @@ public function testGetFiltersOperatorGte() ); } - public function testGetFiltersOperatorGt() + public function testGetFiltersOperatorGt(): void { $value = '2017-03-18'; @@ -119,7 +118,7 @@ public function testGetFiltersOperatorGt() ); } - public function testGetFiltersOperatorLte() + public function testGetFiltersOperatorLte(): void { $value = '2017-03-18'; diff --git a/tests/Grid/Column/DateTimeColumnTest.php b/tests/Grid/Column/DateTimeColumnTest.php index 40f1366..9cf0d9f 100644 --- a/tests/Grid/Column/DateTimeColumnTest.php +++ b/tests/Grid/Column/DateTimeColumnTest.php @@ -11,13 +11,13 @@ class DateTimeColumnTest extends TestCase { - public function testGetType() + public function testGetType(): void { $column = new DateTimeColumn(); $this->assertEquals('datetime', $column->getType()); } - public function testSetFormat() + public function testSetFormat(): void { $format = 'Y-m-d'; @@ -27,7 +27,7 @@ public function testSetFormat() $this->assertEquals($format, $column->getFormat()); } - public function testSetInputFormat() + public function testSetInputFormat(): void { $inputFormat = 'Y-m-d'; @@ -37,7 +37,7 @@ public function testSetInputFormat() $this->assertEquals($inputFormat, $column->getInputFormat()); } - public function testSetTimezone() + public function testSetTimezone(): void { $timezone = 'UTC'; @@ -47,7 +47,7 @@ public function testSetTimezone() $this->assertEquals($timezone, $column->getTimezone()); } - public function testRenderCellWithoutCallback() + public function testRenderCellWithoutCallback(): void { $column = new DateTimeColumn(); $column->setFormat('Y-m-d H:i:s'); @@ -65,7 +65,7 @@ public function testRenderCellWithoutCallback() ); } - public function testRenderCellWithCallback() + public function testRenderCellWithCallback(): void { $column = new DateTimeColumn(); $column->setFormat('Y-m-d H:i:s'); @@ -84,7 +84,7 @@ public function testRenderCellWithCallback() ); } - public function testFilterWithValue() + public function testFilterWithValue(): void { $column = new DateTimeColumn(); $column->setData(['operator' => Column::OPERATOR_BTW, 'from' => '2017-03-22 01:30:00', 'to' => '2017-03-23 19:00:00']); @@ -98,7 +98,7 @@ public function testFilterWithValue() ); } - public function testFilterWithFormattedValue() + public function testFilterWithFormattedValue(): void { $column = new DateTimeColumn(); $column->setInputFormat('m/d/Y H-i-s'); @@ -113,7 +113,7 @@ public function testFilterWithFormattedValue() ); } - public function testFilterWithoutValue() + public function testFilterWithoutValue(): void { $column = new DateTimeColumn(); $column->setData(['operator' => Column::OPERATOR_ISNULL]); @@ -121,21 +121,21 @@ public function testFilterWithoutValue() $this->assertEquals([new Filter(Column::OPERATOR_ISNULL)], $column->getFilters('asource')); } - public function testQueryIsValid() + public function testQueryIsValid(): void { $column = new DateTimeColumn(); $this->assertTrue($column->isQueryValid('2017-03-22 23:00:00')); } - public function testQueryIsInvalid() + public function testQueryIsInvalid(): void { $column = new DateTimeColumn(); $this->assertFalse($column->isQueryValid('foo')); } - public function testInputFormattedQueryIsValid() + public function testInputFormattedQueryIsValid(): void { $column = new DateTimeColumn(); $column->setInputFormat('m/d/Y H-i-s'); @@ -143,7 +143,7 @@ public function testInputFormattedQueryIsValid() $this->assertTrue($column->isQueryValid('03/22/2017 23-00-00')); } - public function testInputFormattedQueryIsInvalid() + public function testInputFormattedQueryIsInvalid(): void { $column = new DateTimeColumn(); $column->setInputFormat('m/d/Y H-i-s'); @@ -151,7 +151,7 @@ public function testInputFormattedQueryIsInvalid() $this->assertFalse($column->isQueryValid('2017-03-22 23:00:00')); } - public function testInitializeDefaultParams() + public function testInitializeDefaultParams(): void { $column = new DateTimeColumn(); @@ -176,7 +176,7 @@ public function testInitializeDefaultParams() $this->assertEquals(date_default_timezone_get(), $column->getTimezone()); } - public function testInitialize() + public function testInitialize(): void { $format = 'Y-m-d H:i:s'; $inputFormat = 'Y-m-d H:i:s'; @@ -208,7 +208,7 @@ public function testInitialize() /** * @dataProvider provideDisplayInput */ - public function testCorrectDisplayOut($value, $expectedOutput, $timezone = null) + public function testCorrectDisplayOut(mixed $value, mixed $expectedOutput, ?string $timezone = null): void { $column = new DateTimeColumn(); $column->setFormat('Y-m-d H:i:s'); @@ -220,7 +220,7 @@ public function testCorrectDisplayOut($value, $expectedOutput, $timezone = null) $this->assertEquals($expectedOutput, $column->getDisplayedValue($value)); } - public function testDisplayValueForDateTimeImmutable() + public function testDisplayValueForDateTimeImmutable(): void { $now = new \DateTimeImmutable(); @@ -229,7 +229,7 @@ public function testDisplayValueForDateTimeImmutable() $this->assertEquals($now->format('Y-m-d H:i:s'), $column->getDisplayedValue($now)); } - public function testDateTimeZoneForDisplayValueIsTheSameAsTheColumn() + public function testDateTimeZoneForDisplayValueIsTheSameAsTheColumn(): void { $column = new DateTimeColumn(); $column->setFormat('Y-m-d H:i:s'); @@ -240,7 +240,7 @@ public function testDateTimeZoneForDisplayValueIsTheSameAsTheColumn() $this->assertEquals('2000-01-01 00:00:00', $column->getDisplayedValue($now)); } - public function provideDisplayInput() + public function provideDisplayInput(): array { $now = new \DateTime(); diff --git a/tests/Grid/Column/JoinColumnTest.php b/tests/Grid/Column/JoinColumnTest.php index 4c09eac..0e484ea 100644 --- a/tests/Grid/Column/JoinColumnTest.php +++ b/tests/Grid/Column/JoinColumnTest.php @@ -12,19 +12,19 @@ class JoinColumnTest extends TestCase /** * @var JoinColumn */ - private $column; + private JoinColumn $column; public function setUp(): void { $this->column = new JoinColumn(); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('join', $this->column->getType()); } - public function testInitializeDefaultParams() + public function testInitializeDefaultParams(): void { $params = []; $column = new JoinColumn($params); @@ -36,10 +36,10 @@ public function testInitializeDefaultParams() $this->assertTrue($column->getIsManualField()); } - public function testInitialize() + public function testInitialize(): void { - $col1 = 'col1'; - $col2 = 'col2'; + $col1 = 'col1'; + $col2 = 'col2'; $separator = '/'; $params = [ @@ -53,7 +53,7 @@ public function testInitialize() $this->assertEquals($separator, $column->getSeparator()); } - public function testSetJoinColumns() + public function testSetJoinColumns(): void { $col1 = 'col1'; $col2 = 'col2'; @@ -63,10 +63,10 @@ public function testSetJoinColumns() $this->assertEquals([$col1, $col2], $this->column->getJoinColumns()); } - public function testSetColumnNameOnFilters() + public function testSetColumnNameOnFilters(): void { - $col1 = 'col1'; - $col2 = 'col2'; + $col1 = 'col1'; + $col2 = 'col2'; $separator = '/'; $params = [ diff --git a/tests/Grid/Column/MassActionColumnTest.php b/tests/Grid/Column/MassActionColumnTest.php index 51241f0..e072ada 100644 --- a/tests/Grid/Column/MassActionColumnTest.php +++ b/tests/Grid/Column/MassActionColumnTest.php @@ -8,33 +8,30 @@ class MassActionColumnTest extends TestCase { - /** - * @var MassActionColumn - */ - private $column; + private MassActionColumn $column; public function setUp(): void { $this->column = new MassActionColumn(); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('massaction', $this->column->getType()); } - public function testGetFilterType() + public function testGetFilterType(): void { $this->assertEquals('massaction', $this->column->getFilterType()); } - public function testIsVisible() + public function testIsVisible(): void { $this->assertFalse($this->column->isVisible(true)); $this->assertTrue($this->column->isVisible(false)); } - public function testInitialize() + public function testInitialize(): void { $this->assertEquals( [ diff --git a/tests/Grid/Column/NumberColumnTest.php b/tests/Grid/Column/NumberColumnTest.php index a162d96..a6454ec 100644 --- a/tests/Grid/Column/NumberColumnTest.php +++ b/tests/Grid/Column/NumberColumnTest.php @@ -11,22 +11,19 @@ class NumberColumnTest extends TestCase { - /** - * @var NumberColumn - */ - private $column; + private NumberColumn $column; public function setUp(): void { $this->column = new NumberColumn(); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('number', $this->column->getType()); } - public function testInitializeDefaultParams() + public function testInitializeDefaultParams(): void { $this->assertEquals(Column::ALIGN_RIGHT, $this->column->getAlign()); $this->assertEquals(\NumberFormatter::DECIMAL, $this->column->getStyle()); @@ -56,13 +53,13 @@ public function testInitializeDefaultParams() $this->assertEquals(Column::OPERATOR_EQ, $this->column->getDefaultOperator()); } - public function testInitializeStyleWithInvalidValue() + public function testInitializeStyleWithInvalidValue(): void { $this->expectException(\InvalidArgumentException::class); $column = new NumberColumn(['style' => 'foostyle']); } - public function testGetStyle() + public function testGetStyle(): void { $column = new NumberColumn(['style' => 'decimal']); $this->assertEquals(\NumberFormatter::DECIMAL, $column->getStyle()); @@ -88,55 +85,55 @@ public function testGetStyle() $this->assertEquals(\NumberFormatter::SPELLOUT, $column->getStyle()); } - public function testGetLocale() + public function testGetLocale(): void { $column = new NumberColumn(['locale' => 'it']); $this->assertEquals('it', $column->getLocale()); } - public function testGetPrecision() + public function testGetPrecision(): void { $column = new NumberColumn(['precision' => 2]); $this->assertEquals(2, $column->getPrecision()); } - public function testGetGrouping() + public function testGetGrouping(): void { $column = new NumberColumn(['grouping' => 3]); $this->assertEquals(3, $column->getGrouping()); } - public function testGetRoundingMode() + public function testGetRoundingMode(): void { $column = new NumberColumn(['roundingMode' => \NumberFormatter::ROUND_HALFDOWN]); $this->assertEquals(\NumberFormatter::ROUND_HALFDOWN, $column->getRoundingMode()); } - public function testGetRuleSet() + public function testGetRuleSet(): void { $column = new NumberColumn(['ruleSet' => \NumberFormatter::PUBLIC_RULESETS]); $this->assertEquals(\NumberFormatter::PUBLIC_RULESETS, $column->getRuleSet()); } - public function testGetCurrencyCode() + public function testGetCurrencyCode(): void { $column = new NumberColumn(['currencyCode' => 'EUR']); $this->assertEquals('EUR', $column->getCurrencyCode()); } - public function testGetFractional() + public function testGetFractional(): void { $column = new NumberColumn(['fractional' => true]); $this->assertEquals(true, $column->getFractional()); } - public function testGetMaxFractionDigits() + public function testGetMaxFractionDigits(): void { $column = new NumberColumn(['maxFractionDigits' => 2]); $this->assertEquals(2, $column->getMaxFractionDigits()); } - public function testIsQueryValid() + public function testIsQueryValid(): void { $this->assertTrue($this->column->isQueryValid('1')); $this->assertTrue($this->column->isQueryValid(1)); @@ -147,7 +144,7 @@ public function testIsQueryValid() $this->assertFalse($this->column->isQueryValid(['foo', 'bar'])); } - public function testRenderCellWithCallback() + public function testRenderCellWithCallback(): void { $value = 1.0; $this->column->manipulateRenderCell(fn($value, $row, $router) => (int)$value); @@ -161,13 +158,13 @@ public function testRenderCellWithCallback() $this->assertEquals($value, $result); } - public function testDisplayedValueWithEmptyValue() + public function testDisplayedValueWithEmptyValue(): void { $this->assertEquals('', $this->column->getDisplayedValue('')); $this->assertEquals('', $this->column->getDisplayedValue(null)); } - public function testDisplayedPercentValue() + public function testDisplayedPercentValue(): void { $column = new NumberColumn([ 'precision' => 2, @@ -182,7 +179,7 @@ public function testDisplayedPercentValue() $this->assertEquals('1,000.00%', $column->getDisplayedValue(1000)); } - public function testDisplayedCurrencyValue() + public function testDisplayedCurrencyValue(): void { $column = new NumberColumn([ 'precision' => 2, @@ -198,7 +195,7 @@ public function testDisplayedCurrencyValue() $this->assertEquals('€1,000.00', $column->getDisplayedValue(1000)); } - public function testDisplayedCurrencyWithoutCurrencyCode() + public function testDisplayedCurrencyWithoutCurrencyCode(): void { $column = new NumberColumn([ 'precision' => 2, @@ -213,7 +210,7 @@ public function testDisplayedCurrencyWithoutCurrencyCode() $this->assertEquals('$1,000.00', $column->getDisplayedValue(1000)); } - public function testDisplayedCurrencyWithoutAValidISO4217CCurrencyCode() + public function testDisplayedCurrencyWithoutAValidISO4217CCurrencyCode(): void { $column = new NumberColumn([ 'precision' => 2, @@ -229,7 +226,7 @@ public function testDisplayedCurrencyWithoutAValidISO4217CCurrencyCode() $column->getDisplayedValue(1000); } - public function testDisplayedValueFromArrayValues() + public function testDisplayedValueFromArrayValues(): void { $column = new NumberColumn([ 'style' => 'decimal', @@ -239,7 +236,7 @@ public function testDisplayedValueFromArrayValues() $this->assertEquals(200, $column->getDisplayedValue(100)); } - public function testGetFilters() + public function testGetFilters(): void { $this->column->setData(['operator' => Column::OPERATOR_BTW, 'from' => '10', 'to' => '20']); $this->assertEquals( diff --git a/tests/Grid/Column/RankColumnTest.php b/tests/Grid/Column/RankColumnTest.php index dca35d0..0ce5a36 100644 --- a/tests/Grid/Column/RankColumnTest.php +++ b/tests/Grid/Column/RankColumnTest.php @@ -10,22 +10,19 @@ class RankColumnTest extends TestCase { - /** - * @var RankColumn - */ - private $column; + private RankColumn $column; public function setUp(): void { $this->column = new RankColumn(); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('rank', $this->column->getType()); } - public function testInitialize() + public function testInitialize(): void { $params = [ 'foo' => 'foo', @@ -50,7 +47,7 @@ public function testInitialize() ); } - public function testSetId() + public function testSetId(): void { $this->assertEquals('rank', $this->column->getId()); @@ -58,7 +55,7 @@ public function testSetId() $this->assertEquals('foo', $column->getId()); } - public function testSetTitle() + public function testSetTitle(): void { $this->assertEquals('rank', $this->column->getTitle()); @@ -66,7 +63,7 @@ public function testSetTitle() $this->assertEquals('foo', $column->getTitle()); } - public function testSetSize() + public function testSetSize(): void { $this->assertEquals('30', $this->column->getSize()); @@ -74,7 +71,7 @@ public function testSetSize() $this->assertEquals('20', $column->getSize()); } - public function testSetAlign() + public function testSetAlign(): void { $this->assertEquals(Column::ALIGN_CENTER, $this->column->getAlign()); @@ -82,7 +79,7 @@ public function testSetAlign() $this->assertEquals(Column::ALIGN_RIGHT, $column->getAlign()); } - public function testRenderCell() + public function testRenderCell(): void { $this->assertEquals(1, $this->column->renderCell(true, $this->createMock(Row::class), $this->createMock(RouterInterface::class))); $this->assertEquals(2, $this->column->renderCell(true, $this->createMock(Row::class), $this->createMock(RouterInterface::class))); diff --git a/tests/Grid/Column/SimpleArrayColumnTest.php b/tests/Grid/Column/SimpleArrayColumnTest.php index 1ef2ab7..1985222 100644 --- a/tests/Grid/Column/SimpleArrayColumnTest.php +++ b/tests/Grid/Column/SimpleArrayColumnTest.php @@ -11,22 +11,19 @@ class SimpleArrayColumnTest extends TestCase { - /** - * @var SimpleArrayColumn - */ - private $column; + private SimpleArrayColumn $column; public function setUp(): void { $this->column = new SimpleArrayColumn(); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('simple_array', $this->column->getType()); } - public function testInitializeDefaultParams() + public function testInitializeDefaultParams(): void { $this->assertEquals( [ @@ -43,7 +40,7 @@ public function testInitializeDefaultParams() $this->assertEquals(Column::OPERATOR_LIKE, $this->column->getDefaultOperator()); } - public function testEqualFilter() + public function testEqualFilter(): void { $value = ['foo, bar']; @@ -52,7 +49,7 @@ public function testEqualFilter() $this->assertEquals([new Filter(Column::OPERATOR_EQ, 'foo, bar')], $this->column->getFilters('asource')); } - public function testNotEqualFilter() + public function testNotEqualFilter(): void { $value = ['foo, bar']; @@ -61,7 +58,7 @@ public function testNotEqualFilter() $this->assertEquals([new Filter(Column::OPERATOR_NEQ, 'foo, bar')], $this->column->getFilters('asource')); } - public function testLikeFilter() + public function testLikeFilter(): void { $value = ['foo, bar']; @@ -70,7 +67,7 @@ public function testLikeFilter() $this->assertEquals([new Filter(Column::OPERATOR_LIKE, 'foo, bar')], $this->column->getFilters('asource')); } - public function testNotLikeFilter() + public function testNotLikeFilter(): void { $value = ['foo, bar']; @@ -79,7 +76,7 @@ public function testNotLikeFilter() $this->assertEquals([new Filter(Column::OPERATOR_NLIKE, 'foo, bar')], $this->column->getFilters('asource')); } - public function testIsNullFilter() + public function testIsNullFilter(): void { $this->column->setData(['operator' => Column::OPERATOR_ISNULL]); @@ -94,7 +91,7 @@ public function testIsNullFilter() $this->assertEquals(Column::DATA_DISJUNCTION, $this->column->getDataJunction()); } - public function testIsNotNullFilter() + public function testIsNotNullFilter(): void { $this->column->setData(['operator' => Column::OPERATOR_ISNOTNULL]); @@ -107,7 +104,7 @@ public function testIsNotNullFilter() ); } - public function testRenderCellWithoutCallback() + public function testRenderCellWithoutCallback(): void { $values = ['foo, bar']; @@ -120,7 +117,7 @@ public function testRenderCellWithoutCallback() $this->assertEquals($values, $result); } - public function testRenderCellWithCallback() + public function testRenderCellWithCallback(): void { $values = ['foo, bar']; diff --git a/tests/Grid/Column/TextColumnTest.php b/tests/Grid/Column/TextColumnTest.php index 3cc8647..3c68a50 100644 --- a/tests/Grid/Column/TextColumnTest.php +++ b/tests/Grid/Column/TextColumnTest.php @@ -9,29 +9,26 @@ class TextColumnTest extends WebTestCase { - /** - * @var TextColumn - */ - private $column; + private TextColumn $column; public function setUp(): void { $this->column = new TextColumn(); } - public function testGetType() + public function testGetType(): void { $this->assertEquals('text', $this->column->getType()); } - public function testIsQueryValid() + public function testIsQueryValid(): void { $this->assertTrue($this->column->isQueryValid('foo')); $this->assertTrue($this->column->isQueryValid(['foo', 1, 'bar', null])); $this->assertFalse($this->column->isQueryValid(1)); } - public function testNullOperatorFilters() + public function testNullOperatorFilters(): void { $this->column->setData(['operator' => Column::OPERATOR_ISNULL]); @@ -46,7 +43,7 @@ public function testNullOperatorFilters() $this->assertEquals(Column::DATA_DISJUNCTION, $this->column->getDataJunction()); } - public function testNotNullOperatorFilters() + public function testNotNullOperatorFilters(): void { $this->column->setData(['operator' => Column::OPERATOR_ISNOTNULL]); @@ -59,7 +56,7 @@ public function testNotNullOperatorFilters() ); } - public function testOtherOperatorFilters() + public function testOtherOperatorFilters(): void { $operators = array_flip(Column::getAvailableOperators()); diff --git a/tests/Grid/Column/TimeColumnTest.php b/tests/Grid/Column/TimeColumnTest.php index b35b312..fbe2606 100644 --- a/tests/Grid/Column/TimeColumnTest.php +++ b/tests/Grid/Column/TimeColumnTest.php @@ -7,7 +7,7 @@ class TimeColumnTest extends TestCase { - public function testGetType() + public function testGetType(): void { $column = new TimeColumn(); diff --git a/tests/Grid/Column/UntypedColumnTest.php b/tests/Grid/Column/UntypedColumnTest.php index e53560c..73ce873 100644 --- a/tests/Grid/Column/UntypedColumnTest.php +++ b/tests/Grid/Column/UntypedColumnTest.php @@ -7,7 +7,7 @@ class UntypedColumnTest extends TestCase { - public function testGetParams() + public function testGetParams(): void { $params = ['foo', 'bar']; $column = new UntypedColumn($params); @@ -15,7 +15,7 @@ public function testGetParams() $this->assertEquals($params, $column->getParams()); } - public function getType() + public function getType(): void { $type = 'text'; diff --git a/tests/Grid/ColumnsTest.php b/tests/Grid/ColumnsTest.php index a98d751..3f719c8 100644 --- a/tests/Grid/ColumnsTest.php +++ b/tests/Grid/ColumnsTest.php @@ -5,30 +5,29 @@ use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Columns; use APY\DataGridBundle\Grid\Helper\ColumnsIterator; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; class ColumnsTest extends TestCase { - /** @var Columns */ - private $columns; + private Columns $columns; - /** @var AuthorizationCheckerInterface */ - private $authChecker; + private AuthorizationCheckerInterface $authChecker; public function setUp(): void { $this->authChecker = $this->createMock(AuthorizationCheckerInterface::class); - $this->columns = new Columns($this->authChecker); + $this->columns = new Columns($this->authChecker); } - public function testGetIterator() + public function testGetIterator(): void { $iterator = $this->columns->getIterator(); $this->assertInstanceOf(ColumnsIterator::class, $iterator); } - public function testAddColumn() + public function testAddColumn(): void { $column = $this->buildColumnMocks(1); $this->columns->addColumn($column); @@ -36,7 +35,7 @@ public function testAddColumn() $this->equalTo(1, $this->columns->count()); } - public function testAddColumnsOrder() + public function testAddColumnsOrder(): void { [$column1, $column2, $column3, $column4] = $this->buildColumnMocks(4); @@ -49,7 +48,7 @@ public function testAddColumnsOrder() $this->assertSame([$column2, $column3, $column4, $column1], iterator_to_array($this->columns->getIterator())); } - public function testRaiseExceptionIfGetColumnByIdDoesNotExists() + public function testRaiseExceptionIfGetColumnByIdDoesNotExists(): void { $this->expectException(\InvalidArgumentException::class); @@ -59,7 +58,7 @@ public function testRaiseExceptionIfGetColumnByIdDoesNotExists() $this->columns->getColumnById('foo'); } - public function testGetColumnById() + public function testGetColumnById(): void { $column = $this->buildColumnMocks(1); $column->method('getId')->willReturn('foo'); @@ -68,7 +67,7 @@ public function testGetColumnById() $this->assertSame($column, $this->columns->getColumnById('foo')); } - public function testHasColumnById() + public function testHasColumnById(): void { $column = $this->buildColumnMocks(1); $column->method('getId')->willReturn('foo'); @@ -78,7 +77,7 @@ public function testHasColumnById() $this->assertTrue($this->columns->hasColumnById('foo', false)); } - public function testRaiseExceptionIfGetPrimaryColumnDoesNotExists() + public function testRaiseExceptionIfGetPrimaryColumnDoesNotExists(): void { $this->expectException(\InvalidArgumentException::class); @@ -89,7 +88,7 @@ public function testRaiseExceptionIfGetPrimaryColumnDoesNotExists() $this->columns->getPrimaryColumn(); } - public function testGetPrimaryColumn() + public function testGetPrimaryColumn(): void { [$column1, $column2, $column3] = $this->buildColumnMocks(3); @@ -105,7 +104,7 @@ public function testGetPrimaryColumn() $this->assertSame($column2, $this->columns->getPrimaryColumn()); } - public function testAddExtension() + public function testAddExtension(): void { $column1 = $this->createMock(Column::class); $column1->method('getType')->willReturn('foo'); @@ -121,7 +120,7 @@ public function testAddExtension() $this->assertSame($column2, $this->columns->getExtensionForColumnType('bar')); } - public function testHasExtensionForColumnType() + public function testHasExtensionForColumnType(): void { $column1 = $this->createMock(Column::class); $column1->method('getType')->willReturn('foo'); @@ -132,7 +131,7 @@ public function testHasExtensionForColumnType() $this->assertFalse($this->columns->hasExtensionForColumnType('bar')); } - public function testGetExtensionForColumnType() + public function testGetExtensionForColumnType(): void { $column1 = $this->createMock(Column::class); $column1->method('getType')->willReturn('foo'); @@ -142,7 +141,7 @@ public function testGetExtensionForColumnType() $this->assertEquals($column1, $this->columns->getExtensionForColumnType('foo')); } - public function testGetHash() + public function testGetHash(): void { $this->assertEquals('', $this->columns->getHash()); @@ -162,7 +161,7 @@ public function testGetHash() $this->assertEquals('thisIsTheHash', $this->columns->getHash()); } - public function testSetColumnsOrder() + public function testSetColumnsOrder(): void { [$column1, $column2, $column3] = $this->buildColumnMocks(3); @@ -179,7 +178,7 @@ public function testSetColumnsOrder() $this->assertSame([$column3, $column1, $column2], iterator_to_array($this->columns->getIterator())); } - public function testPartialSetColumnsOrderAndKeepOthers() + public function testPartialSetColumnsOrderAndKeepOthers(): void { [$column1, $column2, $column3] = $this->buildColumnMocks(3); @@ -196,7 +195,7 @@ public function testPartialSetColumnsOrderAndKeepOthers() $this->assertSame([$column3, $column2, $column1], iterator_to_array($this->columns->getIterator())); } - public function testPartialSetColumnsOrderWithoutKeepOthers() + public function testPartialSetColumnsOrderWithoutKeepOthers(): void { [$column1, $column2, $column3] = $this->buildColumnMocks(3); @@ -213,12 +212,7 @@ public function testPartialSetColumnsOrderWithoutKeepOthers() $this->assertSame([$column3, $column2], iterator_to_array($this->columns->getIterator())); } - /** - * @param int $number - * - * @return array|\PHPUnit\Framework\MockObject\MockObject[]|\PHPUnit\Framework\MockObject\MockObject - */ - private function buildColumnMocks($number) + private function buildColumnMocks(int $number): array|MockObject { $mocks = []; for ($i = 0; $i < $number; ++$i) { diff --git a/tests/Grid/FilterTest.php b/tests/Grid/FilterTest.php index 144c5a0..fb128e0 100644 --- a/tests/Grid/FilterTest.php +++ b/tests/Grid/FilterTest.php @@ -7,7 +7,7 @@ class FilterTest extends TestCase { - public function testCreateFilters() + public function testCreateFilters(): void { $filter1 = new Filter('like', 'foo', 'column1'); @@ -16,28 +16,28 @@ public function testCreateFilters() $this->assertSame('column1', $filter1->getColumnName()); } - public function testGetOperator() + public function testGetOperator(): void { $filter = new Filter('like'); $this->assertEquals('like', $filter->getOperator()); } - public function testGetValue() + public function testGetValue(): void { $filter = new Filter('like', 'foo'); $this->assertEquals('foo', $filter->getValue()); } - public function testGetColumnName() + public function testGetColumnName(): void { $filter = new Filter('like', null, 'col1'); $this->assertEquals('col1', $filter->getColumnName()); } - public function testHasColumnName() + public function testHasColumnName(): void { $filter1 = new Filter('like', 'foo', 'col1'); $filter2 = new Filter('like'); diff --git a/tests/Grid/GridBuilderTest.php b/tests/Grid/GridBuilderTest.php index 320ca77..0c520df 100755 --- a/tests/Grid/GridBuilderTest.php +++ b/tests/Grid/GridBuilderTest.php @@ -10,6 +10,7 @@ use APY\DataGridBundle\Grid\GridFactoryInterface; use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use Doctrine\Persistence\ManagerRegistry; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -24,15 +25,9 @@ */ class GridBuilderTest extends TestCase { - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $factory; + private ?MockObject $factory; - /** - * @var GridBuilder - */ - private $builder; + private ?GridBuilder $builder; /** * {@inheritdoc} @@ -59,7 +54,7 @@ protected function tearDown(): void $this->builder = null; } - public function testAddUnexpectedType() + public function testAddUnexpectedType(): void { $this->expectException(UnexpectedTypeException::class); @@ -67,7 +62,7 @@ public function testAddUnexpectedType() $this->builder->add('foo', ['test']); } - public function testAddColumnTypeString() + public function testAddColumnTypeString(): void { $this->assertFalse($this->builder->has('foo')); @@ -81,7 +76,7 @@ public function testAddColumnTypeString() $this->assertTrue($this->builder->has('foo')); } - public function testAddColumnType() + public function testAddColumnType(): void { $this->factory->expects($this->never())->method('createColumn'); @@ -90,13 +85,13 @@ public function testAddColumnType() $this->assertTrue($this->builder->has('foo')); } - public function testAddIsFluent() + public function testAddIsFluent(): void { $builder = $this->builder->add('name', 'text', ['key' => 'value']); $this->assertSame($builder, $this->builder); } - public function testGetUnknown() + public function testGetUnknown(): void { $this->expectException( InvalidArgumentException::class, @@ -106,7 +101,7 @@ public function testGetUnknown() $this->builder->get('foo'); } - public function testGetExplicitColumnType() + public function testGetExplicitColumnType(): void { $expectedColumn = $this->createMock(Column::class); @@ -122,7 +117,7 @@ public function testGetExplicitColumnType() $this->assertSame($expectedColumn, $column); } - public function testHasColumnType() + public function testHasColumnType(): void { $this->factory->expects($this->once()) ->method('createColumn') @@ -134,12 +129,12 @@ public function testHasColumnType() $this->assertTrue($this->builder->has('foo')); } - public function assertHasNotColumnType() + public function assertHasNotColumnType(): void { $this->assertFalse($this->builder->has('foo')); } - public function testRemove() + public function testRemove(): void { $this->factory->expects($this->once()) ->method('createColumn') @@ -153,13 +148,13 @@ public function testRemove() $this->assertFalse($this->builder->has('foo')); } - public function testRemoveIsFluent() + public function testRemoveIsFluent(): void { $builder = $this->builder->remove('foo'); $this->assertSame($builder, $this->builder); } - public function testGetGrid() + public function testGetGrid(): void { $this->assertInstanceOf(Grid::class, $this->builder->getGrid()); } diff --git a/tests/Grid/GridConfigBuilderTest.php b/tests/Grid/GridConfigBuilderTest.php index 6ad4220..1295d0e 100644 --- a/tests/Grid/GridConfigBuilderTest.php +++ b/tests/Grid/GridConfigBuilderTest.php @@ -10,14 +10,11 @@ class GridConfigBuilderTest extends TestCase { - /** @var string */ - private $name = 'foo'; + private string $name = 'foo'; - /** @var array */ - private $options = ['foo' => 'foo', 'bar' => 'bar']; + private array $options = ['foo' => 'foo', 'bar' => 'bar']; - /** @var GridConfigBuilder */ - private $gridConfigBuilder; + private GridConfigBuilder $gridConfigBuilder; /** * {@inheritdoc} @@ -27,12 +24,12 @@ protected function setUp(): void $this->gridConfigBuilder = new GridConfigBuilder($this->name, $this->options); } - public function testGetName() + public function testGetName(): void { $this->assertEquals($this->name, $this->gridConfigBuilder->getName()); } - public function testGetSource() + public function testGetSource(): void { $source = $this->createMock(Source::class); $this->gridConfigBuilder->setSource($source); @@ -40,7 +37,7 @@ public function testGetSource() $this->assertSame($source, $this->gridConfigBuilder->getSource()); } - public function testGetType() + public function testGetType(): void { $type = $this->createMock(GridTypeInterface::class); $this->gridConfigBuilder->setType($type); @@ -48,7 +45,7 @@ public function testGetType() $this->assertSame($type, $this->gridConfigBuilder->getType()); } - public function testGetRoute() + public function testGetRoute(): void { $route = 'vendor.bundle.foo_route'; $this->gridConfigBuilder->setRoute($route); @@ -56,7 +53,7 @@ public function testGetRoute() $this->assertEquals($route, $this->gridConfigBuilder->getRoute()); } - public function testGetRouteParameters() + public function testGetRouteParameters(): void { $routeParams = ['foo' => 'foo', 'bar' => 'bar']; $this->gridConfigBuilder->setRouteParameters($routeParams); @@ -64,7 +61,7 @@ public function testGetRouteParameters() $this->assertEquals($routeParams, $this->gridConfigBuilder->getRouteParameters()); } - public function testIsPersited() + public function testIsPersited(): void { $persisted = false; $this->gridConfigBuilder->setPersistence($persisted); @@ -72,7 +69,7 @@ public function testIsPersited() $this->assertFalse($this->gridConfigBuilder->isPersisted()); } - public function testGetPage() + public function testGetPage(): void { $page = 5; $this->gridConfigBuilder->setPage($page); @@ -80,25 +77,25 @@ public function testGetPage() $this->assertEquals($page, $this->gridConfigBuilder->getPage()); } - public function testGetOptions() + public function testGetOptions(): void { $this->assertEquals($this->options, $this->gridConfigBuilder->getOptions()); } - public function testHasOption() + public function testHasOption(): void { $this->assertTrue($this->gridConfigBuilder->hasOption('foo')); $this->assertFalse($this->gridConfigBuilder->hasOption('foobar')); } - public function testGetOption() + public function testGetOption(): void { $this->assertEquals('foo', $this->gridConfigBuilder->getOption('foo')); $this->assertEquals('default', $this->gridConfigBuilder->getOption('foobar', 'default')); $this->assertNull($this->gridConfigBuilder->getOption('foobar')); } - public function testGetMaxPerPage() + public function testGetMaxPerPage(): void { $limit = 100; $this->gridConfigBuilder->setMaxPerPage($limit); @@ -106,7 +103,7 @@ public function testGetMaxPerPage() $this->assertEquals($limit, $this->gridConfigBuilder->getMaxPerPage()); } - public function testGetMaxResults() + public function testGetMaxResults(): void { $maxResults = 100; $this->gridConfigBuilder->setMaxResults($maxResults); @@ -114,7 +111,7 @@ public function testGetMaxResults() $this->assertEquals($maxResults, $this->gridConfigBuilder->getMaxResults()); } - public function testIsSortable() + public function testIsSortable(): void { $sortable = false; $this->gridConfigBuilder->setSortable($sortable); @@ -130,7 +127,7 @@ public function testIsFilterable() $this->assertTrue($this->gridConfigBuilder->isFilterable()); } - public function testGetOrder() + public function testGetOrder(): void { $order = 'desc'; $this->gridConfigBuilder->setOrder($order); @@ -138,7 +135,7 @@ public function testGetOrder() $this->assertEquals($order, $this->gridConfigBuilder->getOrder()); } - public function testGetSortBy() + public function testGetSortBy(): void { $sortBy = 'bar'; $this->gridConfigBuilder->setSortBy($sortBy); @@ -146,7 +143,7 @@ public function testGetSortBy() $this->assertEquals($sortBy, $this->gridConfigBuilder->getSortBy()); } - public function testGetGroupBy() + public function testGetGroupBy(): void { $groupBy = ['foo', 'bar']; $this->gridConfigBuilder->setGroupBy($groupBy); @@ -154,7 +151,7 @@ public function testGetGroupBy() $this->assertEquals($groupBy, $this->gridConfigBuilder->getGroupBy()); } - public function testAddAction() + public function testAddAction(): void { $action1 = $this->createMock(RowActionInterface::class); $action1->method('getColumn')->willReturn('foo'); @@ -173,7 +170,7 @@ public function testAddAction() $this->assertSame(['foo' => [$action1], 'bar' => [$action2, $action3]], $this->gridConfigBuilder->getActions()); } - public function testGetGridConfig() + public function testGetGridConfig(): void { $this->assertInstanceOf(GridConfigBuilder::class, $this->gridConfigBuilder->getGridConfig()); } diff --git a/tests/Grid/GridFactoryTest.php b/tests/Grid/GridFactoryTest.php index a006584..9019b25 100755 --- a/tests/Grid/GridFactoryTest.php +++ b/tests/Grid/GridFactoryTest.php @@ -13,6 +13,7 @@ use APY\DataGridBundle\Grid\Mapping\Metadata\Manager; use APY\DataGridBundle\Grid\Type\GridType; use Doctrine\Persistence\ManagerRegistry; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -28,20 +29,11 @@ */ class GridFactoryTest extends TestCase { - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $registry; + private MockObject $registry; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $builder; + private MockObject $builder; - /** - * @var GridFactory - */ - private $factory; + private GridFactory $factory; protected function setUp(): void { @@ -60,7 +52,7 @@ protected function setUp(): void $this->factory = new GridFactory($auth, $router, $requestStack, $twig, $httpKernel, $registry, $manager, $kernel, $translator, $this->registry); } - public function testCreateWithUnexpectedType() + public function testCreateWithUnexpectedType(): void { $this->expectException(UnexpectedTypeException::class); $this->factory->create(1234); @@ -68,7 +60,7 @@ public function testCreateWithUnexpectedType() $this->factory->create(new \stdClass()); } - public function testCreateWithTypeString() + public function testCreateWithTypeString(): void { $this->registry->expects($this->once()) ->method('getType') @@ -78,14 +70,14 @@ public function testCreateWithTypeString() $this->assertInstanceOf(Grid::class, $this->factory->create('foo')); } - public function testCreateWithTypeObject() + public function testCreateWithTypeObject(): void { $this->registry->expects($this->never())->method('getType'); $this->assertInstanceOf(Grid::class, $this->factory->create(new GridType())); } - public function testCreateBuilderWithDefaultType() + public function testCreateBuilderWithDefaultType(): void { $defaultType = new GridType(); @@ -99,7 +91,7 @@ public function testCreateBuilderWithDefaultType() $this->assertSame($defaultType, $builder->getType()); } - public function testCreateBuilder() + public function testCreateBuilder(): void { $givenOptions = ['a' => 1, 'b' => 2]; $resolvedOptions = ['a' => 1, 'b' => 2, 'c' => 3]; @@ -142,13 +134,13 @@ public function testCreateBuilder() $this->assertNull($builder->getSource()); } - public function testCreateColumnWithUnexpectedType() + public function testCreateColumnWithUnexpectedType(): void { $this->expectException(UnexpectedTypeException::class); $this->factory->createColumn('foo', 1234); } - public function testCreateColumnWithTypeString() + public function testCreateColumnWithTypeString(): void { $expectedColumn = new TextColumn(); @@ -167,7 +159,7 @@ public function testCreateColumnWithTypeString() $this->assertTrue($column->isVisibleForSource()); } - public function testCreateColumnWithObject() + public function testCreateColumnWithObject(): void { $column = $this->factory->createColumn('foo', new TextColumn(), ['title' => 'bar']); diff --git a/tests/Grid/GridManagerTest.php b/tests/Grid/GridManagerTest.php index 6a759ba..48181fc 100644 --- a/tests/Grid/GridManagerTest.php +++ b/tests/Grid/GridManagerTest.php @@ -4,6 +4,7 @@ use APY\DataGridBundle\Grid\Grid; use APY\DataGridBundle\Grid\GridManager; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\Response; @@ -11,15 +12,9 @@ class GridManagerTest extends TestCase { - /** - * @var GridManager - */ - private $gridManager; + private GridManager $gridManager; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $container; + private MockObject $container; public function setUp(): void { @@ -27,12 +22,12 @@ public function setUp(): void $this->gridManager = new GridManager($this->container); } - public function testGetIterator() + public function testGetIterator(): void { $this->assertInstanceOf(\SplObjectStorage::class, $this->gridManager->getIterator()); } - public function testCreateGridWithoutId() + public function testCreateGridWithoutId(): void { $grid = $this->createMock(Grid::class); $this @@ -53,7 +48,7 @@ public function testCreateGridWithoutId() $this->assertEquals($grids, $this->gridManager->getIterator()); } - public function testCreateGridWithId() + public function testCreateGridWithId(): void { $grid = $this->createMock(Grid::class); $this @@ -76,7 +71,7 @@ public function testCreateGridWithId() $this->assertEquals($grids, $this->gridManager->getIterator()); } - public function testReturnsManagedGridCount() + public function testReturnsManagedGridCount(): void { $grid = $this->createMock(Grid::class); $this @@ -90,7 +85,7 @@ public function testReturnsManagedGridCount() $this->assertEquals(1, $this->gridManager->count()); } - public function testGetRouteUrl() + public function testGetRouteUrl(): void { $routeUrl = 'aRouteUrl'; $this->gridManager->setRouteUrl($routeUrl); @@ -106,19 +101,19 @@ public function testItThrowsExceptionWhenCheckForRedirectAndGridsNotSetted() $this->gridManager->isReadyForRedirect(); } - public function testItThrowsExceptionWhenTwoDifferentGridsReturnsSameHashDuringCheckForRedirect() + public function testItThrowsExceptionWhenTwoDifferentGridsReturnsSameHashDuringCheckForRedirect(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage(GridManager::SAME_GRID_HASH_EX_MSG); $sameHash = 'hashValue'; - $this->stubTwoGridsForRedirect($sameHash, null, null, $sameHash, null, null); + $this->stubTwoGridsForRedirect($sameHash, null, false, $sameHash, null, false); $this->gridManager->isReadyForRedirect(); } - public function testNoGridsReadyForRedirect() + public function testNoGridsReadyForRedirect(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -128,7 +123,7 @@ public function testNoGridsReadyForRedirect() $this->assertFalse($this->gridManager->isReadyForRedirect()); } - public function testAtLeastOneGridReadyForRedirect() + public function testAtLeastOneGridReadyForRedirect(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -138,7 +133,7 @@ public function testAtLeastOneGridReadyForRedirect() $this->assertTrue($this->gridManager->isReadyForRedirect()); } - public function testItRewindGridListWhenCheckingTwoTimesIfReadyForRedirect() + public function testItRewindGridListWhenCheckingTwoTimesIfReadyForRedirect(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -173,7 +168,7 @@ public function testItRewindGridListWhenCheckingTwoTimesIfReadyForRedirect() $this->gridManager->isReadyForRedirect(); } - public function testItIgnoresEveryGridUrlIfRouteUrlAlreadySetted() + public function testItIgnoresEveryGridUrlIfRouteUrlAlreadySetted(): void { $grid1Hash = 'hashValue1'; $route1Url = 'route1Url'; @@ -181,7 +176,7 @@ public function testItIgnoresEveryGridUrlIfRouteUrlAlreadySetted() $grid2Hash = 'hashValue2'; $route2Url = 'route2Url'; - $this->stubTwoGridsForRedirect($grid1Hash, $route1Url, null, $grid2Hash, $route2Url, null); + $this->stubTwoGridsForRedirect($grid1Hash, $route1Url, false, $grid2Hash, $route2Url, false); $settedRouteUrl = 'settedRouteUrl'; $this->gridManager->setRouteUrl($settedRouteUrl); @@ -191,7 +186,7 @@ public function testItIgnoresEveryGridUrlIfRouteUrlAlreadySetted() $this->assertSame($settedRouteUrl, $this->gridManager->getRouteUrl()); } - public function testItThrowsExceptionWhenCheckForExportAndGridsNotSetted() + public function testItThrowsExceptionWhenCheckForExportAndGridsNotSetted(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage(GridManager::NO_GRID_EX_MSG); @@ -199,19 +194,19 @@ public function testItThrowsExceptionWhenCheckForExportAndGridsNotSetted() $this->gridManager->isReadyForExport(); } - public function testItThrowsExceptionWhenTwoDifferentGridsReturnsSameHashDuringCheckForExport() + public function testItThrowsExceptionWhenTwoDifferentGridsReturnsSameHashDuringCheckForExport(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage(GridManager::SAME_GRID_HASH_EX_MSG); $sameHash = 'hashValue'; - $this->stubTwoGridsForExport($sameHash, null, $sameHash, null); + $this->stubTwoGridsForExport($sameHash, false, $sameHash, false); $this->gridManager->isReadyForExport(); } - public function testNoGridsReadyForExport() + public function testNoGridsReadyForExport(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -221,7 +216,7 @@ public function testNoGridsReadyForExport() $this->assertFalse($this->gridManager->isReadyForExport()); } - public function testAtLeastOneGridReadyForExport() + public function testAtLeastOneGridReadyForExport(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -231,7 +226,7 @@ public function testAtLeastOneGridReadyForExport() $this->assertTrue($this->gridManager->isReadyForExport()); } - public function testItRewindGridListWhenCheckingTwoTimesIfReadyForExport() + public function testItRewindGridListWhenCheckingTwoTimesIfReadyForExport(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -266,7 +261,7 @@ public function testItRewindGridListWhenCheckingTwoTimesIfReadyForExport() $this->gridManager->isReadyForExport(); } - public function testNoGridsHasMassActionRedirect() + public function testNoGridsHasMassActionRedirect(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -276,7 +271,7 @@ public function testNoGridsHasMassActionRedirect() $this->assertFalse($this->gridManager->isMassActionRedirect()); } - public function testAtLeastOneGridHasMassActionRedirect() + public function testAtLeastOneGridHasMassActionRedirect(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -286,7 +281,7 @@ public function testAtLeastOneGridHasMassActionRedirect() $this->assertTrue($this->gridManager->isMassActionRedirect()); } - public function testItRewindGridListWhenCheckingTwoTimesIfHasMassActionRedirect() + public function testItRewindGridListWhenCheckingTwoTimesIfHasMassActionRedirect(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -321,7 +316,7 @@ public function testItRewindGridListWhenCheckingTwoTimesIfHasMassActionRedirect( $this->gridManager->isMassActionRedirect(); } - public function testGridResponseRedirect() + public function testGridResponseRedirect(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -334,7 +329,7 @@ public function testGridResponseRedirect() $this->assertEquals($routeUrl, $this->gridManager->getGridManagerResponse()->getTargetUrl()); } - public function testGridResponseExport() + public function testGridResponseExport(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -349,7 +344,7 @@ public function testGridResponseExport() $this->assertEquals($response, $this->gridManager->getGridManagerResponse()); } - public function testGridResponseMassActionRedirect() + public function testGridResponseMassActionRedirect(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -364,7 +359,7 @@ public function testGridResponseMassActionRedirect() $this->assertEquals($response, $this->gridManager->getGridManagerResponse()); } - public function testGetGridResponseWithoutParams() + public function testGetGridResponseWithoutParams(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -374,7 +369,7 @@ public function testGetGridResponseWithoutParams() $this->assertEquals(['grid1' => $grid, 'grid2' => $grid2], $this->gridManager->getGridManagerResponse()); } - public function testGetGridResponseWithoutView() + public function testGetGridResponseWithoutView(): void { $grid1Hash = 'hashValue1'; $grid2Hash = 'hashValue2'; @@ -387,7 +382,7 @@ public function testGetGridResponseWithoutView() $this->assertEquals(['grid1' => $grid, 'grid2' => $grid2, $param1, $param2], $this->gridManager->getGridManagerResponse($params)); } - public function testGetGridWithViewWithoutParams() + public function testGetGridWithViewWithoutParams(): void { $grid1Hash = 'hashValue1'; @@ -415,7 +410,7 @@ public function testGetGridWithViewWithoutParams() $this->assertInstanceOf(Response::class, $this->gridManager->getGridManagerResponse($view)); } - public function testGetGridWithViewWithViewAndParams() + public function testGetGridWithViewWithViewAndParams(): void { $grid1Hash = 'hashValue1'; @@ -447,22 +442,14 @@ public function testGetGridWithViewWithViewAndParams() $this->assertInstanceOf(Response::class, $this->gridManager->getGridManagerResponse($view, $params)); } - /** - * @param string $grid1Hash - * @param string $route1Url - * @param bool $grid1ReadyForRedirect - * @param string $grid2Hash - * @param string $route2Url - * @param bool $grid2ReadyForRedirect - */ private function stubTwoGridsForRedirect( - $grid1Hash, - $route1Url, - $grid1ReadyForRedirect, - $grid2Hash, - $route2Url, - $grid2ReadyForRedirect - ) { + string $grid1Hash, + ?string $route1Url, + bool $grid1ReadyForRedirect, + string $grid2Hash, + ?string $route2Url, + bool $grid2ReadyForRedirect + ): void { [$grid, $grid2] = $this->stubTwoGrids($grid1Hash, $grid2Hash); $grid @@ -480,15 +467,7 @@ private function stubTwoGridsForRedirect( ->willReturn($route2Url); } - /** - * @param string $grid1Hash - * @param bool $grid1ReadyForExport - * @param string $grid2Hash - * @param bool $grid2ReadyForExport - * - * @return array - */ - private function stubTwoGridsForExport($grid1Hash, $grid1ReadyForExport, $grid2Hash, $grid2ReadyForExport) + private function stubTwoGridsForExport(string $grid1Hash, bool $grid1ReadyForExport, string $grid2Hash, bool $grid2ReadyForExport): array { [$grid, $grid2] = $this->stubTwoGrids($grid1Hash, $grid2Hash); @@ -503,15 +482,7 @@ private function stubTwoGridsForExport($grid1Hash, $grid1ReadyForExport, $grid2H return [$grid, $grid2]; } - /** - * @param string $grid1Hash - * @param bool $grid1IsMassActionRedirect - * @param string $grid2Hash - * @param bool $grid2IsMassActionRedirect - * - * @return array - */ - private function stubTwoGridForMassAction($grid1Hash, $grid1IsMassActionRedirect, $grid2Hash, $grid2IsMassActionRedirect) + private function stubTwoGridForMassAction(string $grid1Hash, bool $grid1IsMassActionRedirect, string $grid2Hash, bool $grid2IsMassActionRedirect): array { [$grid, $grid2] = $this->stubTwoGrids($grid1Hash, $grid2Hash); @@ -526,13 +497,7 @@ private function stubTwoGridForMassAction($grid1Hash, $grid1IsMassActionRedirect return [$grid, $grid2]; } - /** - * @param string $grid1Hash - * @param string $grid2Hash - * - * @return array - */ - private function stubTwoGrids($grid1Hash, $grid2Hash) + private function stubTwoGrids(string $grid1Hash, string $grid2Hash): array { $grid = $this->createMock(Grid::class); $grid diff --git a/tests/Grid/GridRegistryTest.php b/tests/Grid/GridRegistryTest.php index 72dad56..2ed93a1 100755 --- a/tests/Grid/GridRegistryTest.php +++ b/tests/Grid/GridRegistryTest.php @@ -9,6 +9,7 @@ use APY\DataGridBundle\Grid\Exception\TypeNotFoundException; use APY\DataGridBundle\Grid\GridRegistry; use APY\DataGridBundle\Grid\GridTypeInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -16,17 +17,14 @@ */ class GridRegistryTest extends TestCase { - /** - * @var GridRegistry - */ - private $registry; + private GridRegistry $registry; protected function setUp(): void { $this->registry = new GridRegistry(); } - public function testAddTypeAlreadyExists() + public function testAddTypeAlreadyExists(): void { $this->expectException(TypeAlreadyExistsException::class); @@ -35,26 +33,26 @@ public function testAddTypeAlreadyExists() $this->registry->addType($type); } - public function testAddType() + public function testAddType(): void { $this->assertFalse($this->registry->hasType('foo')); $this->registry->addType($this->createTypeMock()); $this->assertTrue($this->registry->hasType('foo')); } - public function testAddIsFluent() + public function testAddIsFluent(): void { $registry = $this->registry->addType($this->createTypeMock()); $this->assertSame($registry, $this->registry); } - public function testGetTypeUnknown() + public function testGetTypeUnknown(): void { $this->expectException(TypeNotFoundException::class); $this->registry->getType('foo'); } - public function testGetType() + public function testGetType(): void { $expectedType = $this->createTypeMock(); @@ -62,7 +60,7 @@ public function testGetType() $this->assertSame($expectedType, $this->registry->getType('foo')); } - public function testAddColumnAlreadyExists() + public function testAddColumnAlreadyExists(): void { $this->expectException(ColumnAlreadyExistsException::class); @@ -72,26 +70,26 @@ public function testAddColumnAlreadyExists() $this->registry->addColumn($type); } - public function testAddColumnType() + public function testAddColumnType(): void { $this->assertFalse($this->registry->hasColumn('type')); $this->registry->addColumn($this->createColumnTypeMock()); $this->assertTrue($this->registry->hasColumn('type')); } - public function testAddColumnTypeIsFluent() + public function testAddColumnTypeIsFluent(): void { $registry = $this->registry->addColumn($this->createColumnTypeMock()); $this->assertSame($registry, $this->registry); } - public function testGetColumnTypeUnknown() + public function testGetColumnTypeUnknown(): void { $this->expectException(ColumnNotFoundException::class); $this->registry->getColumn('type'); } - public function testGetColumnType() + public function testGetColumnType(): void { $expectedColumnType = $this->createColumnTypeMock(); @@ -99,7 +97,7 @@ public function testGetColumnType() $this->assertSame($expectedColumnType, $this->registry->getColumn('type')); } - protected function createTypeMock() + protected function createTypeMock(): MockObject { $mock = $this->createMock(GridTypeInterface::class); $mock->expects($this->any()) @@ -109,7 +107,7 @@ protected function createTypeMock() return $mock; } - protected function createColumnTypeMock() + protected function createColumnTypeMock(): MockObject { $mock = $this->createMock(Column::class); $mock->expects($this->any()) diff --git a/tests/Grid/GridTest.php b/tests/Grid/GridTest.php index e1ab3da..3dd0aaf 100644 --- a/tests/Grid/GridTest.php +++ b/tests/Grid/GridTest.php @@ -20,6 +20,7 @@ use APY\DataGridBundle\Grid\Source\Entity; use APY\DataGridBundle\Grid\Source\Source; use Doctrine\Persistence\ManagerRegistry; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\HeaderBag; use Symfony\Component\HttpFoundation\ParameterBag; @@ -39,72 +40,34 @@ class GridTest extends TestCase { - /** - * @var Grid - */ - private $grid; + private Grid $grid; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $router; + private MockObject $router; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $container; + private MockObject $authChecker; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $authChecker; - - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $registry; + private MockObject $registry; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $manager; + private MockObject $manager; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $request; + private MockObject $request; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $requestStack; + private MockObject $requestStack; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $session; + private MockObject $session; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $environment; + private MockObject $environment; - /** - * @var string - */ - private $gridId; + private ?string $gridId; - /** - * @var string - */ - private $gridHash; + private string $gridHash; public function setUp(): void { $this->arrange($this->createMock(GridConfigInterface::class)); } - public function testInitializeWithoutAnyConfiguration() + public function testInitializeWithoutAnyConfiguration(): void { $this->arrange(); @@ -125,7 +88,7 @@ public function testInitializeWithoutAnyConfiguration() $column->expects($this->never())->method($this->anything()); } - public function testInitializePersistence() + public function testInitializePersistence(): void { $gridConfig = $this->createMock(GridConfigInterface::class); $gridConfig @@ -139,7 +102,7 @@ public function testInitializePersistence() $this->assertTrue($this->grid->getPersistence()); } - public function testInitializeRouteParams() + public function testInitializeRouteParams(): void { $routeParams = ['foo' => 1, 'bar' => 2]; @@ -155,7 +118,7 @@ public function testInitializeRouteParams() $this->assertSame($routeParams, $this->grid->getRouteParameters()); } - public function testInitializeRouteUrlWithoutParams() + public function testInitializeRouteUrlWithoutParams(): void { $route = 'vendor.bundle.controller.route_name'; $routeParams = ['foo' => 1, 'bar' => 2]; @@ -182,7 +145,7 @@ public function testInitializeRouteUrlWithoutParams() $this->assertSame($url, $this->grid->getRouteUrl()); } - public function testInitializeRouteUrlWithParams() + public function testInitializeRouteUrlWithParams(): void { $route = 'vendor.bundle.controller.route_name'; $url = 'aRandomUrl'; @@ -204,7 +167,7 @@ public function testInitializeRouteUrlWithParams() $this->assertSame($url, $this->grid->getRouteUrl()); } - public function testInizializeColumnsNotFilterableAsGridIsNotFilterable() + public function testInizializeColumnsNotFilterableAsGridIsNotFilterable(): void { $gridConfig = $this->createMock(GridConfigInterface::class); $gridConfig @@ -224,7 +187,7 @@ public function testInizializeColumnsNotFilterableAsGridIsNotFilterable() $this->grid->initialize(); } - public function testInizializeColumnsNotSortableAsGridIsNotSortable() + public function testInizializeColumnsNotSortableAsGridIsNotSortable(): void { $gridConfig = $this->createMock(GridConfigInterface::class); $gridConfig @@ -244,7 +207,7 @@ public function testInizializeColumnsNotSortableAsGridIsNotSortable() $this->grid->initialize(); } - public function testInitializeNotEntitySource() + public function testInitializeNotEntitySource(): void { $source = $this->createMock(Source::class); @@ -263,7 +226,7 @@ public function testInitializeNotEntitySource() $this->grid->initialize(); } - public function testInitializeEntitySourceWithoutGroupByFunction() + public function testInitializeEntitySourceWithoutGroupByFunction(): void { $source = $this->createMock(Entity::class); @@ -285,7 +248,7 @@ public function testInitializeEntitySourceWithoutGroupByFunction() $this->grid->initialize(); } - public function testInitializeEntitySourceWithoutGroupByScalarValue() + public function testInitializeEntitySourceWithoutGroupByScalarValue(): void { $groupByField = 'groupBy'; @@ -313,7 +276,7 @@ public function testInitializeEntitySourceWithoutGroupByScalarValue() $this->grid->initialize(); } - public function testInitializeEntitySourceWithoutGroupByArrayValues() + public function testInitializeEntitySourceWithoutGroupByArrayValues(): void { $groupByArray = ['groupByFoo', 'groupByBar']; @@ -341,7 +304,7 @@ public function testInitializeEntitySourceWithoutGroupByArrayValues() $this->grid->initialize(); } - public function testInizializeDefaultOrder() + public function testInizializeDefaultOrder(): void { $sortBy = 'SORTBY'; $orderBy = 'ORDERBY'; @@ -361,7 +324,7 @@ public function testInizializeDefaultOrder() $this->assertSame(sprintf('%s|%s', $sortBy, strtolower($orderBy)), $this->grid->getDefaultOrder()); } - public function testInizializeDefaultOrderWithoutOrder() + public function testInizializeDefaultOrderWithoutOrder(): void { $sortBy = 'SORTBY'; @@ -378,7 +341,7 @@ public function testInizializeDefaultOrderWithoutOrder() $this->assertSame("$sortBy|", $this->grid->getDefaultOrder()); } - public function testInizializeLimits() + public function testInizializeLimits(): void { $maxPerPage = 10; @@ -394,7 +357,7 @@ public function testInizializeLimits() $this->assertSame([$maxPerPage => (string)$maxPerPage], $this->grid->getLimits()); } - public function testInizializeMaxResults() + public function testInizializeMaxResults(): void { $maxResults = 50; @@ -410,7 +373,7 @@ public function testInizializeMaxResults() $this->assertSame($maxResults, $this->grid->getMaxResults()); } - public function testInizializePage() + public function testInizializePage(): void { $page = 1; @@ -426,7 +389,7 @@ public function testInizializePage() $this->assertSame($page, $this->grid->getPage()); } - public function testSetSourceOneThanOneTime() + public function testSetSourceOneThanOneTime(): void { $source = $this->createMock(Source::class); @@ -438,7 +401,7 @@ public function testSetSourceOneThanOneTime() $this->grid->setSource($source); } - public function testSetSource() + public function testSetSource(): void { $source = $this->createMock(Source::class); @@ -456,7 +419,7 @@ public function testSetSource() $this->assertSame($source, $this->grid->getSource()); } - public function testGetSource() + public function testGetSource(): void { $source = $this->createMock(Source::class); @@ -465,12 +428,12 @@ public function testGetSource() $this->assertEquals($source, $this->grid->getSource()); } - public function testGetNullHashIfNotCreated() + public function testGetNullHashIfNotCreated(): void { $this->assertNull($this->grid->getHash()); } - public function testHandleRequestRaiseExceptionIfSourceNotSetted() + public function testHandleRequestRaiseExceptionIfSourceNotSetted(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage(Grid::SOURCE_NOT_SETTED_EX_MSG); @@ -482,7 +445,7 @@ public function testHandleRequestRaiseExceptionIfSourceNotSetted() ); } - public function testAddColumnToLazyColumnsWithoutPosition() + public function testAddColumnToLazyColumnsWithoutPosition(): void { $column = $this->stubColumn(); $this->grid->addColumn($column); @@ -490,7 +453,7 @@ public function testAddColumnToLazyColumnsWithoutPosition() $this->assertSame([['column' => $column, 'position' => 0]], $this->grid->getLazyAddColumn()); } - public function testAddColumnToLazyColumnsWithPosition() + public function testAddColumnToLazyColumnsWithPosition(): void { $column = $this->stubColumn(); $this->grid->addColumn($column, 1); @@ -498,7 +461,7 @@ public function testAddColumnToLazyColumnsWithPosition() $this->assertSame([['column' => $column, 'position' => 1]], $this->grid->getLazyAddColumn()); } - public function testAddColumnsToLazyColumnsWithSamePosition() + public function testAddColumnsToLazyColumnsWithSamePosition(): void { $column1 = $this->stubColumn(); $column2 = $this->stubColumn(); @@ -515,7 +478,7 @@ public function testAddColumnsToLazyColumnsWithSamePosition() ); } - public function testGetColumnFromLazyColumns() + public function testGetColumnFromLazyColumns(): void { $columnId = 'foo'; $column = $this->stubColumn($columnId); @@ -525,7 +488,7 @@ public function testGetColumnFromLazyColumns() $this->assertEquals($column, $this->grid->getColumn($columnId)); } - public function testGetColumnFromColumns() + public function testGetColumnFromColumns(): void { $columnId = 'foo'; $column = $this->stubColumn(); @@ -541,7 +504,7 @@ public function testGetColumnFromColumns() $this->assertEquals($column, $this->grid->getColumn($columnId)); } - public function testRaiseExceptionIfGetNonExistentColumn() + public function testRaiseExceptionIfGetNonExistentColumn(): void { $columnId = 'foo'; @@ -551,12 +514,12 @@ public function testRaiseExceptionIfGetNonExistentColumn() $this->grid->getColumn($columnId); } - public function testGetColumns() + public function testGetColumns(): void { $this->assertInstanceOf(Columns::class, $this->grid->getColumns()); } - public function testHasColumnInLazyColumns() + public function testHasColumnInLazyColumns(): void { $columnId = 'foo'; $column = $this->stubColumn($columnId); @@ -565,7 +528,7 @@ public function testHasColumnInLazyColumns() $this->assertTrue($this->grid->hasColumn($columnId)); } - public function testHasColumnInColumns() + public function testHasColumnInColumns(): void { $columnId = 'foo'; @@ -580,7 +543,7 @@ public function testHasColumnInColumns() $this->assertTrue($this->grid->hasColumn($columnId)); } - public function testSetColumns() + public function testSetColumns(): void { $columns = $this->createMock(Columns::class); $this->grid->setColumns($columns); @@ -588,7 +551,7 @@ public function testSetColumns() $this->assertSame($columns, $this->grid->getColumns()); } - public function testColumnsReorderAndKeepOtherColumns() + public function testColumnsReorderAndKeepOtherColumns(): void { $ids = ['col1', 'col3', 'col2']; @@ -603,7 +566,7 @@ public function testColumnsReorderAndKeepOtherColumns() $this->grid->setColumnsOrder($ids, true); } - public function testColumnsReorderAndDontKeepOtherColumns() + public function testColumnsReorderAndDontKeepOtherColumns(): void { $ids = ['col1', 'col3', 'col2']; @@ -618,7 +581,7 @@ public function testColumnsReorderAndDontKeepOtherColumns() $this->grid->setColumnsOrder($ids, false); } - public function testAddMassActionWithoutRole() + public function testAddMassActionWithoutRole(): void { $massAction = $this->stubMassAction(); $this->grid->addMassAction($massAction); @@ -626,7 +589,7 @@ public function testAddMassActionWithoutRole() $this->assertSame([$massAction], $this->grid->getMassActions()); } - public function testAddMassActionWithGrantForActionRole() + public function testAddMassActionWithGrantForActionRole(): void { $role = 'aRole'; $massAction = $this->stubMassAction($role); @@ -642,7 +605,7 @@ public function testAddMassActionWithGrantForActionRole() $this->assertSame([$massAction], $this->grid->getMassActions()); } - public function testAddMassActionWithoutGrantForActionRole() + public function testAddMassActionWithoutGrantForActionRole(): void { $role = 'aRole'; $massAction = $this->stubMassAction($role); @@ -658,7 +621,7 @@ public function testAddMassActionWithoutGrantForActionRole() $this->assertEmpty($this->grid->getMassActions()); } - public function testGetMassActions() + public function testGetMassActions(): void { $massAction = $this->stubMassAction(); $this->grid->addMassAction($massAction); @@ -666,7 +629,7 @@ public function testGetMassActions() $this->assertEquals([$massAction], $this->grid->getMassActions()); } - public function testRaiseExceptionIfAddTweakWithNotValidId() + public function testRaiseExceptionIfAddTweakWithNotValidId(): void { $tweakId = '#tweakNotValidId'; @@ -676,7 +639,7 @@ public function testRaiseExceptionIfAddTweakWithNotValidId() $this->grid->addTweak('title', [], $tweakId); } - public function testAddTweakWithId() + public function testAddTweakWithId(): void { $title = 'aTweak'; $tweak = ['filters' => [], 'order' => 'columnId', 'page' => 1, 'limit' => 50, 'export' => 1, 'massAction' => 1]; @@ -690,7 +653,7 @@ public function testAddTweakWithId() $this->assertEquals($result, $this->grid->getAllTweaks()); } - public function testAddTweakWithoutId() + public function testAddTweakWithoutId(): void { $title = 'aTweak'; $tweak = ['filters' => [], 'order' => 'columnId', 'page' => 1, 'limit' => 50, 'export' => 1, 'massAction' => 1]; @@ -703,7 +666,7 @@ public function testAddTweakWithoutId() $this->assertEquals($result, $this->grid->getAllTweaks()); } - public function testAddRowActionWithoutRole() + public function testAddRowActionWithoutRole(): void { $colId = 'aColId'; $rowAction = $this->stubRowAction(null, $colId); @@ -712,7 +675,7 @@ public function testAddRowActionWithoutRole() $this->assertSame([$colId => [$rowAction]], $this->grid->getRowActions()); } - public function testAddRowActionWithGrantForActionRole() + public function testAddRowActionWithGrantForActionRole(): void { $role = 'aRole'; $colId = 'aColId'; @@ -729,7 +692,7 @@ public function testAddRowActionWithGrantForActionRole() $this->assertSame([$colId => [$rowAction]], $this->grid->getRowActions()); } - public function testAddRowActionWithoutGrantForActionRole() + public function testAddRowActionWithoutGrantForActionRole(): void { $role = 'aRole'; $rowAction = $this->stubRowAction($role); @@ -745,7 +708,7 @@ public function testAddRowActionWithoutGrantForActionRole() $this->assertEmpty($this->grid->getRowActions()); } - public function testGetRowActions() + public function testGetRowActions(): void { $colId = 'aColId'; $rowAction = $this->stubRowAction(null, $colId); @@ -754,7 +717,7 @@ public function testGetRowActions() $this->assertEquals([$colId => [$rowAction]], $this->grid->getRowActions()); } - public function testSetExportTwigTemplateInstance() + public function testSetExportTwigTemplateInstance(): void { $templateName = 'templateName'; @@ -777,7 +740,7 @@ public function testSetExportTwigTemplateInstance() $this->grid->setTemplate($template); } - public function testSetExportStringTemplate() + public function testSetExportStringTemplate(): void { $template = 'templateString'; @@ -793,7 +756,7 @@ public function testSetExportStringTemplate() $this->grid->setTemplate($template); } - public function testRaiseExceptionIfSetTemplateWithNoValidValue() + public function testRaiseExceptionIfSetTemplateWithNoValidValue(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage(Grid::TWIG_TEMPLATE_LOAD_EX_MSG); @@ -807,7 +770,7 @@ public function testRaiseExceptionIfSetTemplateWithNoValidValue() $this->grid->setTemplate(true); } - public function testSetExportNullTemplate() + public function testSetExportNullTemplate(): void { $this ->session @@ -818,7 +781,7 @@ public function testSetExportNullTemplate() $this->grid->setTemplate(null); } - public function testReturnTwigTemplate() + public function testReturnTwigTemplate(): void { $templateName = 'templateName'; @@ -837,7 +800,7 @@ public function testReturnTwigTemplate() $this->assertEquals($result, $this->grid->getTemplate()); } - public function testReturnStringTemplate() + public function testReturnStringTemplate(): void { $template = 'templateString'; @@ -846,7 +809,7 @@ public function testReturnStringTemplate() $this->assertEquals($template, $this->grid->getTemplate()); } - public function testAddExportWithoutRole() + public function testAddExportWithoutRole(): void { $export = $this->createMock(ExportInterface::class); $export @@ -858,7 +821,7 @@ public function testAddExportWithoutRole() $this->assertSame([$export], $this->grid->getExports()); } - public function testAddExportWithGrantForActionRole() + public function testAddExportWithGrantForActionRole(): void { $role = 'aRole'; @@ -878,7 +841,7 @@ public function testAddExportWithGrantForActionRole() $this->assertSame([$export], $this->grid->getExports()); } - public function testAddExportWithoutGrantForActionRole() + public function testAddExportWithoutGrantForActionRole(): void { $role = 'aRole'; @@ -898,7 +861,7 @@ public function testAddExportWithoutGrantForActionRole() $this->assertEmpty($this->grid->getExports()); } - public function testGetExports() + public function testGetExports(): void { $export = $this->createMock(ExportInterface::class); $export @@ -910,7 +873,7 @@ public function testGetExports() $this->assertEquals([$export], $this->grid->getExports()); } - public function testSetRouteParameter() + public function testSetRouteParameter(): void { $paramName = 'name'; $paramValue = 'value'; @@ -927,7 +890,7 @@ public function testSetRouteParameter() ); } - public function testGetRouteParameters() + public function testGetRouteParameters(): void { $paramName = 'name'; $paramValue = 'value'; @@ -944,7 +907,7 @@ public function testGetRouteParameters() ); } - public function testSetRouteUrl() + public function testSetRouteUrl(): void { $url = 'url'; @@ -953,7 +916,7 @@ public function testSetRouteUrl() $this->assertSame($url, $this->grid->getRouteUrl()); } - public function testGetRouteUrl() + public function testGetRouteUrl(): void { $url = 'url'; @@ -962,7 +925,7 @@ public function testGetRouteUrl() $this->assertEquals($url, $this->grid->getRouteUrl()); } - public function testGetRouteUrlFromRequest() + public function testGetRouteUrlFromRequest(): void { $url = 'url'; @@ -981,7 +944,7 @@ public function testGetRouteUrlFromRequest() $this->assertEquals($url, $this->grid->getRouteUrl()); } - public function testGetId() + public function testGetId(): void { $id = 'id'; $this->grid->setId($id); @@ -989,21 +952,21 @@ public function testGetId() $this->assertEquals($id, $this->grid->getId()); } - public function testGetPersistence() + public function testGetPersistence(): void { $this->grid->setPersistence(true); $this->assertTrue($this->grid->getPersistence()); } - public function testGetDataJunction() + public function testGetDataJunction(): void { $this->grid->setDataJunction(Column::DATA_DISJUNCTION); $this->assertEquals(Column::DATA_DISJUNCTION, $this->grid->getDataJunction()); } - public function testSetInvalidLimitsRaiseException() + public function testSetInvalidLimitsRaiseException(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage(Grid::NOT_VALID_LIMIT_EX_MSG); @@ -1011,7 +974,7 @@ public function testSetInvalidLimitsRaiseException() $this->grid->setLimits('foo'); } - public function testSetIntLimit() + public function testSetIntLimit(): void { $limit = 10; $this->grid->setLimits($limit); @@ -1019,7 +982,7 @@ public function testSetIntLimit() $this->assertSame([$limit => (string)$limit], $this->grid->getLimits()); } - public function testSetArrayLimits() + public function testSetArrayLimits(): void { $limits = [10, 50, 100]; $this->grid->setLimits($limits); @@ -1027,7 +990,7 @@ public function testSetArrayLimits() $this->assertSame(array_combine($limits, $limits), $this->grid->getLimits()); } - public function testSetAssociativeArrayLimits() + public function testSetAssociativeArrayLimits(): void { $limits = [10 => '10', 50 => '50', 100 => '100']; $this->grid->setLimits($limits); @@ -1035,7 +998,7 @@ public function testSetAssociativeArrayLimits() $this->assertSame(array_combine($limits, $limits), $this->grid->getLimits()); } - public function testGetLimits() + public function testGetLimits(): void { $limits = [10, 50, 100]; $this->grid->setLimits($limits); @@ -1043,7 +1006,7 @@ public function testGetLimits() $this->assertEquals(array_combine($limits, $limits), $this->grid->getLimits()); } - public function testSetDefaultPage() + public function testSetDefaultPage(): void { $page = 1; $this->grid->setDefaultPage($page); @@ -1051,7 +1014,7 @@ public function testSetDefaultPage() $this->assertSame($page - 1, $this->grid->getPage()); } - public function testSetDefaultTweak() + public function testSetDefaultTweak(): void { $tweakId = 1; $this->grid->setDefaultTweak($tweakId); @@ -1059,7 +1022,7 @@ public function testSetDefaultTweak() $this->assertEquals($tweakId, $this->grid->getDefaultTweak()); } - public function testSetPageWithInvalidValueRaiseException() + public function testSetPageWithInvalidValueRaiseException(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage(Grid::NOT_VALID_PAGE_NUMBER_EX_MSG); @@ -1068,7 +1031,7 @@ public function testSetPageWithInvalidValueRaiseException() $this->grid->setPage($page); } - public function testSetPageWithZeroValue() + public function testSetPageWithZeroValue(): void { $page = 0; $this->grid->setPage($page); @@ -1076,7 +1039,7 @@ public function testSetPageWithZeroValue() $this->assertSame($page, $this->grid->getPage()); } - public function testGetPage() + public function testGetPage(): void { $page = 10; $this->grid->setPage($page); @@ -1084,13 +1047,13 @@ public function testGetPage() $this->assertEquals($page, $this->grid->getPage()); } - public function testSetMaxResultWithNullValue() + public function testSetMaxResultWithNullValue(): void { $this->grid->setMaxResults(); $this->assertNull($this->grid->getMaxResults()); } - public function testSetMaxResultWithInvalidValueRaiseException() + public function testSetMaxResultWithInvalidValueRaiseException(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage(Grid::NOT_VALID_MAX_RESULT_EX_MSG); @@ -1098,7 +1061,7 @@ public function testSetMaxResultWithInvalidValueRaiseException() $this->grid->setMaxResults(-1); } - public function testSetMaxResult() + public function testSetMaxResult(): void { $maxResult = 1; $this->grid->setMaxResults($maxResult); @@ -1106,7 +1069,7 @@ public function testSetMaxResult() $this->assertSame($maxResult, $this->grid->getMaxResults()); } - public function testIsNotFilteredIfNoColumnIsFiltered() + public function testIsNotFilteredIfNoColumnIsFiltered(): void { $column1 = $this->stubColumn(); $column2 = $this->stubColumn(); @@ -1120,7 +1083,7 @@ public function testIsNotFilteredIfNoColumnIsFiltered() $this->assertFalse($this->grid->isFiltered()); } - public function testIsFilteredIfAtLeastAColumnIsFiltered() + public function testIsFilteredIfAtLeastAColumnIsFiltered(): void { $column1 = $this->stubColumn(); $column2 = $this->stubFilteredColumn(); @@ -1134,7 +1097,7 @@ public function testIsFilteredIfAtLeastAColumnIsFiltered() $this->assertTrue($this->grid->isFiltered()); } - public function testShowTitlesIfAtLeastOneColumnHasATitle() + public function testShowTitlesIfAtLeastOneColumnHasATitle(): void { $column1 = $this->stubColumn(); $column2 = $this->stubTitledColumn(); @@ -1148,7 +1111,7 @@ public function testShowTitlesIfAtLeastOneColumnHasATitle() $this->assertTrue($this->grid->isTitleSectionVisible()); } - public function testDontShowTitlesIfNoColumnsHasATitle() + public function testDontShowTitlesIfNoColumnsHasATitle(): void { $column1 = $this->stubColumn(); $column2 = $this->stubColumn(); @@ -1162,7 +1125,7 @@ public function testDontShowTitlesIfNoColumnsHasATitle() $this->assertFalse($this->grid->isTitleSectionVisible()); } - public function testDontShowTitles() + public function testDontShowTitles(): void { $column = $this->stubTitledColumn(); @@ -1175,7 +1138,7 @@ public function testDontShowTitles() $this->assertFalse($this->grid->isTitleSectionVisible()); } - public function testShowFilterSectionIfAtLeastOneColumnFilterable() + public function testShowFilterSectionIfAtLeastOneColumnFilterable(): void { $column1 = $this->stubColumn(); $column2 = $this->stubFilterableColumn('text'); @@ -1189,7 +1152,7 @@ public function testShowFilterSectionIfAtLeastOneColumnFilterable() $this->assertTrue($this->grid->isFilterSectionVisible()); } - public function testDontShowFilterSectionIfColumnVisibleTypeIsMassAction() + public function testDontShowFilterSectionIfColumnVisibleTypeIsMassAction(): void { $column = $this->stubFilterableColumn('massaction'); @@ -1201,7 +1164,7 @@ public function testDontShowFilterSectionIfColumnVisibleTypeIsMassAction() $this->assertFalse($this->grid->isFilterSectionVisible()); } - public function testDontShowFilterSectionIfColumnVisibleTypeIsActions() + public function testDontShowFilterSectionIfColumnVisibleTypeIsActions(): void { $column = $this->stubFilterableColumn('actions'); @@ -1213,7 +1176,7 @@ public function testDontShowFilterSectionIfColumnVisibleTypeIsActions() $this->assertFalse($this->grid->isFilterSectionVisible()); } - public function testDontShowFilterSectionIfNoColumnFilterable() + public function testDontShowFilterSectionIfNoColumnFilterable(): void { $column1 = $this->stubColumn(); $column2 = $this->stubColumn(); @@ -1227,28 +1190,28 @@ public function testDontShowFilterSectionIfNoColumnFilterable() $this->assertFalse($this->grid->isFilterSectionVisible()); } - public function testDontShowFilterSection() + public function testDontShowFilterSection(): void { $this->grid->hideFilters(); $this->assertFalse($this->grid->isFilterSectionVisible()); } - public function testHideFilters() + public function testHideFilters(): void { $this->grid->hideFilters(); $this->assertFalse($this->grid->getShowFilters()); } - public function testHideTitles() + public function testHideTitles(): void { $this->grid->hideTitles(); $this->assertFalse($this->grid->getShowTitles()); } - public function testAddsColumnExtension() + public function testAddsColumnExtension(): void { $extension = $this->stubColumn(); @@ -1266,7 +1229,7 @@ public function testAddsColumnExtension() $this->grid->addColumnExtension($extension); } - public function testGetPrefixTitle() + public function testGetPrefixTitle(): void { $prefixTitle = 'prefixTitle'; $this->grid->setPrefixTitle($prefixTitle); @@ -1274,7 +1237,7 @@ public function testGetPrefixTitle() $this->assertEquals($prefixTitle, $this->grid->getPrefixTitle()); } - public function testGetNoDataMessage() + public function testGetNoDataMessage(): void { $message = 'foo'; $this->grid->setNoDataMessage($message); @@ -1282,7 +1245,7 @@ public function testGetNoDataMessage() $this->assertEquals($message, $this->grid->getNoDataMessage()); } - public function testGetNoResultMessage() + public function testGetNoResultMessage(): void { $message = 'foo'; $this->grid->setNoResultMessage($message); @@ -1290,7 +1253,7 @@ public function testGetNoResultMessage() $this->assertEquals($message, $this->grid->getNoResultMessage()); } - public function testSetHiddenColumnsWithIntegerId() + public function testSetHiddenColumnsWithIntegerId(): void { $id = 1; $this->grid->setHiddenColumns([$id]); @@ -1298,7 +1261,7 @@ public function testSetHiddenColumnsWithIntegerId() $this->assertSame([$id], $this->grid->getHiddenColumns()); } - public function testSetHiddenColumnWithArrayOfIds() + public function testSetHiddenColumnWithArrayOfIds(): void { $ids = [1, 2, 3]; $this->grid->setHiddenColumns($ids); @@ -1306,7 +1269,7 @@ public function testSetHiddenColumnWithArrayOfIds() $this->assertSame($ids, $this->grid->getHiddenColumns()); } - public function testSetVisibleColumnsWithIntegerId() + public function testSetVisibleColumnsWithIntegerId(): void { $id = 1; $this->grid->setVisibleColumns($id); @@ -1314,7 +1277,7 @@ public function testSetVisibleColumnsWithIntegerId() $this->assertSame([$id], $this->grid->getVisibleColumns()); } - public function testSetVisibleColumnWithArrayOfIds() + public function testSetVisibleColumnWithArrayOfIds(): void { $ids = [1, 2, 3]; $this->grid->setVisibleColumns($ids); @@ -1322,7 +1285,7 @@ public function testSetVisibleColumnWithArrayOfIds() $this->assertSame($ids, $this->grid->getVisibleColumns()); } - public function testShowColumnsWithIntegerId() + public function testShowColumnsWithIntegerId(): void { $id = 1; $this->grid->showColumns($id); @@ -1330,7 +1293,7 @@ public function testShowColumnsWithIntegerId() $this->assertSame([$id => true], $this->grid->getLazyHideShowColumns()); } - public function testShowColumnsArrayOfIds() + public function testShowColumnsArrayOfIds(): void { $ids = [1, 2, 3]; $this->grid->showColumns($ids); @@ -1338,7 +1301,7 @@ public function testShowColumnsArrayOfIds() $this->assertSame([1 => true, 2 => true, 3 => true], $this->grid->getLazyHideShowColumns()); } - public function testHideColumnsWithIntegerId() + public function testHideColumnsWithIntegerId(): void { $id = 1; $this->grid->hideColumns($id); @@ -1346,7 +1309,7 @@ public function testHideColumnsWithIntegerId() $this->assertSame([$id => false], $this->grid->getLazyHideShowColumns()); } - public function testHideColumnsArrayOfIds() + public function testHideColumnsArrayOfIds(): void { $ids = [1, 2, 3]; $this->grid->hideColumns($ids); @@ -1354,7 +1317,7 @@ public function testHideColumnsArrayOfIds() $this->assertSame([1 => false, 2 => false, 3 => false], $this->grid->getLazyHideShowColumns()); } - public function testSetActionsColumnSize() + public function testSetActionsColumnSize(): void { $size = 2; $this->grid->setActionsColumnSize($size); @@ -1362,7 +1325,7 @@ public function testSetActionsColumnSize() $this->assertSame($size, $this->grid->getActionsColumnSize()); } - public function testSetActionsColumnTitle() + public function testSetActionsColumnTitle(): void { $title = 'aTitle'; $this->grid->setActionsColumnTitle($title); @@ -1370,7 +1333,7 @@ public function testSetActionsColumnTitle() $this->assertSame($title, $this->grid->getActionsColumnTitle()); } - public function testClone() + public function testClone(): void { $column1 = $this->stubColumn(); $column2 = $this->stubColumn(); @@ -1385,7 +1348,7 @@ public function testClone() $this->assertNotSame($columns, $grid->getColumns()); } - public function testRaiseExceptionDuringHandleRequestIfNoSourceSetted() + public function testRaiseExceptionDuringHandleRequestIfNoSourceSetted(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage(Grid::SOURCE_NOT_SETTED_EX_MSG); @@ -1398,7 +1361,7 @@ public function testRaiseExceptionDuringHandleRequestIfNoSourceSetted() $this->grid->handleRequest($request); } - public function testCreateHashWithIdDuringHandleRequest() + public function testCreateHashWithIdDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -1408,7 +1371,7 @@ public function testCreateHashWithIdDuringHandleRequest() $this->assertEquals($this->gridHash, $this->grid->getHash()); } - public function testCreateHashWithMd5DuringHandleRequest() + public function testCreateHashWithMd5DuringHandleRequest(): void { $this->arrange($this->createMock(GridConfigInterface::class), null); @@ -1435,7 +1398,7 @@ public function testCreateHashWithMd5DuringHandleRequest() $this->assertSame('grid_' . md5($controller . $columns->getHash() . $sourceHash), $this->grid->getHash()); } - public function testResetGridSessionWhenChangeGridDuringHandleRequest() + public function testResetGridSessionWhenChangeGridDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -1456,14 +1419,14 @@ public function testResetGridSessionWhenChangeGridDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testResetGridSessionWhenResetFiltersIsPressedDuringHandleRequest() + public function testResetGridSessionWhenResetFiltersIsPressedDuringHandleRequest(): void { $this->mockResetGridSessionWhenResetFilterIsPressed(); $this->grid->handleRequest($this->request); } - public function testNotResetGridSessionWhenXmlHttpRequestDuringHandleRequest() + public function testNotResetGridSessionWhenXmlHttpRequestDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -1482,7 +1445,7 @@ public function testNotResetGridSessionWhenXmlHttpRequestDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testNotResetGridSessionWhenPersistenceSettedDuringHandleRequest() + public function testNotResetGridSessionWhenPersistenceSettedDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -1503,14 +1466,14 @@ public function testNotResetGridSessionWhenPersistenceSettedDuringHandleRequest( $this->grid->handleRequest($this->request); } - public function testNotResetGridSessionWhenRefererIsSameGridDuringHandleRequest() + public function testNotResetGridSessionWhenRefererIsSameGridDuringHandleRequest(): void { $this->mockNotResetGridSessionWhenSameGridReferer(); $this->grid->handleRequest($this->request); } - public function testStartNewSessionDuringHandleRequestOnFirstGridRequest() + public function testStartNewSessionDuringHandleRequestOnFirstGridRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -1520,7 +1483,7 @@ public function testStartNewSessionDuringHandleRequestOnFirstGridRequest() $this->assertTrue(true, $this->grid->getNewSession()); } - public function testStartKeepSessionDuringHandleRequestNotOnFirstGridRequest() + public function testStartKeepSessionDuringHandleRequestNotOnFirstGridRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -1536,7 +1499,7 @@ public function testStartKeepSessionDuringHandleRequestNotOnFirstGridRequest() $this->assertFalse($this->grid->getNewSession()); } - public function testMassActionRedirect() + public function testMassActionRedirect(): void { $this->mockMassActionCallbackResponse(); @@ -1545,7 +1508,7 @@ public function testMassActionRedirect() $this->assertTrue($this->grid->isMassActionRedirect()); } - public function testRaiseExceptionIfMassActionIdNotValidDuringHandleRequest() + public function testRaiseExceptionIfMassActionIdNotValidDuringHandleRequest(): void { $massActionId = 10; @@ -1560,7 +1523,7 @@ public function testRaiseExceptionIfMassActionIdNotValidDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testRaiseExceptionIfMassActionCallbackNotValidDuringHandleRequest() + public function testRaiseExceptionIfMassActionCallbackNotValidDuringHandleRequest(): void { $invalidCallback = 'invalidCallback'; @@ -1579,7 +1542,7 @@ public function testRaiseExceptionIfMassActionCallbackNotValidDuringHandleReques $this->grid->handleRequest($this->request); } - public function testResetPageAndLimitIfMassActionHandleAllDataDuringHandleRequest() + public function testResetPageAndLimitIfMassActionHandleAllDataDuringHandleRequest(): void { $this->mockResetPageAndLimitIfMassActionAndAllKeys(); @@ -1588,7 +1551,7 @@ public function testResetPageAndLimitIfMassActionHandleAllDataDuringHandleReques $this->assertEquals(0, $this->grid->getLimit()); } - public function testMassActionResponseFromCallbackDuringHandleRequest() + public function testMassActionResponseFromCallbackDuringHandleRequest(): void { $callbackResponse = $this->mockMassActionCallbackResponse(); @@ -1597,7 +1560,7 @@ public function testMassActionResponseFromCallbackDuringHandleRequest() $this->assertEquals($callbackResponse, $this->grid->getMassActionResponse()); } - public function testMassActionResponseFromControllerActionDuringHandleRequest() + public function testMassActionResponseFromControllerActionDuringHandleRequest(): void { $callbackResponse = $this->mockMassActionControllerResponse(); @@ -1606,7 +1569,7 @@ public function testMassActionResponseFromControllerActionDuringHandleRequest() $this->assertEquals($callbackResponse, $this->grid->getMassActionResponse()); } - public function testRaiseExceptionIfExportIdNotValidDuringHandleRequest() + public function testRaiseExceptionIfExportIdNotValidDuringHandleRequest(): void { $exportId = 10; @@ -1621,7 +1584,7 @@ public function testRaiseExceptionIfExportIdNotValidDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testProcessExportsDuringHandleRequest() + public function testProcessExportsDuringHandleRequest(): void { $response = $this->mockExports(); @@ -1633,63 +1596,63 @@ public function testProcessExportsDuringHandleRequest() $this->assertEquals($response, $this->grid->getExportResponse()); } - public function testProcessExportsButNotFiltersPageOrderLimitDuringHandleRequest() + public function testProcessExportsButNotFiltersPageOrderLimitDuringHandleRequest(): void { $this->mockExportsButNotFiltersPageOrderLimit(); $this->grid->handleRequest($this->request); } - public function testProcessPageDuringHandleRequest() + public function testProcessPageDuringHandleRequest(): void { $this->mockPageRequestData(); $this->grid->handleRequest($this->request); } - public function testProcessPageWithQueryOrderingDuringHandleRequest() + public function testProcessPageWithQueryOrderingDuringHandleRequest(): void { $this->mockPageQueryOrderRequestData(); $this->grid->handleRequest($this->request); } - public function testProcessPageWithQueryLimitDuringHandleRequest() + public function testProcessPageWithQueryLimitDuringHandleRequest(): void { $this->mockPageLimitRequestData(); $this->grid->handleRequest($this->request); } - public function testProcessPageWithMassActionDuringHandleRequest() + public function testProcessPageWithMassActionDuringHandleRequest(): void { $this->mockPageMassActionRequestData(); $this->grid->handleRequest($this->request); } - public function testProcessPageWithFiltersAndRequestDataDuringHandleRequest() + public function testProcessPageWithFiltersAndRequestDataDuringHandleRequest(): void { $this->mockPageFiltersRequestData(); $this->grid->handleRequest($this->request); } - public function testProcessPageWithFiltersDifferentFromSelectDuringHandleRequest() + public function testProcessPageWithFiltersDifferentFromSelectDuringHandleRequest(): void { $this->mockPageNotSelectFilterRequestData(); $this->grid->handleRequest($this->request); } - public function testProcessPageWithSelectFilterColumnNotSelectMultiDuringHandleRequest() + public function testProcessPageWithSelectFilterColumnNotSelectMultiDuringHandleRequest(): void { $this->mockPageColumnNotSelectMultiRequestData(); $this->grid->handleRequest($this->request); } - public function testProcessOrderDescDuringHandleRequest() + public function testProcessOrderDescDuringHandleRequest(): void { $colId = 'colId'; $order = 'desc'; @@ -1711,7 +1674,7 @@ public function testProcessOrderDescDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testProcessOrderAscDuringHandleRequest() + public function testProcessOrderAscDuringHandleRequest(): void { $colId = 'colId'; $order = 'asc'; @@ -1733,14 +1696,14 @@ public function testProcessOrderAscDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testProcessOrderColumnNotSortableDuringHandleRequest() + public function testProcessOrderColumnNotSortableDuringHandleRequest(): void { $this->mockOrderColumnNotSortable(); $this->grid->handleRequest($this->request); } - public function testColumnsNotOrderedDuringHandleRequestIfNoOrderRequested() + public function testColumnsNotOrderedDuringHandleRequestIfNoOrderRequested(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -1764,14 +1727,14 @@ public function testColumnsNotOrderedDuringHandleRequestIfNoOrderRequested() $this->assertSame(0, $this->grid->getPage()); } - public function testProcessConfiguredLimitDuringHandleRequest() + public function testProcessConfiguredLimitDuringHandleRequest(): void { $this->mockConfiguredLimitRequestData(); $this->grid->handleRequest($this->request); } - public function testProcessNonConfiguredLimitDuringHandleRequest() + public function testProcessNonConfiguredLimitDuringHandleRequest(): void { $this->mockNonConfiguredLimitRequestData(); @@ -1780,14 +1743,14 @@ public function testProcessNonConfiguredLimitDuringHandleRequest() $this->assertEmpty($this->grid->getLimit()); } - public function testSetDefaultSessionFiltersDuringHandleRequest() + public function testSetDefaultSessionFiltersDuringHandleRequest(): void { $this->mockDefaultSessionFiltersWithoutRequestData(); $this->grid->handleRequest($this->request); } - public function testSetDefaultPageRaiseExceptionIfPageHasNegativeValueDuringHandleRequest() + public function testSetDefaultPageRaiseExceptionIfPageHasNegativeValueDuringHandleRequest(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage(Grid::PAGE_NOT_VALID_EX_MSG); @@ -1800,14 +1763,14 @@ public function testSetDefaultPageRaiseExceptionIfPageHasNegativeValueDuringHand $this->grid->handleRequest($this->request); } - public function testSetDefaultPageDuringHandleRequest() + public function testSetDefaultPageDuringHandleRequest(): void { $this->mockDefaultPage(); $this->grid->handleRequest($this->request); } - public function testSetDefaultOrderRaiseExceptionIfOrderNotAscNeitherDescDuringHandleRequest() + public function testSetDefaultOrderRaiseExceptionIfOrderNotAscNeitherDescDuringHandleRequest(): void { $columnOrder = 'foo'; @@ -1826,7 +1789,7 @@ public function testSetDefaultOrderRaiseExceptionIfOrderNotAscNeitherDescDuringH $this->grid->handleRequest($this->request); } - public function testSetDefaultOrderRaiseExceptionIfColumnDoesNotExistsDuringHandleRequest() + public function testSetDefaultOrderRaiseExceptionIfColumnDoesNotExistsDuringHandleRequest(): void { $colId = 'col'; @@ -1843,14 +1806,14 @@ public function testSetDefaultOrderRaiseExceptionIfColumnDoesNotExistsDuringHand $this->grid->handleRequest($this->request); } - public function testSetDefaultOrderAscDuringHandleRequest() + public function testSetDefaultOrderAscDuringHandleRequest(): void { $this->mockDefaultOrder('asc'); $this->grid->handleRequest($this->request); } - public function testSetDefaultOrderDescDuringHandleRequest() + public function testSetDefaultOrderDescDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -1878,7 +1841,7 @@ public function testSetDefaultOrderDescDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testSetDefaultLimitRaiseExceptionIfLimitIsNotAPositiveDuringHandleRequest() + public function testSetDefaultLimitRaiseExceptionIfLimitIsNotAPositiveDuringHandleRequest(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage(Grid::DEFAULT_LIMIT_NOT_VALID_EX_MSG); @@ -1891,7 +1854,7 @@ public function testSetDefaultLimitRaiseExceptionIfLimitIsNotAPositiveDuringHand $this->grid->handleRequest($this->request); } - public function testSetDefaultLimitRaiseExceptionIfLimitIsNotDefinedInGridLimitsDuringHandleRequest() + public function testSetDefaultLimitRaiseExceptionIfLimitIsNotDefinedInGridLimitsDuringHandleRequest(): void { $limit = 2; @@ -1906,14 +1869,14 @@ public function testSetDefaultLimitRaiseExceptionIfLimitIsNotDefinedInGridLimits $this->grid->handleRequest($this->request); } - public function testSetDefaultLimitDuringHandleRequest() + public function testSetDefaultLimitDuringHandleRequest(): void { $this->mockDefaultLimit(); $this->grid->handleRequest($this->request); } - public function testProcessDefaultTweaksDuringHandleRequest() + public function testProcessDefaultTweaksDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -1935,7 +1898,7 @@ public function testProcessDefaultTweaksDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testSetPermanentSessionFiltersDuringHandleRequest() + public function testSetPermanentSessionFiltersDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -2024,7 +1987,7 @@ public function testSetPermanentSessionFiltersDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testPrepareRowsFromDataIfDataAlreadyLoadedDuringHandleRequest() + public function testPrepareRowsFromDataIfDataAlreadyLoadedDuringHandleRequest(): void { $source = $this->arrangeGridSourceDataLoadedWithoutRowsReturned(); $columns = $this->arrangeGridWithColumnsIterator(); @@ -2051,7 +2014,7 @@ public function testPrepareRowsFromDataIfDataAlreadyLoadedDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testPrepareRowsFromExecutionIfDataNotLoadedDuringHandleRequest() + public function testPrepareRowsFromExecutionIfDataNotLoadedDuringHandleRequest(): void { $source = $this->arrangeGridSourceDataNotLoadedWithoutRowsReturned(); $columns = $this->arrangeGridWithColumnsIterator(); @@ -2079,7 +2042,7 @@ public function testPrepareRowsFromExecutionIfDataNotLoadedDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testRaiseExceptionIfNotRowInstanceReturnedFromSurceIfDataAlreadyLoadedDuringHandleRequest() + public function testRaiseExceptionIfNotRowInstanceReturnedFromSurceIfDataAlreadyLoadedDuringHandleRequest(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage(Grid::NO_ROWS_RETURNED_EX_MSG); @@ -2089,7 +2052,7 @@ public function testRaiseExceptionIfNotRowInstanceReturnedFromSurceIfDataAlready $this->grid->handleRequest($this->request); } - public function testRaiseExceptionIfNotRowInstanceReturnedFromSurceIfDataNotLoadedLoadedDuringHandleRequest() + public function testRaiseExceptionIfNotRowInstanceReturnedFromSurceIfDataNotLoadedLoadedDuringHandleRequest(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage(Grid::NO_ROWS_RETURNED_EX_MSG); @@ -2099,7 +2062,7 @@ public function testRaiseExceptionIfNotRowInstanceReturnedFromSurceIfDataNotLoad $this->grid->handleRequest($this->request); } - public function testSetFirstPageIfNoRowsFromSourceIfDataAlreadyDataAndRequestedPageNotFirst() + public function testSetFirstPageIfNoRowsFromSourceIfDataAlreadyDataAndRequestedPageNotFirst(): void { $source = $this->arrangeGridSourceDataLoadedWithoutRowsReturned(); $columns = $this->arrangeGridWithColumnsIterator(); @@ -2126,7 +2089,7 @@ public function testSetFirstPageIfNoRowsFromSourceIfDataAlreadyDataAndRequestedP $this->grid->handleRequest($this->request); } - public function testSetFirstPageIfNoRowsFromSourceIfDataNotLoadedAndRequestedPageNotFirst() + public function testSetFirstPageIfNoRowsFromSourceIfDataNotLoadedAndRequestedPageNotFirst(): void { $source = $this->arrangeGridSourceDataNotLoadedWithoutRowsReturned(); $columns = $this->arrangeGridWithColumnsIterator(); @@ -2153,7 +2116,7 @@ public function testSetFirstPageIfNoRowsFromSourceIfDataNotLoadedAndRequestedPag $this->grid->handleRequest($this->request); } - public function testAddRowActionsToAllColumnsDuringHandleRequest() + public function testAddRowActionsToAllColumnsDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -2215,7 +2178,7 @@ public function testAddRowActionsToAllColumnsDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testAddRowActionsToNotExistingColumnDuringHandleRequest() + public function testAddRowActionsToNotExistingColumnDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -2253,7 +2216,7 @@ public function testAddRowActionsToNotExistingColumnDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testAddMassActionColumnsDuringHandleRequest() + public function testAddMassActionColumnsDuringHandleRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -2269,7 +2232,7 @@ public function testAddMassActionColumnsDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testSetPrimaryFieldOnEachRow() + public function testSetPrimaryFieldOnEachRow(): void { $row = $this->createMock(Row::class); $row2 = $this->createMock(Row::class); @@ -2293,7 +2256,7 @@ public function testSetPrimaryFieldOnEachRow() $this->grid->handleRequest($this->request); } - public function testPopulateSelectFiltersInSourceFromDataIfDataLoadedDuringHandleRequest() + public function testPopulateSelectFiltersInSourceFromDataIfDataLoadedDuringHandleRequest(): void { $columns = $this->arrangeGridWithColumnsIterator(); @@ -2306,7 +2269,7 @@ public function testPopulateSelectFiltersInSourceFromDataIfDataLoadedDuringHandl $this->grid->handleRequest($this->request); } - public function testPopulateSelectFiltersInSourceIfDataNotLoadedDuringHandleRequest() + public function testPopulateSelectFiltersInSourceIfDataNotLoadedDuringHandleRequest(): void { $source = $this->arrangeGridSourceDataNotLoadedWithEmptyRows(); @@ -2320,7 +2283,7 @@ public function testPopulateSelectFiltersInSourceIfDataNotLoadedDuringHandleRequ $this->grid->handleRequest($this->request); } - public function testSetTotalCountFromDataDuringHandleRequest() + public function testSetTotalCountFromDataDuringHandleRequest(): void { $totalCount = 2; $this->arrangeGridSourceDataLoadedWithEmptyRows($totalCount); @@ -2331,7 +2294,7 @@ public function testSetTotalCountFromDataDuringHandleRequest() $this->assertSame($totalCount, $this->grid->getTotalCount()); } - public function testSetTotalCountDuringHandleRequest() + public function testSetTotalCountDuringHandleRequest(): void { $totalCount = 2; $this->arrangeGridSourceDataNotLoadedWithEmptyRows($totalCount); @@ -2342,7 +2305,7 @@ public function testSetTotalCountDuringHandleRequest() $this->assertSame($totalCount, $this->grid->getTotalCount()); } - public function testThrowsExceptionIfTotalCountNotIntegerFromDataDuringHandleRequest() + public function testThrowsExceptionIfTotalCountNotIntegerFromDataDuringHandleRequest(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage(sprintf(Grid::INVALID_TOTAL_COUNT_EX_MSG, 'NULL')); @@ -2353,7 +2316,7 @@ public function testThrowsExceptionIfTotalCountNotIntegerFromDataDuringHandleReq $this->grid->handleRequest($this->request); } - public function testThrowsExceptionIfTotalCountNotIntegerDuringHandleRequest() + public function testThrowsExceptionIfTotalCountNotIntegerDuringHandleRequest(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage(sprintf(Grid::INVALID_TOTAL_COUNT_EX_MSG, 'NULL')); @@ -2364,7 +2327,7 @@ public function testThrowsExceptionIfTotalCountNotIntegerDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testRaiseExceptionIfTweakDoesNotExistsDuringHandleRequest() + public function testRaiseExceptionIfTweakDoesNotExistsDuringHandleRequest(): void { $tweakId = 'aValidTweakId'; @@ -2383,105 +2346,105 @@ public function testRaiseExceptionIfTweakDoesNotExistsDuringHandleRequest() $this->grid->handleRequest($this->request); } - public function testProcessTweakResetDuringHandleRequest() + public function testProcessTweakResetDuringHandleRequest(): void { $this->mockTweakReset(); $this->grid->handleRequest($this->request); } - public function testProcessTweakFiltersDuringHandleRequest() + public function testProcessTweakFiltersDuringHandleRequest(): void { $this->mockTweakFilters(); $this->grid->handleRequest($this->request); } - public function testProcessTweakOrderDuringHandleRequest() + public function testProcessTweakOrderDuringHandleRequest(): void { $this->mockTweakOrder(); $this->grid->handleRequest($this->request); } - public function testProcessTweakMassActionDuringHandleRequest() + public function testProcessTweakMassActionDuringHandleRequest(): void { $this->mockTweakMassAction(); $this->grid->handleRequest($this->request); } - public function testProcessTweakPageDuringHandleRequest() + public function testProcessTweakPageDuringHandleRequest(): void { $this->mockTweakPage(); $this->grid->handleRequest($this->request); } - public function testProcessTweakLimitDuringHandleRequest() + public function testProcessTweakLimitDuringHandleRequest(): void { $this->mockTweakLimit(); $this->grid->handleRequest($this->request); } - public function testProcessTweakExportDuringHandleRequest() + public function testProcessTweakExportDuringHandleRequest(): void { $this->mockTweakExport(); $this->grid->handleRequest($this->request); } - public function testProcessTweakExportButNotFiltersPageOrderLimitDuringHandleRequest() + public function testProcessTweakExportButNotFiltersPageOrderLimitDuringHandleRequest(): void { $this->mockTweakExportButNotFiltersPageOrderLimit(); $this->grid->handleRequest($this->request); } - public function testProcessRemoveActiveTweakGroupsDuringHandleRequest() + public function testProcessRemoveActiveTweakGroupsDuringHandleRequest(): void { $this->mockRemoveActiveTweakGroups(); $this->grid->handleRequest($this->request); } - public function testProcessRemoveActiveTweakDuringHandleRequest() + public function testProcessRemoveActiveTweakDuringHandleRequest(): void { $this->mockRemoveActiveTweak(); $this->grid->handleRequest($this->request); } - public function testProcessAddActiveTweakDuringHandleRequest() + public function testProcessAddActiveTweakDuringHandleRequest(): void { $this->mockAddActiveTweak(); $this->grid->handleRequest($this->request); } - public function testProcessHiddenColumnsDuringHandleRequest() + public function testProcessHiddenColumnsDuringHandleRequest(): void { $this->mockHiddenColumns(); $this->grid->handleRequest($this->request); } - public function testProcessVisibleColumnsDuringHandleRequest() + public function testProcessVisibleColumnsDuringHandleRequest(): void { $this->mockVisibleColumns(); $this->grid->handleRequest($this->request); } - public function testProcessColumnVisibilityDuringHandleRequest() + public function testProcessColumnVisibilityDuringHandleRequest(): void { $this->mockColumnVisibility(); $this->grid->handleRequest($this->request); } - public function testGetTweaksWithUrlWithoutGetParameters() + public function testGetTweaksWithUrlWithoutGetParameters(): void { $routeUrl = 'http://www.foo.com'; @@ -2511,7 +2474,7 @@ public function testGetTweaksWithUrlWithoutGetParameters() $this->assertEquals($result, $this->grid->getTweaks()); } - public function testGetTweaksWithUrlWithGetParameters() + public function testGetTweaksWithUrlWithGetParameters(): void { $routeUrl = 'http://www.foo.com?foo=foo'; @@ -2541,7 +2504,7 @@ public function testGetTweaksWithUrlWithGetParameters() $this->assertEquals($result, $this->grid->getTweaks()); } - public function testRaiseExceptionIfGetNonExistentTweak() + public function testRaiseExceptionIfGetNonExistentTweak(): void { $nonExistentTweak = 'aNonExistentTweak'; @@ -2559,7 +2522,7 @@ public function testRaiseExceptionIfGetNonExistentTweak() $this->grid->getTweak($nonExistentTweak); } - public function testGetTweak() + public function testGetTweak(): void { $title = 'aTweak'; $id = 'aValidTweakId'; @@ -2578,7 +2541,7 @@ public function testGetTweak() $this->assertEquals($tweakResult, $this->grid->getTweak($id)); } - public function testGetTweaksByGroupExcludingThoseWhoDoNotHaveTheGroup() + public function testGetTweaksByGroupExcludingThoseWhoDoNotHaveTheGroup(): void { $title = 'aTweak'; $id = 'aValidTweakId'; @@ -2600,7 +2563,7 @@ public function testGetTweaksByGroupExcludingThoseWhoDoNotHaveTheGroup() $this->assertEquals($tweakResult, $this->grid->getTweaksGroup($group)); } - public function testGetActiveTweaks() + public function testGetActiveTweaks(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -2633,7 +2596,7 @@ public function testGetActiveTweaks() $this->assertEquals([$tweakGroup => $tweakId], $this->grid->getActiveTweaks()); } - public function testGetActiveTweakGroup() + public function testGetActiveTweakGroup(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -2667,7 +2630,7 @@ public function testGetActiveTweakGroup() $this->assertEquals(-1, $this->grid->getActiveTweakGroup('invalidGroup')); } - public function testGetExportResponse() + public function testGetExportResponse(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -2691,7 +2654,7 @@ public function testGetExportResponse() $this->assertEquals($response, $this->grid->getExportResponse()); } - public function testIsReadyForExport() + public function testIsReadyForExport(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -2715,7 +2678,7 @@ public function testIsReadyForExport() $this->assertTrue($this->grid->isReadyForExport()); } - public function testSetPermanentFilters() + public function testSetPermanentFilters(): void { $filters = [ 'colId1' => 'value', @@ -2727,7 +2690,7 @@ public function testSetPermanentFilters() $this->assertSame($filters, $this->grid->getPermanentFilters()); } - public function testSetDefaultFilters() + public function testSetDefaultFilters(): void { $filters = [ 'colId1' => 'value', @@ -2739,7 +2702,7 @@ public function testSetDefaultFilters() $this->assertSame($filters, $this->grid->getDefaultFilters()); } - public function testSetDefaultOrder() + public function testSetDefaultOrder(): void { $colId = 'COLID'; $order = 'ASC'; @@ -2749,7 +2712,7 @@ public function testSetDefaultOrder() $this->assertSame(sprintf("$colId|%s", strtolower($order)), $this->grid->getDefaultOrder()); } - public function testGetRows() + public function testGetRows(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -2763,7 +2726,7 @@ public function testGetRows() $this->assertEquals($rows, $this->grid->getRows()); } - public function testGetTotalCount() + public function testGetTotalCount(): void { $totalCount = 20; $this->arrangeGridSourceDataLoadedWithEmptyRows($totalCount); @@ -2774,12 +2737,12 @@ public function testGetTotalCount() $this->assertEquals($totalCount, $this->grid->getTotalCount()); } - public function testGetPageCountWithoutLimit() + public function testGetPageCountWithoutLimit(): void { $this->assertEquals(1, $this->grid->getPageCount()); } - public function testGetPageCount() + public function testGetPageCount(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(29); $this->arrangeGridWithColumnsIterator(); @@ -2800,26 +2763,26 @@ public function testGetPageCount() $this->assertEquals(3, $this->grid->getPageCount()); } - public function testIsPagerSectionNotVisibleWhenNoLimitsSetted() + public function testIsPagerSectionNotVisibleWhenNoLimitsSetted(): void { $this->assertFalse($this->grid->isPagerSectionVisible()); } - public function testIsPagerSectionNotVisibleWhenSmallestLimitGreaterThanTotalCount() + public function testIsPagerSectionNotVisibleWhenSmallestLimitGreaterThanTotalCount(): void { $this->grid->setLimits([10, 20, 30]); $this->assertFalse($this->grid->isPagerSectionVisible()); } - public function testIsPagerSectionVisibleWhenSmallestLimitLowestThanTotalCount() + public function testIsPagerSectionVisibleWhenSmallestLimitLowestThanTotalCount(): void { $this->grid->setLimits([10, 20, 30]); $this->assertFalse($this->grid->isPagerSectionVisible()); } - public function testDeleteAction() + public function testDeleteAction(): void { $source = $this->createMock(Source::class); @@ -2834,7 +2797,7 @@ public function testDeleteAction() $this->grid->deleteAction($deleteIds); } - public function testGetRawDataWithAllColumnsIfNoColumnsRequested() + public function testGetRawDataWithAllColumnsIfNoColumnsRequested(): void { $rows = new Rows(); @@ -2891,7 +2854,7 @@ public function testGetRawDataWithAllColumnsIfNoColumnsRequested() ); } - public function testGetRawDataWithSubsetOfColumns() + public function testGetRawDataWithSubsetOfColumns(): void { $rows = new Rows(); @@ -2948,7 +2911,7 @@ public function testGetRawDataWithSubsetOfColumns() ); } - public function testGetRawDataWithoutNamedIndexesResult() + public function testGetRawDataWithoutNamedIndexesResult(): void { $rows = new Rows(); @@ -2989,7 +2952,7 @@ public function testGetRawDataWithoutNamedIndexesResult() ); } - public function testGetFiltersRaiseExceptionIfNoRequestProcessed() + public function testGetFiltersRaiseExceptionIfNoRequestProcessed(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage(Grid::GET_FILTERS_NO_REQUEST_HANDLED_EX_MSG); @@ -2997,7 +2960,7 @@ public function testGetFiltersRaiseExceptionIfNoRequestProcessed() $this->grid->getFilters(); } - public function testGetFilters() + public function testGetFilters(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3031,10 +2994,12 @@ public function testGetFilters() $filter2From = 'from2'; $filter2 = new Filter($filter2Operator, $filter2From); - $this->grid->setDefaultFilters([ - $col1Id => ['operator' => $filter1Operator, 'from' => $filter1From, 'to' => $filter1To], - $col2Id => ['from' => $filter2From], - ]); + $this->grid->setDefaultFilters( + [ + $col1Id => ['operator' => $filter1Operator, 'from' => $filter1From, 'to' => $filter1To], + $col2Id => ['from' => $filter2From], + ] + ); $this ->session @@ -3060,7 +3025,7 @@ public function testGetFilters() ); } - public function testGetFilterRaiseExceptionIfNoRequestProcessed() + public function testGetFilterRaiseExceptionIfNoRequestProcessed(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage(Grid::GET_FILTERS_NO_REQUEST_HANDLED_EX_MSG); @@ -3068,7 +3033,7 @@ public function testGetFilterRaiseExceptionIfNoRequestProcessed() $this->grid->getFilter('foo'); } - public function testGetFilterReturnNullIfRequestedColumnHasNoFilter() + public function testGetFilterReturnNullIfRequestedColumnHasNoFilter(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3078,7 +3043,7 @@ public function testGetFilterReturnNullIfRequestedColumnHasNoFilter() $this->assertNull($this->grid->getFilter('foo')); } - public function testGetFilter() + public function testGetFilter(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3101,7 +3066,7 @@ public function testGetFilter() $this->assertEquals($filter, $this->grid->getFilter($colId)); } - public function testHasFilterRaiseExceptionIfNoRequestProcessed() + public function testHasFilterRaiseExceptionIfNoRequestProcessed(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage(Grid::HAS_FILTER_NO_REQUEST_HANDLED_EX_MSG); @@ -3109,7 +3074,7 @@ public function testHasFilterRaiseExceptionIfNoRequestProcessed() $this->grid->hasFilter('foo'); } - public function testHasFilterReturnNullIfRequestedColumnHasNoFilter() + public function testHasFilterReturnNullIfRequestedColumnHasNoFilter(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3119,7 +3084,7 @@ public function testHasFilterReturnNullIfRequestedColumnHasNoFilter() $this->assertFalse($this->grid->hasFilter('foo')); } - public function testHasFilter() + public function testHasFilter(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3141,7 +3106,7 @@ public function testHasFilter() $this->assertTrue($this->grid->hasFilter($colId)); } - public function testRaiseExceptionIfNoSourceSettedDuringRedirect() + public function testRaiseExceptionIfNoSourceSettedDuringRedirect(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage(Grid::SOURCE_NOT_SETTED_EX_MSG); @@ -3149,7 +3114,7 @@ public function testRaiseExceptionIfNoSourceSettedDuringRedirect() $this->grid->isReadyForRedirect(); } - public function testCreateHashWithIdDuringRedirect() + public function testCreateHashWithIdDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3159,7 +3124,7 @@ public function testCreateHashWithIdDuringRedirect() $this->assertEquals($this->gridHash, $this->grid->getHash()); } - public function testCreateHashWithMd5DuringRedirect() + public function testCreateHashWithMd5DuringRedirect(): void { $this->arrange($this->createMock(GridConfigInterface::class), null); @@ -3186,14 +3151,14 @@ public function testCreateHashWithMd5DuringRedirect() $this->assertSame('grid_' . md5($controller . $columns->getHash() . $sourceHash), $this->grid->getHash()); } - public function testResetGridSessionWhenResetFiltersIsPressedDuringRedirect() + public function testResetGridSessionWhenResetFiltersIsPressedDuringRedirect(): void { $this->mockResetGridSessionWhenResetFilterIsPressed(); $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testNotResetGridSessionWhenXmlHttpRequestDuringRedirect() + public function testNotResetGridSessionWhenXmlHttpRequestDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3212,7 +3177,7 @@ public function testNotResetGridSessionWhenXmlHttpRequestDuringRedirect() $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testNotResetGridSessionWhenPersistenceSettedDuringRedirect() + public function testNotResetGridSessionWhenPersistenceSettedDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3233,14 +3198,14 @@ public function testNotResetGridSessionWhenPersistenceSettedDuringRedirect() $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testNotResetGridSessionWhenRefererIsSameGridDuringRedirect() + public function testNotResetGridSessionWhenRefererIsSameGridDuringRedirect(): void { $this->mockNotResetGridSessionWhenSameGridReferer(); $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testStartNewSessionDuringRedirectOnFirstRequest() + public function testStartNewSessionDuringRedirectOnFirstRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3250,7 +3215,7 @@ public function testStartNewSessionDuringRedirectOnFirstRequest() $this->assertTrue($this->grid->getNewSession()); } - public function testStartKeepSessionDuringRedirectNotOnFirstRequest() + public function testStartKeepSessionDuringRedirectNotOnFirstRequest(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -3266,28 +3231,28 @@ public function testStartKeepSessionDuringRedirectNotOnFirstRequest() $this->assertFalse($this->grid->getNewSession()); } - public function testProcessHiddenColumnsDuringRedirect() + public function testProcessHiddenColumnsDuringRedirect(): void { $this->mockHiddenColumns(); $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testProcessVisibleColumnsDuringRedirect() + public function testProcessVisibleColumnsDuringRedirect(): void { $this->mockVisibleColumns(); $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testProcessColumnVisibilityDuringRedirect() + public function testProcessColumnVisibilityDuringRedirect(): void { $this->mockColumnVisibility(); $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testRaiseExceptionIfMassActionIdNotValidDuringRedirect() + public function testRaiseExceptionIfMassActionIdNotValidDuringRedirect(): void { $massActionId = 10; @@ -3302,7 +3267,7 @@ public function testRaiseExceptionIfMassActionIdNotValidDuringRedirect() $this->grid->isReadyForRedirect(); } - public function testRaiseExceptionIfMassActionCallbackNotValidDuringRedirect() + public function testRaiseExceptionIfMassActionCallbackNotValidDuringRedirect(): void { $invalidCallback = 'invalidCallback'; @@ -3321,7 +3286,7 @@ public function testRaiseExceptionIfMassActionCallbackNotValidDuringRedirect() $this->grid->isReadyForRedirect(); } - public function testResetPageAndLimitIfMassActionHandleAllDataDuringRedirect() + public function testResetPageAndLimitIfMassActionHandleAllDataDuringRedirect(): void { $this->mockResetPageAndLimitIfMassActionAndAllKeys(); @@ -3330,7 +3295,7 @@ public function testResetPageAndLimitIfMassActionHandleAllDataDuringRedirect() $this->assertEquals(0, $this->grid->getLimit()); } - public function testMassActionResponseFromCallbackDuringRedirect() + public function testMassActionResponseFromCallbackDuringRedirect(): void { $callbackResponse = $this->mockMassActionCallbackResponse(); @@ -3339,7 +3304,7 @@ public function testMassActionResponseFromCallbackDuringRedirect() $this->assertEquals($callbackResponse, $this->grid->getMassActionResponse()); } - public function testMassActionResponseFromControllerActionDuringRedirect() + public function testMassActionResponseFromControllerActionDuringRedirect(): void { $callbackResponse = $this->mockMassActionControllerResponse(); @@ -3348,7 +3313,7 @@ public function testMassActionResponseFromControllerActionDuringRedirect() $this->assertEquals($callbackResponse, $this->grid->getMassActionResponse()); } - public function testRaiseExceptionIfExportIdNotValidDuringRedirect() + public function testRaiseExceptionIfExportIdNotValidDuringRedirect(): void { $exportId = 10; @@ -3363,7 +3328,7 @@ public function testRaiseExceptionIfExportIdNotValidDuringRedirect() $this->grid->isReadyForRedirect(); } - public function testProcessExportsDuringRedirect() + public function testProcessExportsDuringRedirect(): void { $response = $this->mockExports(); @@ -3375,14 +3340,14 @@ public function testProcessExportsDuringRedirect() $this->assertSame($response, $this->grid->getExportResponse()); } - public function testProcessExportsButNotFiltersPageOrderLimitDuringRedirect() + public function testProcessExportsButNotFiltersPageOrderLimitDuringRedirect(): void { $this->mockExportsButNotFiltersPageOrderLimit(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testRaiseExceptionIfTweakDoesNotExistsDuringRedirect() + public function testRaiseExceptionIfTweakDoesNotExistsDuringRedirect(): void { $tweakId = 'aValidTweakId'; @@ -3401,133 +3366,133 @@ public function testRaiseExceptionIfTweakDoesNotExistsDuringRedirect() $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessTweakResetDuringRedirect() + public function testProcessTweakResetDuringRedirect(): void { $this->mockTweakReset(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessTweakFiltersDuringRedirect() + public function testProcessTweakFiltersDuringRedirect(): void { $this->mockTweakFilters(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessTweakOrderDuringRedirect() + public function testProcessTweakOrderDuringRedirect(): void { $this->mockTweakOrder(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessTweakMassActionDuringRedirect() + public function testProcessTweakMassActionDuringRedirect(): void { $this->mockTweakMassAction(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessTweakPageDuringRedirect() + public function testProcessTweakPageDuringRedirect(): void { $this->mockTweakPage(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessTweakLimitDuringRedirect() + public function testProcessTweakLimitDuringRedirect(): void { $this->mockTweakLimit(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessTweakExportDuringRedirect() + public function testProcessTweakExportDuringRedirect(): void { $this->mockTweakExport(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessTweakExportButNotFiltersPageOrderLimitDuringRedirect() + public function testProcessTweakExportButNotFiltersPageOrderLimitDuringRedirect(): void { $this->mockTweakExportButNotFiltersPageOrderLimit(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessRemoveActiveTweakGroupsDuringRedirect() + public function testProcessRemoveActiveTweakGroupsDuringRedirect(): void { $this->mockRemoveActiveTweakGroups(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessRemoveActiveTweakDuringRedirect() + public function testProcessRemoveActiveTweakDuringRedirect(): void { $this->mockRemoveActiveTweak(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessAddActiveTweakDuringRedirect() + public function testProcessAddActiveTweakDuringRedirect(): void { $this->mockAddActiveTweak(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessPageDuringRedirect() + public function testProcessPageDuringRedirect(): void { $this->mockPageRequestData(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessPageWithQueryOrderingDuringRedirect() + public function testProcessPageWithQueryOrderingDuringRedirect(): void { $this->mockPageQueryOrderRequestData(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessPageWithQueryLimitDuringRedirect() + public function testProcessPageWithQueryLimitDuringRedirect(): void { $this->mockPageLimitRequestData(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessPageWithMassActionDuringRedirect() + public function testProcessPageWithMassActionDuringRedirect(): void { $this->mockPageMassActionRequestData(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessPageWithFiltersAndRequestDataDuringRedirect() + public function testProcessPageWithFiltersAndRequestDataDuringRedirect(): void { $this->mockPageFiltersRequestData(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessPageWithFiltersDifferentFromSelectDuringRedirect() + public function testProcessPageWithFiltersDifferentFromSelectDuringRedirect(): void { $this->mockPageNotSelectFilterRequestData(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessPageWithSelectFilterColumnNotSelectMultiDuringRedirect() + public function testProcessPageWithSelectFilterColumnNotSelectMultiDuringRedirect(): void { $this->mockPageColumnNotSelectMultiRequestData(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessOrderDescDuringRedirect() + public function testProcessOrderDescDuringRedirect(): void { $colId = 'colId'; $order = 'desc'; @@ -3549,7 +3514,7 @@ public function testProcessOrderDescDuringRedirect() $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessOrderAscDuringRedirect() + public function testProcessOrderAscDuringRedirect(): void { $colId = 'colId'; $order = 'asc'; @@ -3571,14 +3536,14 @@ public function testProcessOrderAscDuringRedirect() $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessOrderColumnNotSortableDuringRedirect() + public function testProcessOrderColumnNotSortableDuringRedirect(): void { $this->mockOrderColumnNotSortable(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testColumnsNotOrderedIfNoOrderRequestedDuringRedirect() + public function testColumnsNotOrderedIfNoOrderRequestedDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -3602,14 +3567,14 @@ public function testColumnsNotOrderedIfNoOrderRequestedDuringRedirect() $this->assertSame(0, $this->grid->getPage()); } - public function testProcessConfiguredLimitDuringRedirect() + public function testProcessConfiguredLimitDuringRedirect(): void { $this->mockConfiguredLimitRequestData(); $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessNonConfiguredLimitDuringRedirect() + public function testProcessNonConfiguredLimitDuringRedirect(): void { $this->mockNonConfiguredLimitRequestData(); @@ -3618,14 +3583,14 @@ public function testProcessNonConfiguredLimitDuringRedirect() $this->assertEmpty($this->grid->getLimit()); } - public function testSetDefaultSessionFiltersIfNotRequestDataDuringRedirect() + public function testSetDefaultSessionFiltersIfNotRequestDataDuringRedirect(): void { $this->mockDefaultSessionFiltersWithoutRequestData(); $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testSetDefaultSessionFiltersIfSessionDataXmlHttpRequestAndNotExportDuringRedirect() + public function testSetDefaultSessionFiltersIfSessionDataXmlHttpRequestAndNotExportDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -3712,7 +3677,7 @@ public function testSetDefaultSessionFiltersIfSessionDataXmlHttpRequestAndNotExp $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testNotSetDefaultSessionFiltersIfHasRequestDataNotXmlHttpButExportDuringRedirect() + public function testNotSetDefaultSessionFiltersIfHasRequestDataNotXmlHttpButExportDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -3782,7 +3747,7 @@ public function testNotSetDefaultSessionFiltersIfHasRequestDataNotXmlHttpButExpo $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testNotSetDefaultSessionFiltersIfHasRequestDataNotXmlHttpAndNotExportDuringRedirect() + public function testNotSetDefaultSessionFiltersIfHasRequestDataNotXmlHttpAndNotExportDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -3852,7 +3817,7 @@ public function testNotSetDefaultSessionFiltersIfHasRequestDataNotXmlHttpAndNotE $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testSetDefaultPageRaiseExceptionIfPageHasNegativeValueDuringRedirect() + public function testSetDefaultPageRaiseExceptionIfPageHasNegativeValueDuringRedirect(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage(Grid::PAGE_NOT_VALID_EX_MSG); @@ -3865,14 +3830,14 @@ public function testSetDefaultPageRaiseExceptionIfPageHasNegativeValueDuringRedi $this->grid->isReadyForRedirect(); } - public function testSetDefaultPageIfNotRequestDataDuringRedirect() + public function testSetDefaultPageIfNotRequestDataDuringRedirect(): void { $this->mockDefaultPage(); $this->grid->isReadyForRedirect(); } - public function testSetDefaultPageIfRequestDataXmlHttpRequestAndNotExportDuringRedirect() + public function testSetDefaultPageIfRequestDataXmlHttpRequestAndNotExportDuringRedirect(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -3902,7 +3867,7 @@ public function testSetDefaultPageIfRequestDataXmlHttpRequestAndNotExportDuringR $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testNotSetDefaultPageIfHasRequestDataNotXmlHttpButExportDuringRedirect() + public function testNotSetDefaultPageIfHasRequestDataNotXmlHttpButExportDuringRedirect(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -3928,7 +3893,7 @@ public function testNotSetDefaultPageIfHasRequestDataNotXmlHttpButExportDuringRe $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testNotSetDefaultPageIfHasRequestDataNotXmlHttpAndNotExportDuringRedirect() + public function testNotSetDefaultPageIfHasRequestDataNotXmlHttpAndNotExportDuringRedirect(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -3954,7 +3919,7 @@ public function testNotSetDefaultPageIfHasRequestDataNotXmlHttpAndNotExportDurin $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testSetDefaultOrderRaiseExceptionIfOrderNotAscNeitherDescDuringRedirect() + public function testSetDefaultOrderRaiseExceptionIfOrderNotAscNeitherDescDuringRedirect(): void { $columnOrder = 'foo'; @@ -3973,7 +3938,7 @@ public function testSetDefaultOrderRaiseExceptionIfOrderNotAscNeitherDescDuringR $this->grid->isReadyForRedirect(); } - public function testSetDefaultOrderRaiseExceptionIfColumnDoesNotExistsDuringRedirect() + public function testSetDefaultOrderRaiseExceptionIfColumnDoesNotExistsDuringRedirect(): void { $colId = 'col'; @@ -3990,21 +3955,21 @@ public function testSetDefaultOrderRaiseExceptionIfColumnDoesNotExistsDuringRedi $this->grid->isReadyForRedirect(); } - public function testSetDefaultOrderAscIfNotRequestDataDuringRedirect() + public function testSetDefaultOrderAscIfNotRequestDataDuringRedirect(): void { $this->mockDefaultOrder('asc'); $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testSetDefaultOrderDescIfNotRequestDataDuringRedirect() + public function testSetDefaultOrderDescIfNotRequestDataDuringRedirect(): void { $this->mockDefaultOrder('desc'); $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testSetDefaultOrderIfRequestDataXmlHttpRequestAndNotExportDuringRedirect() + public function testSetDefaultOrderIfRequestDataXmlHttpRequestAndNotExportDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -4045,7 +4010,7 @@ public function testSetDefaultOrderIfRequestDataXmlHttpRequestAndNotExportDuring $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testNotSetDefaultOrderIfHasRequestDataNotXmlHttpButExportDuringRedirect() + public function testNotSetDefaultOrderIfHasRequestDataNotXmlHttpButExportDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -4079,7 +4044,7 @@ public function testNotSetDefaultOrderIfHasRequestDataNotXmlHttpButExportDuringR $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testNotSetDefaultOrderIfHasRequestDataNotXmlHttpAndNotExportDuringRedirect() + public function testNotSetDefaultOrderIfHasRequestDataNotXmlHttpAndNotExportDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -4113,7 +4078,7 @@ public function testNotSetDefaultOrderIfHasRequestDataNotXmlHttpAndNotExportDuri $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testSetDefaultLimitRaiseExceptionIfLimitIsNotAPositiveDuringRedirect() + public function testSetDefaultLimitRaiseExceptionIfLimitIsNotAPositiveDuringRedirect(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage(Grid::DEFAULT_LIMIT_NOT_VALID_EX_MSG); @@ -4126,7 +4091,7 @@ public function testSetDefaultLimitRaiseExceptionIfLimitIsNotAPositiveDuringRedi $this->grid->isReadyForRedirect(); } - public function testSetDefaultLimitRaiseExceptionIfLimitIsNotDefinedInGridLimitsDuringRedirect() + public function testSetDefaultLimitRaiseExceptionIfLimitIsNotDefinedInGridLimitsDuringRedirect(): void { $limit = 2; @@ -4141,14 +4106,14 @@ public function testSetDefaultLimitRaiseExceptionIfLimitIsNotDefinedInGridLimits $this->grid->isReadyForRedirect(); } - public function testSetDefaultLimitIfNotSessionDataDuringHandleRedirect() + public function testSetDefaultLimitIfNotSessionDataDuringHandleRedirect(): void { $this->mockDefaultLimit(); $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testSetDefaultLimitIfRequestDataXmlHttpRequestAndNotExportDuringHandleRedirect() + public function testSetDefaultLimitIfRequestDataXmlHttpRequestAndNotExportDuringHandleRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4179,7 +4144,7 @@ public function testSetDefaultLimitIfRequestDataXmlHttpRequestAndNotExportDuring $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testNotSetDefaultLimitIfHasRequestDataNotXmlHttpButExportDuringHandleRedirect() + public function testNotSetDefaultLimitIfHasRequestDataNotXmlHttpButExportDuringHandleRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4203,7 +4168,7 @@ public function testNotSetDefaultLimitIfHasRequestDataNotXmlHttpButExportDuringH $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testNotSetDefaultLimitIfHasRequestDataNotXmlHttpAndNotExportDuringHandleRedirect() + public function testNotSetDefaultLimitIfHasRequestDataNotXmlHttpAndNotExportDuringHandleRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4227,7 +4192,7 @@ public function testNotSetDefaultLimitIfHasRequestDataNotXmlHttpAndNotExportDuri $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testProcessDefaultTweaksIfNotRequestDataDuringRedirect() + public function testProcessDefaultTweaksIfNotRequestDataDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4243,7 +4208,7 @@ public function testProcessDefaultTweaksIfNotRequestDataDuringRedirect() $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testProcessDefaultTweaksIfRequestDataXmlHttpRequestAndNotExportDuringRedirect() + public function testProcessDefaultTweaksIfRequestDataXmlHttpRequestAndNotExportDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4273,7 +4238,7 @@ public function testProcessDefaultTweaksIfRequestDataXmlHttpRequestAndNotExportD $this->assertFalse($this->grid->isReadyForRedirect()); } - public function testNotProcessDefaultTweaksIfHasRequestDataNotXmlHttpButExportDuringRedirect() + public function testNotProcessDefaultTweaksIfHasRequestDataNotXmlHttpButExportDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4295,7 +4260,7 @@ public function testNotProcessDefaultTweaksIfHasRequestDataNotXmlHttpButExportDu $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testNotProcessDefaultTweaksIfHasRequestDataNotXmlHttpAndNotExportDuringRedirect() + public function testNotProcessDefaultTweaksIfHasRequestDataNotXmlHttpAndNotExportDuringRedirect(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4317,7 +4282,7 @@ public function testNotProcessDefaultTweaksIfHasRequestDataNotXmlHttpAndNotExpor $this->assertTrue($this->grid->isReadyForRedirect()); } - public function testGetGridRedirectResponse() + public function testGetGridRedirectResponse(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -4331,28 +4296,28 @@ public function testGetGridRedirectResponse() $this->assertInstanceOf(RedirectResponse::class, $this->grid->getGridResponse()); } - public function testGetGridExportResponse() + public function testGetGridExportResponse(): void { $exportResponse = $this->mockExports(); $this->assertEquals($exportResponse, $this->grid->getGridResponse()); } - public function testGetGridMassActionCallbackRedirectResponse() + public function testGetGridMassActionCallbackRedirectResponse(): void { $response = $this->mockMassActionCallbackResponse(); $this->assertEquals($response, $this->grid->getGridResponse()); } - public function testGetGridMassActionControllerResponse() + public function testGetGridMassActionControllerResponse(): void { $response = $this->mockMassActionControllerResponse(); $this->assertEquals($response, $this->grid->getGridResponse()); } - public function testGetGridWithoutParams() + public function testGetGridWithoutParams(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4360,7 +4325,7 @@ public function testGetGridWithoutParams() $this->assertEquals(['grid' => $this->grid], $this->grid->getGridResponse()); } - public function testGetGridWithoutView() + public function testGetGridWithoutView(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4371,7 +4336,7 @@ public function testGetGridWithoutView() $this->assertEquals(['grid' => $this->grid, $param1, $param2], $this->grid->getGridResponse($params)); } - public function testGetGridWithViewWithoutParams() + public function testGetGridWithViewWithoutParams(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4381,7 +4346,7 @@ public function testGetGridWithViewWithoutParams() $this->assertInstanceOf(Response::class, $this->grid->getGridResponse($view)); } - public function testGetGridWithViewWithViewAndParams() + public function testGetGridWithViewWithViewAndParams(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4663,10 +4628,7 @@ private function mockResetPageAndLimitIfMassActionAndAllKeys() ->with($this->gridHash, [Grid::REQUEST_QUERY_PAGE => 0]); } - /** - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function mockMassActionCallbackResponse() + private function mockMassActionCallbackResponse(): MockObject { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4694,10 +4656,7 @@ function () use ($callbackResponse) { return $callbackResponse; } - /** - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function mockMassActionControllerResponse() + private function mockMassActionControllerResponse(): MockObject { $httpKernel = $this ->getMockBuilder(HttpKernel::class) @@ -4778,10 +4737,7 @@ private function mockMassActionControllerResponse() return $callbackResponse; } - /** - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function mockExports() + private function mockExports(): MockObject { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -4808,7 +4764,7 @@ private function mockExports() return $response; } - private function mockExportsButNotFiltersPageOrderLimit() + private function mockExportsButNotFiltersPageOrderLimit(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -4859,7 +4815,7 @@ private function mockExportsButNotFiltersPageOrderLimit() ->method('set'); } - private function mockTweakReset() + private function mockTweakReset(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -4883,7 +4839,7 @@ private function mockTweakReset() ->with($this->gridHash); } - private function mockTweakFilters() + private function mockTweakFilters(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -4918,7 +4874,7 @@ private function mockTweakFilters() ->with($this->gridHash, ['tweaks' => [$tweakGroup => $tweakId], $colId => ['from' => ['foo'], 'to' => ['bar']]]); } - private function mockTweakOrder() + private function mockTweakOrder(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -4953,7 +4909,7 @@ private function mockTweakOrder() ->with($this->gridHash, ['tweaks' => [$tweakGroup => $tweakId], Grid::REQUEST_QUERY_ORDER => "$colId|$order"]); } - private function mockTweakMassAction() + private function mockTweakMassAction(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -4977,7 +4933,7 @@ private function mockTweakMassAction() ->method('set'); } - private function mockTweakPage() + private function mockTweakPage(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5007,7 +4963,7 @@ private function mockTweakPage() ->with($this->gridHash, ['tweaks' => [$tweakGroup => $tweakId], Grid::REQUEST_QUERY_PAGE => $page]); } - private function mockTweakLimit() + private function mockTweakLimit(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5039,7 +4995,7 @@ private function mockTweakLimit() ->with($this->gridHash, ['tweaks' => [$tweakGroup => $tweakId], Grid::REQUEST_QUERY_LIMIT => $limit]); } - private function mockTweakExport() + private function mockTweakExport(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5063,7 +5019,7 @@ private function mockTweakExport() ->method('set'); } - private function mockTweakExportButNotFiltersPageOrderLimit() + private function mockTweakExportButNotFiltersPageOrderLimit(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5105,7 +5061,7 @@ private function mockTweakExportButNotFiltersPageOrderLimit() ->method('set'); } - private function mockRemoveActiveTweakGroups() + private function mockRemoveActiveTweakGroups(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5156,7 +5112,7 @@ private function mockRemoveActiveTweakGroups() ]); } - private function mockRemoveActiveTweak() + private function mockRemoveActiveTweak(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5207,7 +5163,7 @@ private function mockRemoveActiveTweak() ]); } - private function mockAddActiveTweak() + private function mockAddActiveTweak(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5258,7 +5214,7 @@ private function mockAddActiveTweak() ]); } - private function mockPageRequestData() + private function mockPageRequestData(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5277,7 +5233,7 @@ private function mockPageRequestData() ->with($this->gridHash, [Grid::REQUEST_QUERY_PAGE => $page]); } - private function mockPageQueryOrderRequestData() + private function mockPageQueryOrderRequestData(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -5306,7 +5262,7 @@ private function mockPageQueryOrderRequestData() ->with($this->gridHash, [Grid::REQUEST_QUERY_PAGE => 0]); } - private function mockPageLimitRequestData() + private function mockPageLimitRequestData(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -5323,7 +5279,7 @@ private function mockPageLimitRequestData() ->with($this->gridHash, [Grid::REQUEST_QUERY_PAGE => 0]); } - private function mockPageMassActionRequestData() + private function mockPageMassActionRequestData(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -5344,7 +5300,7 @@ private function mockPageMassActionRequestData() ->with($this->gridHash, [Grid::REQUEST_QUERY_PAGE => 0]); } - private function mockPageFiltersRequestData() + private function mockPageFiltersRequestData(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5363,10 +5319,12 @@ private function mockPageFiltersRequestData() ->method('isFilterable') ->willReturn(true); - $this->stubRequestWithData([ - Grid::REQUEST_QUERY_PAGE => 2, - $colId => $colData, - ]); + $this->stubRequestWithData( + [ + Grid::REQUEST_QUERY_PAGE => 2, + $colId => $colData, + ] + ); $this ->session @@ -5375,7 +5333,7 @@ private function mockPageFiltersRequestData() ->with($this->gridHash, [$colId => $colData, Grid::REQUEST_QUERY_PAGE => 0]); } - private function mockPageNotSelectFilterRequestData() + private function mockPageNotSelectFilterRequestData(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5406,7 +5364,7 @@ private function mockPageNotSelectFilterRequestData() ->with($this->gridHash, [Grid::REQUEST_QUERY_PAGE => $page]); } - private function mockPageColumnNotSelectMultiRequestData() + private function mockPageColumnNotSelectMultiRequestData(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5440,13 +5398,7 @@ private function mockPageColumnNotSelectMultiRequestData() ->with($this->gridHash, [Grid::REQUEST_QUERY_PAGE => $page]); } - /** - * @param string $columnId - * @param string $order - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function mockOrderRequestData($columnId, $order) + private function mockOrderRequestData(string $columnId, string $order): MockObject { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -5468,7 +5420,7 @@ private function mockOrderRequestData($columnId, $order) return $column; } - private function mockOrderColumnNotSortable() + private function mockOrderColumnNotSortable(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -5499,7 +5451,7 @@ private function mockOrderColumnNotSortable() ->with($this->gridHash, [Grid::REQUEST_QUERY_PAGE => 0]); } - private function mockConfiguredLimitRequestData() + private function mockConfiguredLimitRequestData(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5520,7 +5472,7 @@ private function mockConfiguredLimitRequestData() ->with($this->gridHash, [Grid::REQUEST_QUERY_LIMIT => $limit, Grid::REQUEST_QUERY_PAGE => 0]); } - private function mockNonConfiguredLimitRequestData() + private function mockNonConfiguredLimitRequestData(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -5534,7 +5486,7 @@ private function mockNonConfiguredLimitRequestData() ->with($this->gridHash, [Grid::REQUEST_QUERY_PAGE => 0]); } - private function mockDefaultSessionFiltersWithoutRequestData() + private function mockDefaultSessionFiltersWithoutRequestData(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -5602,30 +5554,17 @@ private function mockDefaultSessionFiltersWithoutRequestData() ]); } - /** - * @param string $col1Id - * @param string $col2Id - * @param string $col3Id - * @param string $col4Id - * @param string $col5Id - * @param string $col1FilterValue - * @param array $col2FilterValue - * @param string $col5From - * @param string $col5To - * - * @return array - */ private function arrangeColumnsFilters( - $col1Id, - $col2Id, - $col3Id, - $col4Id, - $col5Id, - $col1FilterValue, - $col2FilterValue, - $col5From, - $col5To - ) { + string $col1Id, + string $col2Id, + string $col3Id, + string $col4Id, + string $col5Id, + string|array $col1FilterValue, + string|array $col2FilterValue, + string $col5From, + string $col5To + ): array { $column1 = $this->stubColumn($col1Id); $this->grid->addColumn($column1); @@ -5665,7 +5604,7 @@ private function arrangeColumnsFilters( return [$column1, $column2, $column3, $column4, $column5]; } - private function mockDefaultPage() + private function mockDefaultPage(): void { $row = $this->createMock(Row::class); $rows = new Rows(); @@ -5686,7 +5625,7 @@ private function mockDefaultPage() /** * @param string $order */ - private function mockDefaultOrder($order) + private function mockDefaultOrder(string $order): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); @@ -5711,7 +5650,7 @@ private function mockDefaultOrder($order) ->with($this->gridHash, [Grid::REQUEST_QUERY_ORDER => "$columnId|$order"]); } - private function mockDefaultLimit() + private function mockDefaultLimit(): void { $this->arrangeGridSourceDataLoadedWithEmptyRows(); $this->arrangeGridPrimaryColumn(); @@ -5727,13 +5666,7 @@ private function mockDefaultLimit() ->with($this->gridHash, [Grid::REQUEST_QUERY_LIMIT => $limit]); } - /** - * @param int $totalCount - * @param string $sourceHash - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function arrangeGridSourceDataLoadedWithEmptyRows($totalCount = 0, $sourceHash = null) + private function arrangeGridSourceDataLoadedWithEmptyRows(?int $totalCount = 0, ?string $sourceHash = null): MockObject { $source = $this->createMock(Source::class); $source @@ -5774,12 +5707,7 @@ private function arrangeGridSourceDataLoadedWithRows(Rows $rows, $totalCount = 0 $this->grid->setSource($source); } - /** - * @param int $totalCount - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function arrangeGridSourceDataLoadedWithoutRowsReturned($totalCount = 0) + private function arrangeGridSourceDataLoadedWithoutRowsReturned(int $totalCount = 0): MockObject { $source = $this->createMock(Source::class); $source @@ -5794,10 +5722,7 @@ private function arrangeGridSourceDataLoadedWithoutRowsReturned($totalCount = 0) return $source; } - /** - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function arrangeGridSourceDataNotLoadedWithoutRowsReturned() + private function arrangeGridSourceDataNotLoadedWithoutRowsReturned(): MockObject { $source = $this->createMock(Source::class); $source @@ -5812,12 +5737,7 @@ private function arrangeGridSourceDataNotLoadedWithoutRowsReturned() return $source; } - /** - * @param int $totalCount - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function arrangeGridSourceDataNotLoadedWithEmptyRows($totalCount = 0) + private function arrangeGridSourceDataNotLoadedWithEmptyRows(?int $totalCount = 0): MockObject { $source = $this->createMock(Source::class); $source @@ -5862,12 +5782,7 @@ private function stubPrimaryColumn() return $column; } - /** - * @param string $columnId - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function stubFilteredColumn($columnId = null) + private function stubFilteredColumn(int|string|null $columnId = null): MockObject { $column = $this->stubColumn($columnId); $column @@ -5877,12 +5792,7 @@ private function stubFilteredColumn($columnId = null) return $column; } - /** - * @param mixed $columnId - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function stubTitledColumn($columnId = null) + private function stubTitledColumn(int|string|null $columnId = null): MockObject { $column = $this->stubColumn($columnId); $column @@ -5892,13 +5802,7 @@ private function stubTitledColumn($columnId = null) return $column; } - /** - * @param string $type - * @param mixed $columnId - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function stubFilterableColumn($type, $columnId = null) + private function stubFilterableColumn(string $type, int|string|null $columnId = null): MockObject { $column = $this->stubColumn($columnId); $column @@ -5911,13 +5815,7 @@ private function stubFilterableColumn($type, $columnId = null) return $column; } - /** - * @param string $defaultOp - * @param mixed $columnId - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function stubColumnWithDefaultOperator($defaultOp, $columnId = null) + private function stubColumnWithDefaultOperator(string $defaultOp, int|string|null $columnId = null): MockObject { $column = $this->stubColumn($columnId); $column @@ -5927,12 +5825,7 @@ private function stubColumnWithDefaultOperator($defaultOp, $columnId = null) return $column; } - /** - * @param mixed $columnId - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function stubColumn($columnId = null) + private function stubColumn(int|string|null $columnId = null): MockObject { $column = $this ->getMockBuilder(Column::class) @@ -5945,10 +5838,7 @@ private function stubColumn($columnId = null) return $column; } - /** - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function arrangeGridWithColumnsIterator() + private function arrangeGridWithColumnsIterator(): MockObject { $column = $this->stubColumn('primaryID'); @@ -5992,12 +5882,7 @@ private function stubMassActionWithCallback($aCallback, array $params = []) return $massAction; } - /** - * @param string $role - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function stubMassAction($role = null) + private function stubMassAction(?string $role = null): MockObject { // @todo: It seems that MassActionInterface does not have getRole in it. is that fine? $massAction = $this @@ -6011,13 +5896,7 @@ private function stubMassAction($role = null) return $massAction; } - /** - * @param string $role - * @param mixed $colId - * - * @return \PHPUnit\Framework\MockObject\MockObject - */ - private function stubRowAction($role = null, $colId = null) + private function stubRowAction(?string $role = null, int|string|null $colId = null): MockObject { // @todo: It seems that RowActionInterface does not have getRole in it. is that fine? $rowAction = $this @@ -6034,10 +5913,7 @@ private function stubRowAction($role = null, $colId = null) return $rowAction; } - /** - * @param array $requestData - */ - private function stubRequestWithData(array $requestData) + private function stubRequestWithData(array $requestData): void { $this ->request @@ -6046,12 +5922,7 @@ private function stubRequestWithData(array $requestData) ->willReturn($requestData); } - /** - * @param int $tweakPage - * - * @return array - */ - private function arrangeDefaultTweaks($tweakPage) + private function arrangeDefaultTweaks(int $tweakPage): array { $group = 'aGroup'; $title = 'aTweak'; diff --git a/tests/Grid/Helper/ColumnsIteratorTest.php b/tests/Grid/Helper/ColumnsIteratorTest.php index 3aeb2fb..64c24c5 100644 --- a/tests/Grid/Helper/ColumnsIteratorTest.php +++ b/tests/Grid/Helper/ColumnsIteratorTest.php @@ -4,14 +4,14 @@ use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Helper\ColumnsIterator; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class ColumnsIteratorTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $iterator; + private MockObject $iterator; - public function testAcceptAnyColumn() + public function testAcceptAnyColumn(): void { $this->setUpMocks(); $columnsIterator = new ColumnsIterator($this->iterator, false); @@ -19,7 +19,7 @@ public function testAcceptAnyColumn() $this->assertTrue($columnsIterator->accept()); } - public function testAcceptSourceColumnThatsVisibile() + public function testAcceptSourceColumnThatsVisibile(): void { $this->setUpMocks(true); $columnsIterator = new ColumnsIterator($this->iterator, true); @@ -27,7 +27,7 @@ public function testAcceptSourceColumnThatsVisibile() $this->assertTrue($columnsIterator->accept()); } - public function testNotAcceptSourceColumnThatsNotVisibile() + public function testNotAcceptSourceColumnThatsNotVisibile(): void { $this->setUpMocks(false); $columnsIterator = new ColumnsIterator($this->iterator, true); @@ -35,14 +35,11 @@ public function testNotAcceptSourceColumnThatsNotVisibile() $this->assertFalse($columnsIterator->accept()); } - /** - * @param null|bool $isVisibleForSource - */ - protected function setUpMocks($isVisibleForSource = null) + protected function setUpMocks(?bool $isVisibleForSource = null): void { $column = $this->getMockBuilder(Column::class) - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); if (null === $isVisibleForSource) { $column->expects($this->never())->method('isVisibleForSource'); @@ -51,8 +48,8 @@ protected function setUpMocks($isVisibleForSource = null) } $this->iterator = $this->getMockBuilder(\Iterator::class) - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $this->iterator->expects($this->any())->method('current')->willReturn($column); } } diff --git a/tests/Grid/Mapping/ColumnTest.php b/tests/Grid/Mapping/ColumnTest.php index c8f70f6..ec1ab93 100644 --- a/tests/Grid/Mapping/ColumnTest.php +++ b/tests/Grid/Mapping/ColumnTest.php @@ -13,20 +13,20 @@ public function setUp(): void $this->arrayMetadata = ['foo' => 'bar', 'groups' => 'baz']; } - public function testColumnMetadataCanBeEmpty() + public function testColumnMetadataCanBeEmpty(): void { $column = new Column([]); $this->assertEmpty($column->getMetadata()); $this->assertSame(['default'], $column->getGroups()); } - public function testColumnStringMetadataInjectedInConstructor() + public function testColumnStringMetadataInjectedInConstructor(): void { $column = new Column($this->stringMetadata); $this->assertSame($this->stringMetadata, $column->getMetadata()); } - public function testColumnArrayMetadataInjectedInConstructor() + public function testColumnArrayMetadataInjectedInConstructor(): void { $column = new Column($this->arrayMetadata); $this->assertSame($this->arrayMetadata, $column->getMetadata()); diff --git a/tests/Grid/Mapping/Metadata/DriverHeapTest.php b/tests/Grid/Mapping/Metadata/DriverHeapTest.php index 0874bd6..5859a93 100644 --- a/tests/Grid/Mapping/Metadata/DriverHeapTest.php +++ b/tests/Grid/Mapping/Metadata/DriverHeapTest.php @@ -7,7 +7,7 @@ class DriverHeapTest extends TestCase { - public function testCompareOk() + public function testCompareOk(): void { $priority1 = $priority2 = 1; @@ -16,7 +16,7 @@ public function testCompareOk() $this->assertEquals(0, $driverHeap->compare($priority1, $priority2)); } - public function testPriority1MoreThanPriority2() + public function testPriority1MoreThanPriority2(): void { $priority1 = 100; $priority2 = 1; @@ -26,7 +26,7 @@ public function testPriority1MoreThanPriority2() $this->assertEquals(-1, $driverHeap->compare($priority1, $priority2)); } - public function testPriority1LessThanPriority2() + public function testPriority1LessThanPriority2(): void { $priority1 = 1; $priority2 = 100; diff --git a/tests/Grid/Mapping/Metadata/ManagerTest.php b/tests/Grid/Mapping/Metadata/ManagerTest.php index 4844505..9d97f2d 100644 --- a/tests/Grid/Mapping/Metadata/ManagerTest.php +++ b/tests/Grid/Mapping/Metadata/ManagerTest.php @@ -15,7 +15,7 @@ public function setUp(): void $this->manager = new Manager(); } - public function testAddDriver() + public function testAddDriver(): void { $driverInterfaceMock = $this->createMock(DriverInterface::class); $priority = 1; @@ -28,7 +28,7 @@ public function testAddDriver() $this->assertEquals($driverHeap, $this->manager->getDrivers()); } - public function testGetDrivers() + public function testGetDrivers(): void { $driverInterfaceMock = $this->createMock(DriverInterface::class); @@ -42,7 +42,7 @@ public function testGetDrivers() $this->assertEquals($driverHeap, $drivers); } - public function testGetDriversReturnDifferentClone() + public function testGetDriversReturnDifferentClone(): void { $driverFirstTime = $this->manager->getDrivers(); $driverSecondTime = $this->manager->getDrivers(); @@ -50,7 +50,7 @@ public function testGetDriversReturnDifferentClone() $this->assertNotSame($driverFirstTime, $driverSecondTime); } - public function testGetMetadataWithoutDrivers() + public function testGetMetadataWithoutDrivers(): void { $cols = []; $mappings = []; @@ -66,7 +66,7 @@ public function testGetMetadataWithoutDrivers() $this->assertEquals($metadataExpected, $metadata); } - public function testGetMetadata() + public function testGetMetadata(): void { $fields = ['0' => 'bar']; $groupBy = ['foo' => 'bar']; diff --git a/tests/Grid/Mapping/Metadata/MetadataTest.php b/tests/Grid/Mapping/Metadata/MetadataTest.php index 91d0e38..e312a0b 100644 --- a/tests/Grid/Mapping/Metadata/MetadataTest.php +++ b/tests/Grid/Mapping/Metadata/MetadataTest.php @@ -14,7 +14,7 @@ public function setUp(): void $this->metadata = new Metadata(); } - public function testGetFields() + public function testGetFields(): void { $field = ['foo' => 'bar']; @@ -23,7 +23,7 @@ public function testGetFields() $this->assertEquals($field, $this->metadata->getFields()); } - public function testHasFieldMappingWithField() + public function testHasFieldMappingWithField(): void { $field = 'foo'; $value = 'bar'; @@ -35,7 +35,7 @@ public function testHasFieldMappingWithField() $this->assertFalse($this->metadata->hasFieldMapping('notAddedField')); } - public function testGetterFieldMappingReturnDefaultTypeText() + public function testGetterFieldMappingReturnDefaultTypeText(): void { $field = 'foo'; $value = 'bar'; @@ -46,7 +46,7 @@ public function testGetterFieldMappingReturnDefaultTypeText() $this->assertEquals('text', $this->metadata->getFieldMappingType($field)); } - public function testGetterMappingFieldWithType() + public function testGetterMappingFieldWithType(): void { $field = 'foo'; $value = 'bar'; @@ -56,7 +56,7 @@ public function testGetterMappingFieldWithType() $this->assertEquals($value, $this->metadata->getFieldMappingType($field)); } - public function testGetterGroupBy() + public function testGetterGroupBy(): void { $groupBy = 'groupBy'; @@ -64,7 +64,7 @@ public function testGetterGroupBy() $this->assertEquals($groupBy, $this->metadata->getGroupBy()); } - public function testGetterName() + public function testGetterName(): void { $name = 'name'; @@ -73,7 +73,7 @@ public function testGetterName() $this->assertEquals($name, $this->metadata->getName()); } - public function testGetColumnsFromMappingWithoutTypeReturnException() + public function testGetColumnsFromMappingWithoutTypeReturnException(): void { $this->expectException(\Exception::class); @@ -91,7 +91,7 @@ public function testGetColumnsFromMappingWithoutTypeReturnException() $this->metadata->getColumnsFromMapping($columnsMock); } - public function testGetColumnsFromMapping() + public function testGetColumnsFromMapping(): void { $field = 'foo'; $field2 = 'foo2'; diff --git a/tests/Grid/Mapping/SourceTest.php b/tests/Grid/Mapping/SourceTest.php index 9bc0085..98a93ba 100644 --- a/tests/Grid/Mapping/SourceTest.php +++ b/tests/Grid/Mapping/SourceTest.php @@ -12,34 +12,34 @@ public function setUp(): void $this->source = new Source([]); } - public function testColumnsHasDefaultValue() + public function testColumnsHasDefaultValue(): void { $this->assertSame([], $this->source->getColumns()); } - public function testFilterableHasDefaultValue() + public function testFilterableHasDefaultValue(): void { $this->assertTrue($this->source->isFilterable()); } - public function testSortableHasDefaultValue() + public function testSortableHasDefaultValue(): void { $this->assertTrue($this->source->isSortable()); } - public function testGroupsHasDefaultValue() + public function testGroupsHasDefaultValue(): void { $expectedGroups = ['0' => 'default']; $this->assertSame($expectedGroups, $this->source->getGroups()); } - public function testGroupByHasDefaultValue() + public function testGroupByHasDefaultValue(): void { $this->assertSame([], $this->source->getGroupBy()); } - public function testGetterColumns() + public function testGetterColumns(): void { $columns = 'columns'; $expectedColumns = [$columns]; @@ -49,7 +49,7 @@ public function testGetterColumns() $this->assertEquals($expectedColumns, $this->source->getColumns()); } - public function testGetterHasColumns() + public function testGetterHasColumns(): void { $columns = 'columns'; @@ -58,7 +58,7 @@ public function testGetterHasColumns() $this->assertTrue($this->source->hasColumns()); } - public function testGetterFilterable() + public function testGetterFilterable(): void { $filterable = false; @@ -67,7 +67,7 @@ public function testGetterFilterable() $this->assertEquals($filterable, $this->source->isFilterable()); } - public function testGetterSortable() + public function testGetterSortable(): void { $sortable = false; @@ -76,7 +76,7 @@ public function testGetterSortable() $this->assertFalse($this->source->isSortable()); } - public function testGetterGroups() + public function testGetterGroups(): void { $groups = 'groups'; $expectedGroups = [$groups]; @@ -86,7 +86,7 @@ public function testGetterGroups() $this->assertEquals($expectedGroups, $this->source->getGroups()); } - public function testGetterGroupBy() + public function testGetterGroupBy(): void { $groupsBy = 'groupBy'; $expectedGroupsBy = [$groupsBy]; diff --git a/tests/Grid/RowTest.php b/tests/Grid/RowTest.php index 3e0cede..55a97c6 100644 --- a/tests/Grid/RowTest.php +++ b/tests/Grid/RowTest.php @@ -8,15 +8,14 @@ class RowTest extends TestCase { - /** @var Row */ - private $row; + private Row $row; public function setUp(): void { $this->row = new Row(); } - public function testSetRepository() + public function testSetRepository(): void { $repo = $this->createMock(EntityRepository::class); $this->row->setRepository($repo); @@ -24,7 +23,7 @@ public function testSetRepository() $this->assertEquals($repo, $this->row->getRepository()); } - public function testSetPrimaryField() + public function testSetPrimaryField(): void { $pf = 'id'; $this->row->setPrimaryField($pf); @@ -32,7 +31,7 @@ public function testSetPrimaryField() $this->assertSame($pf, $this->row->getPrimaryField()); } - public function testGetPrimaryField() + public function testGetPrimaryField(): void { $pf = 'id'; $this->row->setPrimaryField($pf); @@ -40,7 +39,7 @@ public function testGetPrimaryField() $this->assertEquals($pf, $this->row->getPrimaryField()); } - public function testSetField() + public function testSetField(): void { $field1Id = 'col1'; $field1Val = 'col1_val'; @@ -54,7 +53,7 @@ public function testSetField() $this->assertSame([$field1Id => $field1Val, $field2Id => $field2Val], $this->row->getFields()); } - public function testGetField() + public function testGetField(): void { $field = 'col1'; $val = 'col1_val'; @@ -65,14 +64,14 @@ public function testGetField() $this->assertEmpty($this->row->getField('col2')); } - public function testGetPrimaryFieldValueWithoutDefiningIt() + public function testGetPrimaryFieldValueWithoutDefiningIt(): void { $this->expectException(\InvalidArgumentException::class); $this->row->getPrimaryFieldValue(); } - public function testGetPrimaryFieldValueWithoutAddingItToFields() + public function testGetPrimaryFieldValueWithoutAddingItToFields(): void { $this->expectException(\InvalidArgumentException::class); @@ -86,7 +85,7 @@ public function testGetPrimaryFieldValueWithoutAddingItToFields() $this->row->getPrimaryFieldValue(); } - public function testGetSinglePrimaryFieldValue() + public function testGetSinglePrimaryFieldValue(): void { $field = 'id'; $value = 1; @@ -98,7 +97,7 @@ public function testGetSinglePrimaryFieldValue() $this->assertEquals($value, $this->row->getPrimaryFieldValue()); } - public function testGetArrayPrimaryFieldsValue() + public function testGetArrayPrimaryFieldsValue(): void { $field1 = 'id'; $value1 = 1; @@ -113,7 +112,7 @@ public function testGetArrayPrimaryFieldsValue() $this->assertEquals([$field1 => $value1, $field2 => $value2], $this->row->getPrimaryFieldValue()); } - public function testGetSinglePrimaryKeyValue() + public function testGetSinglePrimaryKeyValue(): void { $field = 'foo'; $value = 1; @@ -125,7 +124,7 @@ public function testGetSinglePrimaryKeyValue() $this->assertEquals(['id' => $value], $this->row->getPrimaryKeyValue()); } - public function testGetCompositePrimaryKeyValue() + public function testGetCompositePrimaryKeyValue(): void { $field1 = 'foo'; $value1 = 1; @@ -140,7 +139,7 @@ public function testGetCompositePrimaryKeyValue() $this->assertEquals([$field1 => $value1, $field2 => $value2], $this->row->getPrimaryKeyValue()); } - public function testGetEntity() + public function testGetEntity(): void { $field = 'foo'; $value = 1; @@ -160,7 +159,7 @@ public function testGetEntity() $this->assertSame($entityDummy, $this->row->getEntity()); } - public function testGetClass() + public function testGetClass(): void { $class = 'Vendor/Bundle/Foo'; $this->row->setClass($class); @@ -168,7 +167,7 @@ public function testGetClass() $this->assertEquals($class, $this->row->getClass()); } - public function testGetColor() + public function testGetColor(): void { $color = 'blue'; $this->row->setColor($color); @@ -176,7 +175,7 @@ public function testGetColor() $this->assertEquals($color, $this->row->getColor()); } - public function testGetLegend() + public function testGetLegend(): void { $legend = 'bar'; $this->row->setLegend($legend); diff --git a/tests/Grid/RowsTest.php b/tests/Grid/RowsTest.php index 17610c7..14ead86 100644 --- a/tests/Grid/RowsTest.php +++ b/tests/Grid/RowsTest.php @@ -8,11 +8,9 @@ class RowsTest extends TestCase { - /** @var Rows */ - private $rowsSUT; + private Rows $rowsSUT; - /** @var array */ - private $rows; + private array $rows; public function setUp(): void { @@ -20,23 +18,23 @@ public function setUp(): void $this->rowsSUT = new Rows($this->rows); } - public function testAddRowsOnConstruct() + public function testAddRowsOnConstruct(): void { $this->assertEquals(3, $this->rowsSUT->count()); } - public function testGetIterator() + public function testGetIterator(): void { $this->assertInstanceOf(\SplObjectStorage::class, $this->rowsSUT->getIterator()); } - public function testAddRow() + public function testAddRow(): void { $this->rowsSUT->addRow($this->createMock(Row::class)); $this->assertEquals(4, $this->rowsSUT->count()); } - public function testToArray() + public function testToArray(): void { $this->assertEquals($this->rows, $this->rowsSUT->toArray()); } diff --git a/tests/Grid/Source/VectorTest.php b/tests/Grid/Source/VectorTest.php index d4c52a4..66421d5 100644 --- a/tests/Grid/Source/VectorTest.php +++ b/tests/Grid/Source/VectorTest.php @@ -13,36 +13,33 @@ class VectorTest extends TestCase { - /** - * @var Vector - */ - private $vector; + private Vector $vector; public function setUp(): void { $this->vector = new Vector([], []); } - public function testCreateVectorWithEmptyData() + public function testCreateVectorWithEmptyData(): void { $this->assertEmpty($this->vector->getData()); } - public function testRaiseExceptionDuringVectorCreationWhenDataIsNotAVector() + public function testRaiseExceptionDuringVectorCreationWhenDataIsNotAVector(): void { $this->expectException(\InvalidArgumentException::class); new Vector(['notAnArray'], []); } - public function testRaiseExceptionDuringVectorCreationWhenEmptyVector() + public function testRaiseExceptionDuringVectorCreationWhenEmptyVector(): void { $this->expectException(\InvalidArgumentException::class); new Vector([[]], []); } - public function testCreateVectorWithColumns() + public function testCreateVectorWithColumns(): void { $column = $this->createMock(Column::class); $column2 = $this->createMock(Column::class); @@ -53,14 +50,14 @@ public function testCreateVectorWithColumns() $this->assertEquals($columns, $vector->getColumnsArray()); } - public function testInitialiseWithoutData() + public function testInitialiseWithoutData(): void { $this->vector->initialise($this->createMock(ManagerRegistry::class), $this->createMock(Manager::class)); $this->assertEmpty($this->vector->getColumnsArray()); } - public function testInizialiseWithGuessedColumnsMergedToAlreadySettedColumns() + public function testInizialiseWithGuessedColumnsMergedToAlreadySettedColumns(): void { $columnId = 'cId'; $column = $this->createMock(Column::class); @@ -108,7 +105,7 @@ public function testInizialiseWithGuessedColumnsMergedToAlreadySettedColumns() $this->assertEquals([$column, $column2, $uc1, $uc2], $vector->getColumnsArray()); } - public function testInizialiseWithoutGuessedColumns() + public function testInizialiseWithoutGuessedColumns(): void { $columnId = 'cId'; $column = $this->createMock(Column::class); @@ -132,7 +129,7 @@ public function testInizialiseWithoutGuessedColumns() /** * @dataProvider guessedColumnProvider */ - public function testInizializeWithGuessedColumn($vectorValue, UntypedColumn $untypedColumn, $columnType) + public function testInizializeWithGuessedColumn(array $vectorValue, UntypedColumn $untypedColumn, string $columnType): void { $untypedColumn->setType($columnType); @@ -142,7 +139,7 @@ public function testInizializeWithGuessedColumn($vectorValue, UntypedColumn $unt $this->assertEquals([$untypedColumn], $vector->getColumnsArray()); } - public function testExecute() + public function testExecute(): void { $rows = [new Row(), new Row()]; $columns = $this->createMock(Columns::class); @@ -156,7 +153,7 @@ public function testExecute() $this->assertEquals($rows, $vector->execute($columns, 0, null, null)); } - public function testPopulateSelectFilters() + public function testPopulateSelectFilters(): void { $columns = $this->createMock(Columns::class); @@ -169,7 +166,7 @@ public function testPopulateSelectFilters() $vector->populateSelectFilters($columns); } - public function testGetTotalCount() + public function testGetTotalCount(): void { $maxResults = 10; @@ -182,7 +179,7 @@ public function testGetTotalCount() $this->assertEquals(8, $vector->getTotalCount($maxResults)); } - public function testGetHash() + public function testGetHash(): void { $idCol1 = 'idCol1'; $column1 = $this->createMock(Column::class); @@ -201,7 +198,7 @@ public function testGetHash() $this->assertEquals('APY\DataGridBundle\Grid\Source\Vector' . md5($idCol1 . $idCol2), $vector->getHash()); } - public function testId() + public function testId(): void { $id = 'id'; $this->vector->setId($id); @@ -209,7 +206,7 @@ public function testId() $this->assertEquals($id, $this->vector->getId()); } - public function guessedColumnProvider() + public function guessedColumnProvider(): array { $uc = new UntypedColumn( [ diff --git a/tests/Test.php b/tests/Test.php index 3caa11e..7c46936 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -6,7 +6,7 @@ class Test extends TestCase { - public function testPHPUnit() + public function testPHPUnit(): void { $this->assertTrue(true); } diff --git a/tests/Twig/DataGridExtensionTest.php b/tests/Twig/DataGridExtensionTest.php index 47b3429..6f68b4c 100644 --- a/tests/Twig/DataGridExtensionTest.php +++ b/tests/Twig/DataGridExtensionTest.php @@ -16,10 +16,7 @@ */ class DataGridExtensionTest extends TestCase { - /** - * @var DataGridExtension - */ - private $extension; + private DataGridExtension $extension; public function setUp(): void { @@ -27,7 +24,7 @@ public function setUp(): void $this->extension = new DataGridExtension($router, ''); } - public function testGetGridUrl() + public function testGetGridUrl(): void { $baseUrl = 'https://localhost'; $gridHash = 'my_grid'; From ad970e157e13401bb0f737f8687a27f016f96692 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 22 Mar 2023 10:14:33 -0400 Subject: [PATCH 22/38] Clean up --- src/Grid/Action/MassAction.php | 6 +++--- src/Grid/Action/RowAction.php | 10 +--------- src/Grid/Column/DateTimeColumn.php | 4 ++-- .../manipulate_row_action_rendering.md | 8 ++++---- src/Twig/DataGridExtension.php | 4 +++- tests/Grid/Action/RowActionTest.php | 4 ++-- 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/Grid/Action/MassAction.php b/src/Grid/Action/MassAction.php index 34ef863..54b8ffd 100644 --- a/src/Grid/Action/MassAction.php +++ b/src/Grid/Action/MassAction.php @@ -28,7 +28,7 @@ class MassAction implements MassActionInterface public function __construct( string $title, - ?string $callback = null, + \Closure|string|null $callback = null, bool $confirm = false, array $parameters = [], ?string $role = null @@ -53,7 +53,7 @@ public function getTitle(): string return $this->title; } - public function setCallback(\Closure|string $callback): self + public function setCallback(\Closure|string|null $callback): self { $this->callback = $callback; @@ -101,7 +101,7 @@ public function getParameters(): array return $this->parameters; } - public function setRole(string $role): self + public function setRole(?string $role): self { $this->role = $role; diff --git a/src/Grid/Action/RowAction.php b/src/Grid/Action/RowAction.php index ec7c2ce..2bd55dd 100644 --- a/src/Grid/Action/RowAction.php +++ b/src/Grid/Action/RowAction.php @@ -187,7 +187,7 @@ public function getAttributes(): array return $this->attributes; } - public function setRole(string $role): self + public function setRole(?string $role): self { $this->role = $role; @@ -199,14 +199,6 @@ public function getRole(): ?string return $this->role; } - /** - * @deprecated This is deprecated and will be removed in 3.0; use addManipulateRender instead. - */ - public function manipulateRender(\Closure $callback) - { - return $this->addManipulateRender($callback); - } - public function addManipulateRender(\Closure $callback): self { $this->callbacks[] = $callback; diff --git a/src/Grid/Column/DateTimeColumn.php b/src/Grid/Column/DateTimeColumn.php index 70a8846..5c8d2d1 100644 --- a/src/Grid/Column/DateTimeColumn.php +++ b/src/Grid/Column/DateTimeColumn.php @@ -89,7 +89,7 @@ public function renderCell(mixed $value, Row $row, RouterInterface $router): mix return $value; } - public function getDisplayedValue(\Datetime|\DateTimeImmutable|string|int $value): string + public function getDisplayedValue(\DateTimeInterface|string|int $value): string { if (!empty($value)) { $dateTime = $this->getDatetime($value, new \DateTimeZone($this->getTimezone())); @@ -115,7 +115,7 @@ public function getDisplayedValue(\Datetime|\DateTimeImmutable|string|int $value return ''; } - protected function getDatetime(\Datetime|\DateTimeImmutable|string|int $data, \DateTimeZone $timezone): \DateTimeInterface + protected function getDatetime(\DateTimeInterface|string|int $data, \DateTimeZone $timezone): \DateTimeInterface { if ($data instanceof \DateTime || $data instanceof \DateTimeImmutable) { return $data->setTimezone($timezone); diff --git a/src/Resources/doc/grid_configuration/manipulate_row_action_rendering.md b/src/Resources/doc/grid_configuration/manipulate_row_action_rendering.md index 730745a..a4772f1 100644 --- a/src/Resources/doc/grid_configuration/manipulate_row_action_rendering.md +++ b/src/Resources/doc/grid_configuration/manipulate_row_action_rendering.md @@ -9,13 +9,13 @@ If the callback returns `null` or don't return the action, the action won't be d ```php manipulateRender($callback); +$rowAction->addManipulateRender($callback); $grid->addRowAction($rowAction); ... ``` -## Method RowAction::manipulateRender parameters +## Method RowAction::addManipulateRender parameters |parameter|Type|Default value|Description| |:--:|:--|:--|:--|:--| @@ -38,7 +38,7 @@ If the action is disabled, only its title is displayed, with all additional attr ```php manipulateRender( +$rowAction->addManipulateRender( function ($action, $row) { if ($row->getField('quantity') == 0) { @@ -59,4 +59,4 @@ $rowAction->manipulateRender( $grid->addRowAction($rowAction); ... -``` \ No newline at end of file +``` diff --git a/src/Twig/DataGridExtension.php b/src/Twig/DataGridExtension.php index 452c658..a9660e1 100644 --- a/src/Twig/DataGridExtension.php +++ b/src/Twig/DataGridExtension.php @@ -216,7 +216,7 @@ public function getGridColumnOperator(Environment $environment, Column $column, * * @return string|void */ - public function getGridUrl($section, Grid $grid, Column|string|int|null $param = null) + public function getGridUrl($section, Grid $grid, Column|string|int|null $param = null): ?string { $prefix = $grid->getRouteUrl() . (strpos($grid->getRouteUrl(), '?') ? '&' : '?') . $grid->getHash() . '['; @@ -236,6 +236,8 @@ public function getGridUrl($section, Grid $grid, Column|string|int|null $param = case 'export': return $prefix . Grid::REQUEST_QUERY_EXPORT . ']=' . $param; } + + return null; } public function getGridSearch(Environment $environment, Grid $grid, ?string $theme = null, string|int $id = '', array $params = []): string diff --git a/tests/Grid/Action/RowActionTest.php b/tests/Grid/Action/RowActionTest.php index e8e76c2..bc836d8 100644 --- a/tests/Grid/Action/RowActionTest.php +++ b/tests/Grid/Action/RowActionTest.php @@ -177,8 +177,8 @@ public function testManipulateRender(): void return 2; }; - $this->rowAction->manipulateRender($callback1); - $this->rowAction->manipulateRender($callback2); + $this->rowAction->addManipulateRender($callback1); + $this->rowAction->addManipulateRender($callback2); $this->assertSame([$callback1, $callback2], $this->rowAction->getCallbacks()); } From 4a75657476e1c3c58ca7d5bb6d936da2a45b4b45 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 22 Mar 2023 10:19:10 -0400 Subject: [PATCH 23/38] Update function definition --- src/Translation/ColumnTitleAnnotationTranslationExtractor.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Translation/ColumnTitleAnnotationTranslationExtractor.php b/src/Translation/ColumnTitleAnnotationTranslationExtractor.php index aacd942..ee42d5f 100644 --- a/src/Translation/ColumnTitleAnnotationTranslationExtractor.php +++ b/src/Translation/ColumnTitleAnnotationTranslationExtractor.php @@ -9,6 +9,7 @@ use JMS\TranslationBundle\Model\Message; use JMS\TranslationBundle\Model\MessageCatalogue; use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface; +use Twig\Node\Node; class ColumnTitleAnnotationTranslationExtractor implements FileVisitorInterface, \PHPParser_NodeVisitor { @@ -80,7 +81,7 @@ public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, ar } } - public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue): void + public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, Node $ast): void { } } From 3f6c58ede23e39b250aef1a950f29fac8c853eb5 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 22 Mar 2023 10:30:12 -0400 Subject: [PATCH 24/38] Update symfony version requirement --- composer.json | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index e700d67..0cebd63 100644 --- a/composer.json +++ b/composer.json @@ -7,27 +7,26 @@ "license": "MIT", "require": { "php": ">=8.0", - "symfony/form": "^5.2|^6.2", - "symfony/dependency-injection": "^5.2|^6.2", - "symfony/config": "^5.2|^6.2", - "symfony/http-foundation": "^5.2|^6.2", - "symfony/http-kernel": "^5.2|^6.2", - "symfony/options-resolver": "^5.2|^6.2", - "symfony/security-core": "^5.2|^6.2", - "symfony/serializer": "^5.2|^6.2", + "symfony/form": "^5.4|^6.2", + "symfony/dependency-injection": "^5.4|^6.2", + "symfony/config": "^5.4|^6.2", + "symfony/http-foundation": "^5.4|^6.2", + "symfony/http-kernel": "^5.4|^6.2", + "symfony/options-resolver": "^5.4|^6.2", + "symfony/security-core": "^5.4|^6.2", + "symfony/serializer": "^5.4|^6.2", "twig/twig": "^2.4|^3.0", - "symfony/translation": "^5.2|^6.2", + "symfony/translation": "^5.4|^6.2", "jms/translation-bundle": "^1.8", "doctrine/annotations": "^2.0" }, "require-dev": { "ext-intl": "*", "dg/bypass-finals": "^1.2", - "symfony/framework-bundle": "^5.2|^6.2", - "symfony/expression-language": "^5.2|^6.2", - "symfony/phpunit-bridge": "^5.2|^6.2", - "phpunit/phpunit": "^9.5", - "doctrine/orm": "~2.4,>=2.4.5" + "symfony/framework-bundle": "^5.4|^6.2", + "symfony/expression-language": "^5.4|^6.2", + "symfony/phpunit-bridge": "^5.4|^6.2", + "phpunit/phpunit": "^9.5" }, "suggest": { "ext-intl": "Translate the grid", From 421a23d481c68c68272e3c9186332f75da2e45f2 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 29 Mar 2023 10:15:57 -0400 Subject: [PATCH 25/38] Add a conflict and remove code that checks against an old version of doctrine/orm --- composer.json | 3 +++ src/Grid/Column/Column.php | 18 ------------------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 0cebd63..32bd5a6 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,9 @@ "PHPExcel": "Export the grid (Excel, HTML or PDF)", "doctrine/orm": "If you want to use Entity as source, please require doctrine/orm" }, + "conflict": { + "doctrime/orm": "<2.6" + }, "autoload": { "psr-4": { "APY\\DataGridBundle\\": "src" diff --git a/src/Grid/Column/Column.php b/src/Grid/Column/Column.php index 0b9f626..ba293aa 100644 --- a/src/Grid/Column/Column.php +++ b/src/Grid/Column/Column.php @@ -14,7 +14,6 @@ use APY\DataGridBundle\Grid\Filter; use APY\DataGridBundle\Grid\Row; -use Doctrine\ORM\Version; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -641,23 +640,6 @@ public function setOperators(?array $operators): self public function getOperators(): array { - // Issue with Doctrine - // ------------------- - // @see http://www.doctrine-project.org/jira/browse/DDC-1857 - // @see http://www.doctrine-project.org/jira/browse/DDC-1858 - if ($this->hasDQLFunction() && version_compare(Version::VERSION, '2.5') < 0) { - return array_intersect($this->operators, [ - self::OPERATOR_EQ, - self::OPERATOR_NEQ, - self::OPERATOR_LT, - self::OPERATOR_LTE, - self::OPERATOR_GT, - self::OPERATOR_GTE, - self::OPERATOR_BTW, - self::OPERATOR_BTWE, - ]); - } - return $this->operators; } From 4b7e7332cd606a7781a69d6f735f0b14f07f20d6 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 29 Mar 2023 10:18:52 -0400 Subject: [PATCH 26/38] Remove unnecessary phpdco --- src/Twig/DataGridExtension.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Twig/DataGridExtension.php b/src/Twig/DataGridExtension.php index a9660e1..2ffc765 100644 --- a/src/Twig/DataGridExtension.php +++ b/src/Twig/DataGridExtension.php @@ -209,14 +209,7 @@ public function getGridColumnOperator(Environment $environment, Column $column, return $this->renderBlock($environment, 'grid_column_operator', ['grid' => $grid, 'column' => $column, 'submitOnChange' => $submitOnChange, 'op' => $operator]); } - /** - * @param string $section - * @param \APY\DataGridBundle\Grid\Grid $grid - * @param \APY\DataGridBundle\Grid\Column\Column $param - * - * @return string|void - */ - public function getGridUrl($section, Grid $grid, Column|string|int|null $param = null): ?string + public function getGridUrl(string $section, Grid $grid, Column|string|int|null $param = null): ?string { $prefix = $grid->getRouteUrl() . (strpos($grid->getRouteUrl(), '?') ? '&' : '?') . $grid->getHash() . '['; From c8d2df6176f3fdfa763881d9880113020ef6b6f7 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 29 Mar 2023 13:40:38 -0400 Subject: [PATCH 27/38] Remove conflict --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index 32bd5a6..0cebd63 100644 --- a/composer.json +++ b/composer.json @@ -34,9 +34,6 @@ "PHPExcel": "Export the grid (Excel, HTML or PDF)", "doctrine/orm": "If you want to use Entity as source, please require doctrine/orm" }, - "conflict": { - "doctrime/orm": "<2.6" - }, "autoload": { "psr-4": { "APY\\DataGridBundle\\": "src" From b53260be8958997440a62898a76767367211c522 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Tue, 4 Apr 2023 16:14:04 -0400 Subject: [PATCH 28/38] Return a string when rendering a cell --- src/Grid/Column/BooleanColumn.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grid/Column/BooleanColumn.php b/src/Grid/Column/BooleanColumn.php index 4193836..e70bdb2 100644 --- a/src/Grid/Column/BooleanColumn.php +++ b/src/Grid/Column/BooleanColumn.php @@ -47,7 +47,7 @@ public function renderCell(mixed $value, Row $row, RouterInterface $router): mix { $value = parent::renderCell($value, $row, $router); - return $value ? : false; + return $value ? : 'false'; } public function getDisplayedValue(mixed $value): mixed From 09332ecf3736d48e51e5966ca6e1e9b3ae756f5e Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Tue, 4 Apr 2023 16:18:07 -0400 Subject: [PATCH 29/38] Add conflict --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 0cebd63..32bd5a6 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,9 @@ "PHPExcel": "Export the grid (Excel, HTML or PDF)", "doctrine/orm": "If you want to use Entity as source, please require doctrine/orm" }, + "conflict": { + "doctrime/orm": "<2.6" + }, "autoload": { "psr-4": { "APY\\DataGridBundle\\": "src" From 91e5b247469b0d42f062ca51a9be8c9efd9b54b5 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Tue, 4 Apr 2023 16:22:30 -0400 Subject: [PATCH 30/38] Fix renderCell assertions --- tests/Grid/Column/BooleanColumnTest.php | 42 +++++++++++-------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/tests/Grid/Column/BooleanColumnTest.php b/tests/Grid/Column/BooleanColumnTest.php index ee8d447..185fa2c 100644 --- a/tests/Grid/Column/BooleanColumnTest.php +++ b/tests/Grid/Column/BooleanColumnTest.php @@ -33,22 +33,22 @@ public function testInitialize(): void { $params = [ 'filter' => 'foo', - 'bar' => 'bar', - 'size' => 52, + 'bar' => 'bar', + 'size' => 52, ]; $column = new BooleanColumn($params); $this->assertEquals( [ - 'filter' => 'select', - 'selectFrom' => 'values', - 'operators' => [Column::OPERATOR_EQ], - 'defaultOperator' => Column::OPERATOR_EQ, + 'filter' => 'select', + 'selectFrom' => 'values', + 'operators' => [Column::OPERATOR_EQ], + 'defaultOperator' => Column::OPERATOR_EQ, 'operatorsVisible' => false, - 'selectMulti' => false, - 'bar' => 'bar', - 'size' => 52, + 'selectMulti' => false, + 'bar' => 'bar', + 'size' => 52, ], $column->getParams() ); @@ -142,13 +142,11 @@ function ($value, $row, $router) { } ); - $this->assertFalse( - $this->column->renderCell( - 1, - $this->createMock(Row::class), - $this->createMock(Router::class) - ) - ); + $this->assertEquals('false', $this->column->renderCell( + 1, + $this->createMock(Row::class), + $this->createMock(Router::class) + )); $this->column->manipulateRenderCell( function ($value, $row, $router) { @@ -156,12 +154,10 @@ function ($value, $row, $router) { } ); - $this->assertFalse( - $this->column->renderCell( - 1, - $this->createMock(Row::class), - $this->createMock(Router::class) - ) - ); + $this->assertEquals('false', $this->column->renderCell( + 1, + $this->createMock(Row::class), + $this->createMock(Router::class) + )); } } From 126792dec756c6e003cd2c1300254d52b10401ff Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 5 Apr 2023 09:37:23 -0400 Subject: [PATCH 31/38] Add doctrine/orm to project dependencies --- composer.json | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 32bd5a6..abde10f 100644 --- a/composer.json +++ b/composer.json @@ -7,35 +7,32 @@ "license": "MIT", "require": { "php": ">=8.0", - "symfony/form": "^5.4|^6.2", - "symfony/dependency-injection": "^5.4|^6.2", - "symfony/config": "^5.4|^6.2", - "symfony/http-foundation": "^5.4|^6.2", - "symfony/http-kernel": "^5.4|^6.2", - "symfony/options-resolver": "^5.4|^6.2", - "symfony/security-core": "^5.4|^6.2", - "symfony/serializer": "^5.4|^6.2", + "symfony/form": "^5.2|^6.2", + "symfony/dependency-injection": "^5.2|^6.2", + "symfony/config": "^5.2|^6.2", + "symfony/http-foundation": "^5.2|^6.2", + "symfony/http-kernel": "^5.2|^6.2", + "symfony/options-resolver": "^5.2|^6.2", + "symfony/security-core": "^5.2|^6.2", + "symfony/serializer": "^5.2|^6.2", "twig/twig": "^2.4|^3.0", - "symfony/translation": "^5.4|^6.2", + "symfony/translation": "^5.2|^6.2", "jms/translation-bundle": "^1.8", - "doctrine/annotations": "^2.0" + "doctrine/annotations": "^2.0", + "doctrine/orm": "^2.13" }, "require-dev": { "ext-intl": "*", "dg/bypass-finals": "^1.2", - "symfony/framework-bundle": "^5.4|^6.2", - "symfony/expression-language": "^5.4|^6.2", - "symfony/phpunit-bridge": "^5.4|^6.2", + "symfony/framework-bundle": "^5.2|^6.2", + "symfony/expression-language": "^5.2|^6.2", + "symfony/phpunit-bridge": "^5.2|^6.2", "phpunit/phpunit": "^9.5" }, "suggest": { "ext-intl": "Translate the grid", "ext-mbstring": "Convert your data with the right charset", - "PHPExcel": "Export the grid (Excel, HTML or PDF)", - "doctrine/orm": "If you want to use Entity as source, please require doctrine/orm" - }, - "conflict": { - "doctrime/orm": "<2.6" + "PHPExcel": "Export the grid (Excel, HTML or PDF)" }, "autoload": { "psr-4": { From 7c0013e0418fbe00050d2d4f614307423b6e73f0 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 5 Apr 2023 09:42:12 -0400 Subject: [PATCH 32/38] Remove unused use statement --- src/Grid/Grid.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index de321c8..bdf9698 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -24,7 +24,6 @@ use APY\DataGridBundle\Grid\Source\Entity; use APY\DataGridBundle\Grid\Source\Source; use Doctrine\Persistence\ManagerRegistry; -use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; From a854a0eee841a3195e644dc88566c8a65b4f8023 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Wed, 5 Apr 2023 13:02:03 -0400 Subject: [PATCH 33/38] Remove unnecessary variable assignmnet --- src/Grid/Columns.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Grid/Columns.php b/src/Grid/Columns.php index 0ddf849..621a0dd 100644 --- a/src/Grid/Columns.php +++ b/src/Grid/Columns.php @@ -38,7 +38,6 @@ public function getIterator(bool $showOnlySourceColumns = false): \Traversable public function addColumn(Column $column, int $position = 0): self { - $position = $position; $column->setAuthorizationChecker($this->authorizationChecker); if ($position == 0) { From d057250a5076c6bae02d032ed962542294923e99 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Tue, 20 Jun 2023 10:12:23 -0400 Subject: [PATCH 34/38] Allow older version of doctrine/annotations --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index abde10f..cdeae3d 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "twig/twig": "^2.4|^3.0", "symfony/translation": "^5.2|^6.2", "jms/translation-bundle": "^1.8", - "doctrine/annotations": "^2.0", + "doctrine/annotations": "^1.14|^2.0", "doctrine/orm": "^2.13" }, "require-dev": { From 00af4ac03291f94ada82d2ba86342b933ab79785 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Tue, 20 Jun 2023 10:18:21 -0400 Subject: [PATCH 35/38] Remove jms/translation-bundle dependency --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index cdeae3d..a70e0e3 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ "symfony/serializer": "^5.2|^6.2", "twig/twig": "^2.4|^3.0", "symfony/translation": "^5.2|^6.2", - "jms/translation-bundle": "^1.8", "doctrine/annotations": "^1.14|^2.0", "doctrine/orm": "^2.13" }, From 094b5a38aaf5c5dc483e90743d85c9d2cd31ac33 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Tue, 20 Jun 2023 11:57:43 -0400 Subject: [PATCH 36/38] Fix issues with properties being accessed before being initialized and fix types on some properties --- src/Grid/Column/Column.php | 2 +- src/Grid/Grid.php | 14 +++++++------- src/Grid/GridConfigBuilder.php | 6 +++--- src/Grid/GridConfigInterface.php | 4 ++-- src/Grid/Mapping/Driver/Annotation.php | 10 +++++----- src/Grid/Row.php | 4 ++-- src/Grid/Source/Entity.php | 14 +++++++------- src/Twig/DataGridExtension.php | 22 +++++++++++----------- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Grid/Column/Column.php b/src/Grid/Column/Column.php index ba293aa..3af6e1a 100644 --- a/src/Grid/Column/Column.php +++ b/src/Grid/Column/Column.php @@ -87,7 +87,7 @@ abstract class Column protected ?\Closure $callback = null; - protected ?int $order = null; + protected ?string $order = null; protected ?int $size; diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index bdf9698..e1b88b0 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -138,9 +138,9 @@ class Grid implements GridInterface private bool $newSession = false; - private ?string $noDataMessage; + private string $noDataMessage = ''; - private ?string $noResultMessage; + private string $noResultMessage = ''; /** * @var \APY\DataGridBundle\Grid\Export\Export[] @@ -183,9 +183,9 @@ class Grid implements GridInterface private array $lazyHideShowColumns = []; - private ?int $actionsColumnSize; + private ?int $actionsColumnSize = null; - private ?string $actionsColumnTitle; + private string $actionsColumnTitle = ''; private ?bool $massActionsInNewTab; @@ -566,9 +566,9 @@ protected function processExports(int|string|bool|null $exportId): bool if ($export instanceof Export) { $export->setTwig($this->twig) - ->setTranslator($this->translator) - ->setRouter($this->router) - ->setKernelCharset($this->kernelCharset); + ->setTranslator($this->translator) + ->setRouter($this->router) + ->setKernelCharset($this->kernelCharset); } $export->computeData($this); diff --git a/src/Grid/GridConfigBuilder.php b/src/Grid/GridConfigBuilder.php index 640888b..d4f3846 100644 --- a/src/Grid/GridConfigBuilder.php +++ b/src/Grid/GridConfigBuilder.php @@ -26,7 +26,7 @@ class GridConfigBuilder implements GridConfigBuilderInterface protected int $page = 0; - protected ?int $limit = null; + protected int|array|null $limit = null; protected ?int $maxResults = null; @@ -177,12 +177,12 @@ public function getOption(string $name, mixed $default = null): mixed /** * {@inheritdoc} */ - public function getMaxPerPage(): ?int + public function getMaxPerPage(): int|array|null { return $this->limit; } - public function setMaxPerPage(?int $limit): self + public function setMaxPerPage(int|array|null $limit): self { $this->limit = $limit; diff --git a/src/Grid/GridConfigInterface.php b/src/Grid/GridConfigInterface.php index 164cc19..5a743ad 100644 --- a/src/Grid/GridConfigInterface.php +++ b/src/Grid/GridConfigInterface.php @@ -110,9 +110,9 @@ public function getMaxResults(): ?int; /** * Returns the maximum number of items per page. * - * @return int The maximum number of items per page. + * @return int|array|null The maximum number of items per page. */ - public function getMaxPerPage(): ?int; + public function getMaxPerPage(): int|array|null; /** * Returns the default order. diff --git a/src/Grid/Mapping/Driver/Annotation.php b/src/Grid/Mapping/Driver/Annotation.php index 32a6810..20f2c5a 100644 --- a/src/Grid/Mapping/Driver/Annotation.php +++ b/src/Grid/Mapping/Driver/Annotation.php @@ -14,7 +14,7 @@ use APY\DataGridBundle\Grid\Mapping\Column as Column; use APY\DataGridBundle\Grid\Mapping\Source as Source; -use Doctrine\Common\Annotations\AnnotationReader; +use Doctrine\Common\Annotations\Reader; class Annotation implements DriverInterface { @@ -30,10 +30,10 @@ class Annotation implements DriverInterface private array $groupBy; - private AnnotationReader $reader; + private Reader $reader; public function __construct( - AnnotationReader $reader + Reader $reader ) { $this->reader = $reader; $this->columns = $this->fields = $this->loaded = $this->groupBy = $this->filterable = $this->sortable = []; @@ -106,7 +106,7 @@ protected function loadMetadataFromReader($className, $group = 'default'): void $this->loaded[$className][$group] = true; } - protected function getMetadataFromClassProperty(string $className, Column|Source $class, ?string $name = null, string $group = 'default'): void + protected function getMetadataFromClassProperty(string $className, object $class, ?string $name = null, string $group = 'default'): void { if ($class instanceof Column) { $metadata = $class->getMetadata(); @@ -162,7 +162,7 @@ protected function getMetadataFromClassProperty(string $className, Column|Source } } - protected function getMetadataFromClass(string $className, Column|Source $class, string $group): void + protected function getMetadataFromClass(string $className, object $class, string $group): void { if ($class instanceof Source) { foreach ($class->getGroups() as $sourceGroup) { diff --git a/src/Grid/Row.php b/src/Grid/Row.php index f824b5f..4231d31 100644 --- a/src/Grid/Row.php +++ b/src/Grid/Row.php @@ -18,7 +18,7 @@ class Row { private array $fields; - private string $class; + private ?string $class = null; private string $color; @@ -124,7 +124,7 @@ public function setClass(string $class): self return $this; } - public function getClass(): string + public function getClass(): ?string { return $this->class; } diff --git a/src/Grid/Source/Entity.php b/src/Grid/Source/Entity.php index 05dcafc..a092fc3 100644 --- a/src/Grid/Source/Entity.php +++ b/src/Grid/Source/Entity.php @@ -56,7 +56,7 @@ class Entity extends Source private string $entityName; - private string $managerName; + private ?string $managerName; private Metadata $metadata; @@ -70,7 +70,7 @@ class Entity extends Source private array $hints; - private QueryBuilder $queryBuilder; + private ?QueryBuilder $queryBuilder = null; private string $tableAlias; @@ -632,11 +632,11 @@ public function populateSelectFilters(Columns|array $columns, bool $loop = false $query = ($selectFrom === 'source') ? clone $this->querySelectfromSource : clone $this->query; $query = $query->select($this->getFieldName($column, true)) - ->distinct() - ->orderBy($this->getFieldName($column), 'asc') - ->setFirstResult(null) - ->setMaxResults(null) - ->getQuery(); + ->distinct() + ->orderBy($this->getFieldName($column), 'asc') + ->setFirstResult(null) + ->setMaxResults(null) + ->getQuery(); if ($selectFrom === 'query') { foreach ($this->hints as $hintKey => $hintValue) { $query->setHint($hintKey, $hintValue); diff --git a/src/Twig/DataGridExtension.php b/src/Twig/DataGridExtension.php index 2ffc765..03aeab7 100644 --- a/src/Twig/DataGridExtension.php +++ b/src/Twig/DataGridExtension.php @@ -124,7 +124,7 @@ public function getFunctions(): array ]; } - public function initGrid(Grid $grid, ?string $theme = null, string|int $id = '', array $params = []): void + public function initGrid(Grid $grid, ?string $theme = null, string|int|null $id = '', array $params = []): void { $this->theme = $theme; $this->templates = []; @@ -133,7 +133,7 @@ public function initGrid(Grid $grid, ?string $theme = null, string|int $id = '', $this->params = $params; } - public function getGrid(Environment $environment, Grid $grid, ?string $theme = null, string|int $id = '', array $params = [], bool $withjs = true): string + public function getGrid(Environment $environment, Grid $grid, ?string $theme = null, string|int|null $id = '', array $params = [], bool $withjs = true): string { $this->initGrid($grid, $theme, $id, $params); @@ -165,11 +165,11 @@ public function getGridCell(Environment $environment, Column $column, Row $row, $id = $this->names[$grid->getHash()]; if (($id != '' && ($this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getType() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getType() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_cell'))) + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_cell') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_cell'))) || $this->hasBlock($environment, $block = 'grid_column_' . $column->getRenderBlockId() . '_cell') || $this->hasBlock($environment, $block = 'grid_column_' . $column->getType() . '_cell') || $this->hasBlock($environment, $block = 'grid_column_' . $column->getParentType() . '_cell') @@ -188,10 +188,10 @@ public function getGridFilter(Environment $environment, Column $column, Grid $gr $id = $this->names[$grid->getHash()]; if (($id != '' && ($this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_filter') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_filter') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getType() . '_filter') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_filter')) - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_filter_type_' . $column->getFilterType())) + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_filter') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getType() . '_filter') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_filter')) + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_filter_type_' . $column->getFilterType())) || $this->hasBlock($environment, $block = 'grid_column_' . $column->getRenderBlockId() . '_filter') || $this->hasBlock($environment, $block = 'grid_column_id_' . $column->getRenderBlockId() . '_filter') || $this->hasBlock($environment, $block = 'grid_column_type_' . $column->getType() . '_filter') From 4aa1c1d2ec4bb400cfa592769e28168ac9a57a6e Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 22 Jun 2023 10:05:55 -0400 Subject: [PATCH 37/38] Fix issue with export properties being inaccessible --- src/Grid/Export/Export.php | 67 ++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/Grid/Export/Export.php b/src/Grid/Export/Export.php index 1ebb298..a299e42 100644 --- a/src/Grid/Export/Export.php +++ b/src/Grid/Export/Export.php @@ -36,7 +36,7 @@ abstract class Export implements ExportInterface private array $parameters = []; - private array $templates; + private ?array $templates = null; private Environment $twig; @@ -50,24 +50,25 @@ abstract class Export implements ExportInterface private array $params = []; - private string $content; + protected string $content = ''; private string $charset; private ?string $role; public function __construct( - string $title, - string $fileName = 'export', - array $params = [], - string $charset = 'UTF-8', + string $title, + string $fileName = 'export', + array $params = [], + string $charset = 'UTF-8', ?string $role = null - ) { - $this->title = $title; + ) + { + $this->title = $title; $this->fileName = $fileName; - $this->params = $params; - $this->charset = $charset; - $this->role = $role; + $this->params = $params; + $this->charset = $charset; + $this->role = $role; } public function setTwig(Environment $twig): self @@ -104,20 +105,20 @@ public function getResponse(): Response $kernelCharset = $this->kernelCharset; if ($this->charset != $kernelCharset && function_exists('mb_strlen')) { $this->content = mb_convert_encoding($this->content, $this->charset, $kernelCharset); - $filesize = mb_strlen($this->content, '8bit'); + $filesize = mb_strlen($this->content, '8bit'); } else { - $filesize = strlen($this->content); + $filesize = strlen($this->content); $this->charset = $kernelCharset; } $headers = [ - 'Content-Description' => 'File Transfer', - 'Content-Type' => $this->getMimeType(), - 'Content-Disposition' => sprintf('attachment; filename="%s"', $this->getBaseName()), + 'Content-Description' => 'File Transfer', + 'Content-Type' => $this->getMimeType(), + 'Content-Disposition' => sprintf('attachment; filename="%s"', $this->getBaseName()), 'Content-Transfer-Encoding' => 'binary', - 'Cache-Control' => 'must-revalidate', - 'Pragma' => 'public', - 'Content-Length' => $filesize, + 'Cache-Control' => 'must-revalidate', + 'Pragma' => 'public', + 'Content-Length' => $filesize, ]; $response = new Response($this->content, 200, $headers); @@ -156,7 +157,7 @@ protected function getGridData(Grid $grid): array protected function getRawGridData(Grid $grid): array { - $result = []; + $result = []; $this->grid = $grid; if ($this->grid->isTitleSectionVisible()) { @@ -208,7 +209,7 @@ protected function getGridTitles(): array $titlesClean = array_map([$this, 'cleanHTML'], $matches[0]); - $i = 0; + $i = 0; $titles = []; foreach ($this->grid->getColumns() as $column) { @@ -243,7 +244,7 @@ protected function getGridRows(): array foreach ($this->grid->getRows() as $i => $row) { foreach ($this->grid->getColumns() as $column) { if ($column->isVisible(true)) { - $cellHTML = $this->getGridCell($column, $row); + $cellHTML = $this->getGridCell($column, $row); $rows[$i][$column->getId()] = $this->cleanHTML($cellHTML); } } @@ -277,17 +278,21 @@ protected function getGridCell(Column $column, Row $row): string $separator = $column->getSeparator(); - $block = null; + $block = null; $return = []; foreach ($values as $sourceValue) { $value = $column->renderCell($sourceValue, $row, $this->router); $id = $this->grid->getId(); - if (($id != '' && ($block !== null - || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_cell') - || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getType() . '_cell') - || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell'))) + if ( + ($id != '' + && ($block !== null + || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_cell') + || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getType() . '_cell') + || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell') + ) + ) || $this->hasBlock($block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_cell') || $this->hasBlock($block = 'grid_' . $id . '_column_type_' . $column->getType() . '_cell') || $this->hasBlock($block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_cell') @@ -299,7 +304,7 @@ protected function getGridCell(Column $column, Row $row): string || $this->hasBlock($block = 'grid_column_type_' . $column->getParentType() . '_cell')) { $html = $this->renderBlock($block, ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]); } else { - $html = $this->renderBlock('grid_column_cell', ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]); + $html = $this->renderBlock('grid_column_cell', ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]); $block = null; } @@ -347,11 +352,11 @@ protected function getTemplates(): array return $this->templates; } - public function setTemplate(\Twig\TemplateWrapper|string $template): self + public function setTemplate(\Twig\TemplateWrapper|string|null $template): self { if (is_string($template)) { if (substr($template, 0, 8) === '__SELF__') { - $this->templates = $this->getTemplatesFromString(substr($template, 8)); + $this->templates = $this->getTemplatesFromString(substr($template, 8)); $this->templates[] = $this->twig->load(static::DEFAULT_TEMPLATE); } else { $this->templates = $this->getTemplatesFromString($template); @@ -372,7 +377,7 @@ protected function getTemplatesFromString(string|TemplateWrapper $theme): array $template = $this->twig->load($theme); while ($template instanceof \Twig\TemplateWrapper) { $templates[] = $template; - $template = $template->getParent([]); + $template = $template->getParent([]); } return $templates; From f731f01f52a9613724642714983fe7bfc5ba3018 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 22 Jun 2023 10:28:01 -0400 Subject: [PATCH 38/38] Add an accessor for the params class variable on the grid Export class --- src/Grid/Export/Export.php | 64 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Grid/Export/Export.php b/src/Grid/Export/Export.php index a299e42..a5fda84 100644 --- a/src/Grid/Export/Export.php +++ b/src/Grid/Export/Export.php @@ -26,7 +26,7 @@ abstract class Export implements ExportInterface { public const DEFAULT_TEMPLATE = '@APYDataGrid/blocks.html.twig'; - private string $title; + private string $title = ''; private string $fileName; @@ -57,18 +57,17 @@ abstract class Export implements ExportInterface private ?string $role; public function __construct( - string $title, - string $fileName = 'export', - array $params = [], - string $charset = 'UTF-8', + string $title, + string $fileName = 'export', + array $params = [], + string $charset = 'UTF-8', ?string $role = null - ) - { - $this->title = $title; + ) { + $this->title = $title; $this->fileName = $fileName; - $this->params = $params; - $this->charset = $charset; - $this->role = $role; + $this->params = $params; + $this->charset = $charset; + $this->role = $role; } public function setTwig(Environment $twig): self @@ -105,20 +104,20 @@ public function getResponse(): Response $kernelCharset = $this->kernelCharset; if ($this->charset != $kernelCharset && function_exists('mb_strlen')) { $this->content = mb_convert_encoding($this->content, $this->charset, $kernelCharset); - $filesize = mb_strlen($this->content, '8bit'); + $filesize = mb_strlen($this->content, '8bit'); } else { - $filesize = strlen($this->content); + $filesize = strlen($this->content); $this->charset = $kernelCharset; } $headers = [ - 'Content-Description' => 'File Transfer', - 'Content-Type' => $this->getMimeType(), - 'Content-Disposition' => sprintf('attachment; filename="%s"', $this->getBaseName()), + 'Content-Description' => 'File Transfer', + 'Content-Type' => $this->getMimeType(), + 'Content-Disposition' => sprintf('attachment; filename="%s"', $this->getBaseName()), 'Content-Transfer-Encoding' => 'binary', - 'Cache-Control' => 'must-revalidate', - 'Pragma' => 'public', - 'Content-Length' => $filesize, + 'Cache-Control' => 'must-revalidate', + 'Pragma' => 'public', + 'Content-Length' => $filesize, ]; $response = new Response($this->content, 200, $headers); @@ -157,7 +156,7 @@ protected function getGridData(Grid $grid): array protected function getRawGridData(Grid $grid): array { - $result = []; + $result = []; $this->grid = $grid; if ($this->grid->isTitleSectionVisible()) { @@ -209,7 +208,7 @@ protected function getGridTitles(): array $titlesClean = array_map([$this, 'cleanHTML'], $matches[0]); - $i = 0; + $i = 0; $titles = []; foreach ($this->grid->getColumns() as $column) { @@ -244,7 +243,7 @@ protected function getGridRows(): array foreach ($this->grid->getRows() as $i => $row) { foreach ($this->grid->getColumns() as $column) { if ($column->isVisible(true)) { - $cellHTML = $this->getGridCell($column, $row); + $cellHTML = $this->getGridCell($column, $row); $rows[$i][$column->getId()] = $this->cleanHTML($cellHTML); } } @@ -278,21 +277,17 @@ protected function getGridCell(Column $column, Row $row): string $separator = $column->getSeparator(); - $block = null; + $block = null; $return = []; foreach ($values as $sourceValue) { $value = $column->renderCell($sourceValue, $row, $this->router); $id = $this->grid->getId(); - if ( - ($id != '' - && ($block !== null + if (($id != '' && ($block !== null || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_cell') || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getType() . '_cell') - || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell') - ) - ) + || $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell'))) || $this->hasBlock($block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_cell') || $this->hasBlock($block = 'grid_' . $id . '_column_type_' . $column->getType() . '_cell') || $this->hasBlock($block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_cell') @@ -304,7 +299,7 @@ protected function getGridCell(Column $column, Row $row): string || $this->hasBlock($block = 'grid_column_type_' . $column->getParentType() . '_cell')) { $html = $this->renderBlock($block, ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]); } else { - $html = $this->renderBlock('grid_column_cell', ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]); + $html = $this->renderBlock('grid_column_cell', ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]); $block = null; } @@ -356,7 +351,7 @@ public function setTemplate(\Twig\TemplateWrapper|string|null $template): self { if (is_string($template)) { if (substr($template, 0, 8) === '__SELF__') { - $this->templates = $this->getTemplatesFromString(substr($template, 8)); + $this->templates = $this->getTemplatesFromString(substr($template, 8)); $this->templates[] = $this->twig->load(static::DEFAULT_TEMPLATE); } else { $this->templates = $this->getTemplatesFromString($template); @@ -377,7 +372,7 @@ protected function getTemplatesFromString(string|TemplateWrapper $theme): array $template = $this->twig->load($theme); while ($template instanceof \Twig\TemplateWrapper) { $templates[] = $template; - $template = $template->getParent([]); + $template = $template->getParent([]); } return $templates; @@ -507,6 +502,11 @@ public function getParameter(string $name): string return $this->parameters[$name]; } + public function getParams(): array + { + return $this->params; + } + public function setRole(?string $role): self { $this->role = $role;