Skip to content

Commit

Permalink
Require php 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Vermeiren committed Jun 13, 2022
1 parent dcb7eaa commit 3f743bc
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 58 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
},
"require": {
"php": ">=5.4"
"php": ">=8.1"
},
"config": {
"bin-dir": "bin"
Expand Down
28 changes: 14 additions & 14 deletions src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -67,39 +67,39 @@ public function __construct(
/**
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* @return string
*/
public function getDbField()
public function getDbField(): string
{
return $this->dbField;
}

/**
* @return bool
*/
public function isSearchable()
public function isSearchable(): bool
{
return $this->searchable;
}

/**
* @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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ColumnTransformerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ interface ColumnTransformerInterface
*
* @return array
*/
public function transform(array $data);
public function transform(array $data): array;
}
20 changes: 10 additions & 10 deletions src/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public function __construct(array $columns)
/**
* {@inheritdoc}
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return array_key_exists($offset, $this->columns);
}

/**
* {@inheritdoc}
*/
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
if ($this->offsetExists($offset) === false) {
throw new \InvalidArgumentException(sprintf('%s column not available', $offset));
Expand All @@ -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;
Expand All @@ -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]);
Expand All @@ -80,47 +80,47 @@ public function offsetUnset($offset)
/**
* {@inheritdoc}
*/
public function rewind()
public function rewind(): void
{
$this->position = 0;
}

/**
* {@inheritdoc}
*/
public function current()
public function current(): mixed
{
return $this->columns[$this->position];
}

/**
* {@inheritdoc}
*/
public function key()
public function key(): mixed
{
return $this->position;
}

/**
* {@inheritdoc}
*/
public function next()
public function next(): void
{
++$this->position;
}

/**
* {@inheritdoc}
*/
public function valid()
public function valid(): bool
{
return array_key_exists($this->position, $this->columns);
}

/**
* @return array
*/
public function getSearchableFields()
public function getSearchableFields(): array
{
$searchable = array();

Expand Down
11 changes: 4 additions & 7 deletions src/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/DataTablesRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ interface DataTablesRepositoryInterface
*
* @return int
*/
public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $columns);
public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $columns): int;

/**
* @param Parameters $parameters
* @param Columns $columns
*
* @return int
*/
public function getDataTablesFilteredRecordsCount(Parameters $parameters, Columns $columns);
public function getDataTablesFilteredRecordsCount(Parameters $parameters, Columns $columns): int;

/**
* @param Parameters $parameters
* @param Columns $columns
*
* @return array
*/
public function getDataTablesData(Parameters $parameters, Columns $columns);
public function getDataTablesData(Parameters $parameters, Columns $columns): array;
}
6 changes: 3 additions & 3 deletions src/Doctrine/ODM/DataTablesRepositoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ 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());
}

/**
* {@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());
}

/**
* {@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());
Expand Down
6 changes: 3 additions & 3 deletions src/Doctrine/ORM/DataTablesRepositoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ')')
Expand All @@ -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);

Expand All @@ -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())
Expand Down
Loading

0 comments on commit 3f743bc

Please sign in to comment.