forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpMinorVersionIterator.php
More file actions
78 lines (64 loc) · 1.66 KB
/
Copy pathPhpMinorVersionIterator.php
File metadata and controls
78 lines (64 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php declare(strict_types = 1);
namespace PHPStan\Php;
use IteratorAggregate;
use Override;
use PHPStan\ShouldNotHappenException;
use Traversable;
use function floor;
/**
* @api
*
* @implements IteratorAggregate<PhpVersion>
*/
final class PhpMinorVersionIterator implements IteratorAggregate
{
private PhpVersion $currentVersion;
public function __construct(
PhpVersion $startVersion,
private PhpVersion $endVersion,
)
{
if ($startVersion->getMajorVersionId() < 5
|| $startVersion->getMajorVersionId() > 8
) {
throw new ShouldNotHappenException();
}
if ($endVersion->getMajorVersionId() < 5
|| $endVersion->getMajorVersionId() > 8
) {
throw new ShouldNotHappenException();
}
$this->currentVersion = $startVersion;
}
#[Override]
public function getIterator(): Traversable
{
yield $this->currentVersion;
while (true) {
if (
$this->currentVersion->getMajorVersionId() === 5
&& $this->currentVersion->getMinorVersionId() === 6
) {
$next = new PhpVersion(70000);
} elseif (
$this->currentVersion->getMajorVersionId() === 7
&& $this->currentVersion->getMinorVersionId() === 4
) {
$next = new PhpVersion(80000);
} else {
$nextMinorVersionId = $this->currentVersion->getVersionId() + 100;
$nextWithZeroPatch = (int) floor($nextMinorVersionId / 100) * 100;
$next = new PhpVersion($nextWithZeroPatch);
}
if ($next->getVersionId() > $this->endVersion->getVersionId()) {
break;
}
$this->currentVersion = $next;
yield $this->currentVersion;
}
if ($this->currentVersion->getVersionId() === $this->endVersion->getVersionId()) {
return;
}
yield $this->endVersion;
}
}