Skip to content

Commit 8ef4a6b

Browse files
committed
update code for PHP 8
1 parent ea4a2d3 commit 8ef4a6b

24 files changed

+26
-156
lines changed

src/ChunkIterableAggregate.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,11 @@
2222
*/
2323
final class ChunkIterableAggregate implements IteratorAggregate
2424
{
25-
private int $chunkSize;
26-
27-
/**
28-
* @var iterable<TKey, T>
29-
*/
30-
private iterable $iterable;
31-
3225
/**
3326
* @param iterable<TKey, T> $iterable
3427
*/
35-
public function __construct(iterable $iterable, int $chunkSize)
28+
public function __construct(private iterable $iterable, private int $chunkSize)
3629
{
37-
$this->iterable = $iterable;
38-
$this->chunkSize = $chunkSize;
3930
}
4031

4132
/**

src/ClosureIterator.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,13 @@ final class ClosureIterator implements Iterator
3030
*/
3131
private Generator $generator;
3232

33-
/**
34-
* @var iterable<int, mixed>
35-
*/
36-
private iterable $parameters;
37-
3833
/**
3934
* @param callable(mixed): iterable<TKey, T> $callable
4035
* @param iterable<int, mixed> $parameters
4136
*/
42-
public function __construct(callable $callable, iterable $parameters = [])
37+
public function __construct(callable $callable, private iterable $parameters = [])
4338
{
4439
$this->callable = $callable;
45-
$this->parameters = $parameters;
4640
$this->generator = $this->getGenerator();
4741
}
4842

src/ClosureIteratorAggregate.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,13 @@ final class ClosureIteratorAggregate implements IteratorAggregate
2525
*/
2626
private $callable;
2727

28-
/**
29-
* @var iterable<int, mixed>
30-
*/
31-
private iterable $parameters;
32-
3328
/**
3429
* @param callable(mixed ...$parameters): iterable<TKey, T> $callable
3530
* @param iterable<int, mixed> $parameters
3631
*/
37-
public function __construct(callable $callable, iterable $parameters = [])
32+
public function __construct(callable $callable, private iterable $parameters = [])
3833
{
3934
$this->callable = $callable;
40-
$this->parameters = $parameters;
4135
}
4236

4337
/**

src/ConcatIterableAggregate.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,11 @@
2222
*/
2323
final class ConcatIterableAggregate implements IteratorAggregate
2424
{
25-
/**
26-
* @var iterable<mixed, iterable<TKey, T>>
27-
*/
28-
private iterable $iterables;
29-
3025
/**
3126
* @param iterable<mixed, iterable<TKey, T>> $iterables
3227
*/
33-
public function __construct(iterable $iterables)
28+
public function __construct(private iterable $iterables)
3429
{
35-
$this->iterables = $iterables;
3630
}
3731

3832
/**

src/FilterIterableAggregate.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
*/
2222
final class FilterIterableAggregate implements IteratorAggregate
2323
{
24-
/**
25-
* @var iterable<TKey, T>
26-
*/
27-
private iterable $iterable;
28-
2924
/**
3025
* @var Closure(T, TKey, iterable<TKey, T>): bool
3126
*/
@@ -35,9 +30,8 @@ final class FilterIterableAggregate implements IteratorAggregate
3530
* @param iterable<TKey, T> $iterable
3631
* @param (Closure(T, TKey, iterable<TKey, T>): bool) $predicate
3732
*/
38-
public function __construct(iterable $iterable, Closure $predicate)
33+
public function __construct(private iterable $iterable, Closure $predicate)
3934
{
40-
$this->iterable = $iterable;
4135
$this->predicate = $predicate;
4236
}
4337

src/InterruptableIterableIteratorAggregate.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,11 @@ final class InterruptableIterableIteratorAggregate implements IteratorAggregate
2222
{
2323
public const BREAK = 'break';
2424

25-
/**
26-
* @var iterable<TKey, T>
27-
*/
28-
private iterable $iterable;
29-
3025
/**
3126
* @param iterable<TKey, T> $iterable
3227
*/
33-
public function __construct(iterable $iterable)
28+
public function __construct(private iterable $iterable)
3429
{
35-
$this->iterable = $iterable;
3630
}
3731

3832
/**

src/IterableIteratorAggregate.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@
2020
*/
2121
final class IterableIteratorAggregate implements IteratorAggregate
2222
{
23-
/**
24-
* @var iterable<TKey, T>
25-
*/
26-
private iterable $iterable;
27-
2823
/**
2924
* @param iterable<TKey, T> $iterable
3025
*/
31-
public function __construct(iterable $iterable)
26+
public function __construct(private iterable $iterable)
3227
{
33-
$this->iterable = $iterable;
3428
}
3529

3630
/**

src/LimitIterableAggregate.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,11 @@
2121
*/
2222
final class LimitIterableAggregate implements IteratorAggregate
2323
{
24-
/**
25-
* @var iterable<TKey, T>
26-
*/
27-
private iterable $iterable;
28-
29-
private int $limit;
30-
31-
private int $offset;
32-
3324
/**
3425
* @param iterable<TKey, T> $iterable
3526
*/
36-
public function __construct(iterable $iterable, int $offset = 0, int $limit = -1)
27+
public function __construct(private iterable $iterable, private int $offset = 0, private int $limit = -1)
3728
{
38-
$this->iterable = $iterable;
39-
$this->offset = $offset;
40-
$this->limit = $limit;
4129
}
4230

4331
/**

src/MapIterableAggregate.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@ final class MapIterableAggregate implements IteratorAggregate
2727
*/
2828
private Closure $closure;
2929

30-
/**
31-
* @var iterable<TKey, T>
32-
*/
33-
private iterable $iterable;
34-
3530
/**
3631
* @param iterable<TKey, T> $iterable
3732
* @param (Closure(T, TKey, iterable<TKey, T>): W) $closure
3833
*/
39-
public function __construct(iterable $iterable, Closure $closure)
34+
public function __construct(private iterable $iterable, Closure $closure)
4035
{
41-
$this->iterable = $iterable;
4236
$this->closure = $closure;
4337
}
4438

src/MersenneTwisterRNGIteratorAggregate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getIterator(): Generator
3737

3838
// @phpstan-ignore-next-line
3939
while (true) {
40-
yield mt_rand($this->min, $this->max);
40+
yield random_int($this->min, $this->max);
4141
}
4242
}
4343

src/MultipleIterableAggregate.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,12 @@
2121
*/
2222
final class MultipleIterableAggregate implements IteratorAggregate
2323
{
24-
/**
25-
* @var (0|1|2|3)
26-
*/
27-
private int $flags;
28-
29-
/**
30-
* @var iterable<array-key, iterable<TKey, T>>
31-
*/
32-
private iterable $iterables;
33-
3424
/**
3525
* @param iterable<array-key, iterable<TKey, T>> $iterables
3626
* @param (0|1|2|3) $flags
3727
*/
38-
public function __construct(iterable $iterables, int $flags = MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC)
28+
public function __construct(private iterable $iterables, private int $flags = MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC)
3929
{
40-
$this->flags = $flags;
41-
$this->iterables = $iterables;
4230
}
4331

4432
/**

src/NormalizeIterableAggregate.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@
2020
*/
2121
final class NormalizeIterableAggregate implements IteratorAggregate
2222
{
23-
/**
24-
* @var iterable<TKey, T>
25-
*/
26-
private iterable $iterable;
27-
2823
/**
2924
* @param iterable<TKey, T> $iterable
3025
*/
31-
public function __construct(iterable $iterable)
26+
public function __construct(private iterable $iterable)
3227
{
33-
$this->iterable = $iterable;
3428
}
3529

3630
/**

src/PackIterableAggregate.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@
2020
*/
2121
final class PackIterableAggregate implements IteratorAggregate
2222
{
23-
/**
24-
* @var iterable<TKey, T>
25-
*/
26-
private iterable $iterable;
27-
2823
/**
2924
* @param iterable<TKey, T> $iterable
3025
*/
31-
public function __construct(iterable $iterable)
26+
public function __construct(private iterable $iterable)
3227
{
33-
$this->iterable = $iterable;
3428
}
3529

3630
/**

src/RandomIterableAggregate.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ final class RandomIterableAggregate implements IteratorAggregate
2525
*/
2626
private PackIterableAggregate $iteratorAggregate;
2727

28-
private int $seed;
29-
3028
/**
3129
* @param iterable<TKey, T> $iterable
3230
*/
33-
public function __construct(iterable $iterable, int $seed = 0)
31+
public function __construct(iterable $iterable, private int $seed = 0)
3432
{
3533
$this->iteratorAggregate = new PackIterableAggregate($iterable);
36-
$this->seed = $seed;
3734
}
3835

3936
/**
@@ -56,7 +53,7 @@ private function randomize(iterable $iterable, int $seed): Generator
5653
$queue = [];
5754

5855
foreach (new UnpackIterableAggregate($iterable) as $key => $value) {
59-
if (0 === mt_rand(0, $seed)) {
56+
if (0 === random_int(0, $seed)) {
6057
yield $key => $value;
6158

6259
continue;

src/ReductionIterableAggregate.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,14 @@ final class ReductionIterableAggregate implements IteratorAggregate
2727
*/
2828
private Closure $closure;
2929

30-
/**
31-
* @var W
32-
*/
33-
private mixed $initial;
34-
35-
/**
36-
* @var iterable<TKey, T>
37-
*/
38-
private iterable $iterable;
39-
4030
/**
4131
* @param iterable<TKey, T> $iterable
4232
* @param (Closure(W, T, TKey, iterable<TKey, T>): W) $closure
4333
* @param W $initial
4434
*/
45-
public function __construct(iterable $iterable, Closure $closure, mixed $initial)
35+
public function __construct(private iterable $iterable, Closure $closure, private mixed $initial)
4636
{
47-
$this->iterable = $iterable;
4837
$this->closure = $closure;
49-
$this->initial = $initial;
5038
}
5139

5240
/**

src/ResourceIteratorAggregate.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
*/
2121
final class ResourceIteratorAggregate implements IteratorAggregate
2222
{
23-
private bool $closeResource;
24-
2523
/**
2624
* @var resource
2725
*/
@@ -30,14 +28,13 @@ final class ResourceIteratorAggregate implements IteratorAggregate
3028
/**
3129
* @param false|resource $resource
3230
*/
33-
public function __construct($resource, bool $closeResource = false)
31+
public function __construct($resource, private bool $closeResource = false)
3432
{
3533
if (!is_resource($resource) || 'stream' !== get_resource_type($resource)) {
3634
throw new InvalidArgumentException('Invalid resource type.');
3735
}
3836

3937
$this->resource = $resource;
40-
$this->closeResource = $closeResource;
4138
}
4239

4340
/**

src/StringIteratorAggregate.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@
1717
*/
1818
final class StringIteratorAggregate implements IteratorAggregate
1919
{
20-
private string $data;
21-
22-
private string $delimiter;
23-
24-
public function __construct(string $data, string $delimiter = '')
20+
public function __construct(private string $data, private string $delimiter = '')
2521
{
26-
$this->data = $data;
27-
$this->delimiter = $delimiter;
2822
}
2923

3024
/**

src/TypedIterableAggregate.php

+2-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use InvalidArgumentException;
1414
use IteratorAggregate;
1515

16-
use function get_class;
1716
use function gettype;
1817
use function is_object;
1918

@@ -30,19 +29,12 @@ final class TypedIterableAggregate implements IteratorAggregate
3029
*/
3130
private $getType;
3231

33-
/**
34-
* @var iterable<TKey, T>
35-
*/
36-
private iterable $iterable;
37-
3832
/**
3933
* @param iterable<TKey, T> $iterable
4034
* @param callable(mixed): string $getType
4135
*/
42-
public function __construct(iterable $iterable, ?callable $getType = null)
36+
public function __construct(private iterable $iterable, ?callable $getType = null)
4337
{
44-
$this->iterable = $iterable;
45-
4638
$this->getType = $getType ??
4739
static function (mixed $variable): string {
4840
if (!is_object($variable)) {
@@ -52,7 +44,7 @@ static function (mixed $variable): string {
5244
$interfaces = class_implements($variable);
5345

5446
if ([] === $interfaces || false === $interfaces) {
55-
return get_class($variable);
47+
return $variable::class;
5648
}
5749

5850
sort($interfaces);

0 commit comments

Comments
 (0)