diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..3a9251f --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: byjg diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 290ff04..a781440 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -16,10 +16,9 @@ jobs: strategy: matrix: php-version: + - "8.3" - "8.2" - "8.1" - - "8.0" - - "7.4" steps: - uses: actions/checkout@v4 diff --git a/composer.json b/composer.json index c86ed9b..4a4dede 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/ArrayDataset.php b/src/ArrayDataset.php index f195b6a..5a81f65 100644 --- a/src/ArrayDataset.php +++ b/src/ArrayDataset.php @@ -4,7 +4,6 @@ use ByJG\AnyDataset\Core\GenericIterator; use ByJG\AnyDataset\Core\IteratorFilter; -use UnexpectedValueException; class ArrayDataset { @@ -12,15 +11,15 @@ 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 @@ -28,7 +27,7 @@ class ArrayDataset * @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; @@ -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}(); } } @@ -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); } diff --git a/src/ArrayDatasetIterator.php b/src/ArrayDatasetIterator.php index e38f90e..79a8409 100644 --- a/src/ArrayDatasetIterator.php +++ b/src/ArrayDatasetIterator.php @@ -5,7 +5,6 @@ use ByJG\AnyDataset\Core\GenericIterator; use ByJG\AnyDataset\Core\IteratorFilter; use ByJG\AnyDataset\Core\Row; -use InvalidArgumentException; class ArrayDatasetIterator extends GenericIterator { @@ -13,47 +12,46 @@ 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; @@ -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); } @@ -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; @@ -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; @@ -129,7 +126,7 @@ public function moveNext() return $row; } - public function key() + public function key(): int { return $this->index; }