Skip to content

Commit a185418

Browse files
authored
Merge pull request #4 from byjg/5.0
PHP 8.1 Implementation
2 parents 0a35d2b + a6a8a76 commit a185418

File tree

5 files changed

+35
-37
lines changed

5 files changed

+35
-37
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: byjg

.github/workflows/phpunit.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ jobs:
1616
strategy:
1717
matrix:
1818
php-version:
19+
- "8.3"
1920
- "8.2"
2021
- "8.1"
21-
- "8.0"
22-
- "7.4"
2322

2423
steps:
2524
- uses: actions/checkout@v4

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"prefer-stable": true,
1010
"minimum-stability": "dev",
1111
"require": {
12-
"php": ">=7.4",
13-
"byjg/anydataset": "4.9.*"
12+
"php": ">=8.1 <8.4",
13+
"byjg/anydataset": "^5.0"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"
16+
"phpunit/phpunit": "^9.6"
1717
},
1818
"provide": {
1919
"byjg/anydataset-implementation": "1.0"

src/ArrayDataset.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,30 @@
44

55
use ByJG\AnyDataset\Core\GenericIterator;
66
use ByJG\AnyDataset\Core\IteratorFilter;
7-
use UnexpectedValueException;
87

98
class ArrayDataset
109
{
1110

1211
/**
1312
* @var array
1413
*/
15-
protected $array;
14+
protected array $array;
1615
/**
17-
* @var mixed|string
16+
* @var string|null
1817
*/
19-
protected $propertyIndexName;
18+
protected ?string $propertyIndexName;
2019
/**
21-
* @var mixed|string
20+
* @var string|null
2221
*/
23-
protected $propertyKeyName;
22+
protected ?string $propertyKeyName;
2423

2524
/**
2625
* Constructor Method
2726
*
2827
* @param array $array
2928
* @param string $property The name of the field if the item is not an array or object
3029
*/
31-
public function __construct(array $array, string $property = "value", $propertyIndexName = "__id", $propertyKeyName = "__key")
30+
public function __construct(array $array, string $property = "value", ?string $propertyIndexName = "__id", ?string $propertyKeyName = "__key")
3231
{
3332
$this->propertyIndexName = $propertyIndexName;
3433
$this->propertyKeyName = $propertyKeyName;
@@ -44,7 +43,7 @@ public function __construct(array $array, string $property = "value", $propertyI
4443
$result = array("__class" => get_class($value));
4544
$methods = get_class_methods($value);
4645
foreach ($methods as $method) {
47-
if (strpos($method, "get") === 0) {
46+
if (str_starts_with($method, "get")) {
4847
$result[substr($method, 3)] = $value->{$method}();
4948
}
5049
}
@@ -58,10 +57,10 @@ public function __construct(array $array, string $property = "value", $propertyI
5857
/**
5958
* Return a GenericIterator
6059
*
61-
* @param IteratorFilter $filter
60+
* @param IteratorFilter|null $filter
6261
* @return GenericIterator
6362
*/
64-
public function getIterator($filter = null)
63+
public function getIterator(IteratorFilter $filter = null): GenericIterator
6564
{
6665
return new ArrayDatasetIterator($this->array, $filter, $this->propertyIndexName, $this->propertyKeyName);
6766
}

src/ArrayDatasetIterator.php

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,53 @@
55
use ByJG\AnyDataset\Core\GenericIterator;
66
use ByJG\AnyDataset\Core\IteratorFilter;
77
use ByJG\AnyDataset\Core\Row;
8-
use InvalidArgumentException;
98

109
class ArrayDatasetIterator extends GenericIterator
1110
{
1211

1312
/**
1413
* @var array
1514
*/
16-
protected $rows;
15+
protected array $rows;
1716

1817
/**
1918
* Enter description here...
2019
*
2120
* @var array
2221
*/
23-
protected $keys;
22+
protected array $keys;
2423

2524
/**
2625
/* @var int
2726
*/
28-
protected $index;
27+
protected int $index;
2928

3029
/**
3130
* @var Row
3231
*/
33-
protected $currentRow;
32+
protected ?Row $currentRow;
3433

3534
/**
36-
* @var IteratorFilter
35+
* @var IteratorFilter|null
3736
*/
38-
protected $filter;
37+
protected ?IteratorFilter $filter;
3938
/**
40-
* @var mixed|string
39+
* @var string|null
4140
*/
42-
protected $propertyIndexName;
41+
protected ?string $propertyIndexName;
4342
/**
44-
* @var mixed|string
43+
* @var string|null
4544
*/
46-
protected $propertyKeyName;
45+
protected ?string $propertyKeyName;
4746

4847
/**
4948
* @param array $rows
50-
* @param IteratorFilter $filter
49+
* @param IteratorFilter|null $filter
50+
* @param string|null $propertyIndexName
51+
* @param string|null $propertyKeyName
5152
*/
52-
public function __construct($rows, $filter, $propertyIndexName = "__id", $propertyKeyName = "__key")
53+
public function __construct(array $rows, ?IteratorFilter $filter, ?string $propertyIndexName = "__id", ?string $propertyKeyName = "__key")
5354
{
54-
if (!is_array($rows)) {
55-
throw new InvalidArgumentException("ArrayDatasetIterator must receive an array");
56-
}
5755
$this->index = 0;
5856
$this->currentRow = null;
5957
$this->rows = $rows;
@@ -62,13 +60,12 @@ public function __construct($rows, $filter, $propertyIndexName = "__id", $proper
6260

6361
$this->propertyIndexName = $propertyIndexName;
6462
$this->propertyKeyName = $propertyKeyName;
65-
6663
}
6764

6865
/**
6966
* @return int
7067
*/
71-
public function count()
68+
public function count(): int
7269
{
7370
return count($this->rows);
7471
}
@@ -77,7 +74,7 @@ public function count()
7774
* @return bool
7875
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
7976
*/
80-
public function hasNext()
77+
public function hasNext(): bool
8178
{
8279
if (!empty($this->currentRow)) {
8380
return true;
@@ -114,10 +111,10 @@ public function hasNext()
114111
}
115112

116113
/**
117-
* @return Row
114+
* @return Row|null
118115
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
119116
*/
120-
public function moveNext()
117+
public function moveNext(): ?Row
121118
{
122119
if (!$this->hasNext()) {
123120
return null;
@@ -129,7 +126,7 @@ public function moveNext()
129126
return $row;
130127
}
131128

132-
public function key()
129+
public function key(): int
133130
{
134131
return $this->index;
135132
}

0 commit comments

Comments
 (0)