Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: byjg
3 changes: 1 addition & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ jobs:
strategy:
matrix:
php-version:
- "8.3"
- "8.2"
- "8.1"
- "8.0"
- "7.4"

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"php": ">=7.4",
"byjg/anydataset": "4.9.*"
"php": ">=8.1 <8.4",
"byjg/anydataset": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"
"phpunit/phpunit": "^9.6"
},
"provide": {
"byjg/anydataset-implementation": "1.0"
Expand Down
19 changes: 9 additions & 10 deletions src/ArrayDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,30 @@

use ByJG\AnyDataset\Core\GenericIterator;
use ByJG\AnyDataset\Core\IteratorFilter;
use UnexpectedValueException;

class ArrayDataset
{

/**
* @var array
*/
protected $array;
protected array $array;
/**
* @var mixed|string
* @var string|null
*/
protected $propertyIndexName;
protected ?string $propertyIndexName;
/**
* @var mixed|string
* @var string|null
*/
protected $propertyKeyName;
protected ?string $propertyKeyName;

/**
* Constructor Method
*
* @param array $array
* @param string $property The name of the field if the item is not an array or object
*/
public function __construct(array $array, string $property = "value", $propertyIndexName = "__id", $propertyKeyName = "__key")
public function __construct(array $array, string $property = "value", ?string $propertyIndexName = "__id", ?string $propertyKeyName = "__key")
{
$this->propertyIndexName = $propertyIndexName;
$this->propertyKeyName = $propertyKeyName;
Expand All @@ -44,7 +43,7 @@ public function __construct(array $array, string $property = "value", $propertyI
$result = array("__class" => get_class($value));
$methods = get_class_methods($value);
foreach ($methods as $method) {
if (strpos($method, "get") === 0) {
if (str_starts_with($method, "get")) {
$result[substr($method, 3)] = $value->{$method}();
}
}
Expand All @@ -58,10 +57,10 @@ public function __construct(array $array, string $property = "value", $propertyI
/**
* Return a GenericIterator
*
* @param IteratorFilter $filter
* @param IteratorFilter|null $filter
* @return GenericIterator
*/
public function getIterator($filter = null)
public function getIterator(IteratorFilter $filter = null): GenericIterator
{
return new ArrayDatasetIterator($this->array, $filter, $this->propertyIndexName, $this->propertyKeyName);
}
Expand Down
41 changes: 19 additions & 22 deletions src/ArrayDatasetIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,53 @@
use ByJG\AnyDataset\Core\GenericIterator;
use ByJG\AnyDataset\Core\IteratorFilter;
use ByJG\AnyDataset\Core\Row;
use InvalidArgumentException;

class ArrayDatasetIterator extends GenericIterator
{

/**
* @var array
*/
protected $rows;
protected array $rows;

/**
* Enter description here...
*
* @var array
*/
protected $keys;
protected array $keys;

/**
/* @var int
*/
protected $index;
protected int $index;

/**
* @var Row
*/
protected $currentRow;
protected ?Row $currentRow;

/**
* @var IteratorFilter
* @var IteratorFilter|null
*/
protected $filter;
protected ?IteratorFilter $filter;
/**
* @var mixed|string
* @var string|null
*/
protected $propertyIndexName;
protected ?string $propertyIndexName;
/**
* @var mixed|string
* @var string|null
*/
protected $propertyKeyName;
protected ?string $propertyKeyName;

/**
* @param array $rows
* @param IteratorFilter $filter
* @param IteratorFilter|null $filter
* @param string|null $propertyIndexName
* @param string|null $propertyKeyName
*/
public function __construct($rows, $filter, $propertyIndexName = "__id", $propertyKeyName = "__key")
public function __construct(array $rows, ?IteratorFilter $filter, ?string $propertyIndexName = "__id", ?string $propertyKeyName = "__key")
{
if (!is_array($rows)) {
throw new InvalidArgumentException("ArrayDatasetIterator must receive an array");
}
$this->index = 0;
$this->currentRow = null;
$this->rows = $rows;
Expand All @@ -62,13 +60,12 @@ public function __construct($rows, $filter, $propertyIndexName = "__id", $proper

$this->propertyIndexName = $propertyIndexName;
$this->propertyKeyName = $propertyKeyName;

}

/**
* @return int
*/
public function count()
public function count(): int
{
return count($this->rows);
}
Expand All @@ -77,7 +74,7 @@ public function count()
* @return bool
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
*/
public function hasNext()
public function hasNext(): bool
{
if (!empty($this->currentRow)) {
return true;
Expand Down Expand Up @@ -114,10 +111,10 @@ public function hasNext()
}

/**
* @return Row
* @return Row|null
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
*/
public function moveNext()
public function moveNext(): ?Row
{
if (!$this->hasNext()) {
return null;
Expand All @@ -129,7 +126,7 @@ public function moveNext()
return $row;
}

public function key()
public function key(): int
{
return $this->index;
}
Expand Down