From 3f743bc161032bc29b272ec7e64fc70ac84cf34b Mon Sep 17 00:00:00 2001 From: Tony Vermeiren Date: Mon, 13 Jun 2022 09:53:53 +0200 Subject: [PATCH] Require php 8.1 --- composer.json | 2 +- src/Column.php | 28 ++++++++-------- src/ColumnTransformerInterface.php | 2 +- src/Columns.php | 20 ++++++------ src/DataProvider.php | 11 +++---- src/DataTablesRepositoryInterface.php | 6 ++-- .../ODM/DataTablesRepositoryTrait.php | 6 ++-- .../ORM/DataTablesRepositoryTrait.php | 6 ++-- src/Parameters.php | 32 +++++++++---------- 9 files changed, 55 insertions(+), 58 deletions(-) diff --git a/composer.json b/composer.json index c73d597..b9ae118 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } }, "require": { - "php": ">=5.4" + "php": ">=8.1" }, "config": { "bin-dir": "bin" diff --git a/src/Column.php b/src/Column.php index f8d83e8..cfb9f54 100644 --- a/src/Column.php +++ b/src/Column.php @@ -44,18 +44,18 @@ class Column /** * Column constructor * - * @param string $name - * @param string $dbField + * @param string|null $name + * @param string|null $dbField * @param bool $searchable * @param bool $orderable - * @param null|array $classes + * @param array|null $classes */ public function __construct( - $name, - $dbField, - $searchable, - $orderable, - $classes = [] + ?string $name, + ?string $dbField, + bool $searchable, + bool $orderable, + ?array $classes = [] ) { $this->name = $name; $this->dbField = $dbField; @@ -67,7 +67,7 @@ public function __construct( /** * @return string */ - public function getName() + public function getName(): string { return $this->name; } @@ -75,7 +75,7 @@ public function getName() /** * @return string */ - public function getDbField() + public function getDbField(): string { return $this->dbField; } @@ -83,7 +83,7 @@ public function getDbField() /** * @return bool */ - public function isSearchable() + public function isSearchable(): bool { return $this->searchable; } @@ -91,15 +91,15 @@ public function isSearchable() /** * @return bool */ - public function isOrderable() + public function isOrderable(): bool { return $this->orderable; } /** - * @return array + * @return array|null */ - public function getClasses() + public function getClasses(): ?array { return $this->classes; } diff --git a/src/ColumnTransformerInterface.php b/src/ColumnTransformerInterface.php index ad74f0d..9bfe001 100644 --- a/src/ColumnTransformerInterface.php +++ b/src/ColumnTransformerInterface.php @@ -18,5 +18,5 @@ interface ColumnTransformerInterface * * @return array */ - public function transform(array $data); + public function transform(array $data): array; } diff --git a/src/Columns.php b/src/Columns.php index e3cc475..52289f7 100644 --- a/src/Columns.php +++ b/src/Columns.php @@ -40,7 +40,7 @@ public function __construct(array $columns) /** * {@inheritdoc} */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return array_key_exists($offset, $this->columns); } @@ -48,7 +48,7 @@ public function offsetExists($offset) /** * {@inheritdoc} */ - public function offsetGet($offset) + public function offsetGet($offset): mixed { if ($this->offsetExists($offset) === false) { throw new \InvalidArgumentException(sprintf('%s column not available', $offset)); @@ -60,7 +60,7 @@ public function offsetGet($offset) /** * {@inheritdoc} */ - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { if ($this->offsetExists($offset) === false) { $this->columns[$offset] = $value; @@ -70,7 +70,7 @@ public function offsetSet($offset, $value) /** * {@inheritdoc} */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { if ($this->offsetExists($offset) === false) { unset($this->columns[$offset]); @@ -80,7 +80,7 @@ public function offsetUnset($offset) /** * {@inheritdoc} */ - public function rewind() + public function rewind(): void { $this->position = 0; } @@ -88,7 +88,7 @@ public function rewind() /** * {@inheritdoc} */ - public function current() + public function current(): mixed { return $this->columns[$this->position]; } @@ -96,7 +96,7 @@ public function current() /** * {@inheritdoc} */ - public function key() + public function key(): mixed { return $this->position; } @@ -104,7 +104,7 @@ public function key() /** * {@inheritdoc} */ - public function next() + public function next(): void { ++$this->position; } @@ -112,7 +112,7 @@ public function next() /** * {@inheritdoc} */ - public function valid() + public function valid(): bool { return array_key_exists($this->position, $this->columns); } @@ -120,7 +120,7 @@ public function valid() /** * @return array */ - public function getSearchableFields() + public function getSearchableFields(): array { $searchable = array(); diff --git a/src/DataProvider.php b/src/DataProvider.php index 006020d..942e162 100644 --- a/src/DataProvider.php +++ b/src/DataProvider.php @@ -29,15 +29,13 @@ public function getData( Columns $columns, DataTablesRepositoryInterface $dataTablesRepository, ColumnTransformerInterface $columnTransformer - ) { - $data = array( + ): array { + return array( 'draw' => $parameters->getDraw(), 'recordsTotal' => $dataTablesRepository->getDataTablesTotalRecordsCount($parameters, $columns), 'recordsFiltered' => $dataTablesRepository->getDataTablesFilteredRecordsCount($parameters, $columns), 'data' => $this->getColumns($parameters, $columns, $dataTablesRepository, $columnTransformer), ); - - return $data; } /** @@ -53,10 +51,9 @@ private function getColumns( Columns $columns, DataTablesRepositoryInterface $dataTablesRepository, ColumnTransformerInterface $columnTransformer - ) { + ): array { $data = $dataTablesRepository->getDataTablesData($parameters, $columns); - $columnsData = $columnTransformer->transform($data); - return $columnsData; + return $columnTransformer->transform($data); } } diff --git a/src/DataTablesRepositoryInterface.php b/src/DataTablesRepositoryInterface.php index 7de7e69..efac39c 100644 --- a/src/DataTablesRepositoryInterface.php +++ b/src/DataTablesRepositoryInterface.php @@ -24,7 +24,7 @@ interface DataTablesRepositoryInterface * * @return int */ - public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $columns); + public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $columns): int; /** * @param Parameters $parameters @@ -32,7 +32,7 @@ public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $ * * @return int */ - public function getDataTablesFilteredRecordsCount(Parameters $parameters, Columns $columns); + public function getDataTablesFilteredRecordsCount(Parameters $parameters, Columns $columns): int; /** * @param Parameters $parameters @@ -40,5 +40,5 @@ public function getDataTablesFilteredRecordsCount(Parameters $parameters, Column * * @return array */ - public function getDataTablesData(Parameters $parameters, Columns $columns); + public function getDataTablesData(Parameters $parameters, Columns $columns): array; } diff --git a/src/Doctrine/ODM/DataTablesRepositoryTrait.php b/src/Doctrine/ODM/DataTablesRepositoryTrait.php index f91c1b2..8aba7a9 100644 --- a/src/Doctrine/ODM/DataTablesRepositoryTrait.php +++ b/src/Doctrine/ODM/DataTablesRepositoryTrait.php @@ -21,7 +21,7 @@ trait DataTablesRepositoryTrait /** * {@inheritdoc} */ - public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $columns) + public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $columns): int { return iterator_count($this->createQueryBuilder()->getQuery()->execute()); } @@ -29,7 +29,7 @@ public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $ /** * {@inheritdoc} */ - public function getDataTablesFilteredRecordsCount(Parameters $parameters, Columns $columns) + public function getDataTablesFilteredRecordsCount(Parameters $parameters, Columns $columns): int { return iterator_count($this->getFilteredDataTablesQb($parameters, $columns)->getQuery()->execute()); } @@ -37,7 +37,7 @@ public function getDataTablesFilteredRecordsCount(Parameters $parameters, Column /** * {@inheritdoc} */ - public function getDataTablesData(Parameters $parameters, Columns $columns) + public function getDataTablesData(Parameters $parameters, Columns $columns): array { $qb = $this->getFilteredDataTablesQb($parameters, $columns); $qb->limit($parameters->getLength())->skip($parameters->getStart()); diff --git a/src/Doctrine/ORM/DataTablesRepositoryTrait.php b/src/Doctrine/ORM/DataTablesRepositoryTrait.php index a603aed..2e7421b 100644 --- a/src/Doctrine/ORM/DataTablesRepositoryTrait.php +++ b/src/Doctrine/ORM/DataTablesRepositoryTrait.php @@ -23,7 +23,7 @@ trait DataTablesRepositoryTrait /** * {@inheritdoc} */ - public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $columns) + public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $columns): int { return $this->createQueryBuilder(self::ENTITY_ALIAS) ->select('count(' . self::ENTITY_ALIAS . ')') @@ -34,7 +34,7 @@ public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $ /** * {@inheritdoc} */ - public function getDataTablesFilteredRecordsCount(Parameters $parameters, Columns $columns) + public function getDataTablesFilteredRecordsCount(Parameters $parameters, Columns $columns): int { $qb = $this->getFilteredDataTablesQb($parameters, $columns); @@ -46,7 +46,7 @@ public function getDataTablesFilteredRecordsCount(Parameters $parameters, Column /** * {@inheritdoc} */ - public function getDataTablesData(Parameters $parameters, Columns $columns) + public function getDataTablesData(Parameters $parameters, Columns $columns): array { $qb = $this->getFilteredDataTablesQb($parameters, $columns); $qb->setFirstResult($parameters->getStart()) diff --git a/src/Parameters.php b/src/Parameters.php index b23e597..05006f7 100644 --- a/src/Parameters.php +++ b/src/Parameters.php @@ -75,7 +75,7 @@ private function __construct() * * @return Parameters */ - public static function fromParameterBag(ParameterBag $parameterBag, Columns $columns, array $attributes = array()) + public static function fromParameterBag(ParameterBag $parameterBag, Columns $columns, array $attributes = array()): Parameters { $parameters = new Parameters(); @@ -94,15 +94,15 @@ public static function fromParameterBag(ParameterBag $parameterBag, Columns $col /** * @return int */ - public function getDraw() + public function getDraw(): int { - return $this->draw; + return (int) $this->draw; } /** * @return int */ - public function getLength() + public function getLength(): int { return (int) $this->length; } @@ -110,7 +110,7 @@ public function getLength() /** * @return int */ - public function getStart() + public function getStart(): int { return (int) $this->start; } @@ -118,7 +118,7 @@ public function getStart() /** * @return string */ - public function getOrderField() + public function getOrderField(): ?string { // Only sorting on one column supported for now $columnIndex = $this->order[0]['column']; @@ -133,7 +133,7 @@ public function getOrderField() /** * @return string */ - public function getOrderDirection() + public function getOrderDirection(): string { return $this->order[0]['dir']; // Only sorting on one column supported for now } @@ -141,7 +141,7 @@ public function getOrderDirection() /** * @return array */ - public function getFilters() + public function getFilters(): array { return $this->filters; } @@ -149,7 +149,7 @@ public function getFilters() /** * @return bool */ - public function hasFilters() + public function hasFilters(): bool { if (null === $this->filters) { return false; @@ -166,10 +166,10 @@ public function hasFilters() * * @return void */ - public function addFilter($field, $value = null) + public function addFilter($field, $value = null): void { if (is_callable($field)) { - return $this->addCallableFilter($field); + $this->addCallableFilter($field); } $this->filters[$field] = $value; @@ -182,15 +182,15 @@ public function addFilter($field, $value = null) * * @return void */ - public function addCallableFilter(callable $callback) + public function addCallableFilter(callable $callback): void { $this->filters['callable_' . count($this->filters)] = $callback; } /** - * @return string + * @return bool */ - public function hasSearchString() + public function hasSearchString(): bool { return empty($this->search['value']) === false; } @@ -198,7 +198,7 @@ public function hasSearchString() /** * @return string */ - public function getSearchString() + public function getSearchString(): string { return $this->search['value']; } @@ -211,7 +211,7 @@ public function getSearchString() * * @return mixed */ - public function getAttribute($key, $default = null) + public function getAttribute($key, $default = null): mixed { return array_key_exists($key, $this->attributes) ? $this->attributes[$key] : $default; }