Skip to content

Commit e7dc009

Browse files
rob006claude
andcommitted
Add support for PHP 8.x, drop support for PHP < 7.4.
- Add native return types to Iterator and Countable methods in RangesCollection (fixes deprecation warnings on PHP 8.1+). - Make $previous parameter of RangeSplitException::__construct() explicitly nullable (fixes deprecation warning on PHP 8.4+). - Use typed properties. - Upgrade PHPUnit to 9.6 and convert deprecations to exceptions in tests. - Add GitHub Actions workflow running tests on PHP 7.4 - 8.5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bf4a375 commit e7dc009

7 files changed

Lines changed: 53 additions & 20 deletions

File tree

‎.github/workflows/tests.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
tests:
9+
name: PHP ${{ matrix.php }}
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
16+
17+
steps:
18+
- uses: actions/checkout@v5
19+
20+
- uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php }}
23+
coverage: none
24+
ini-values: error_reporting=-1, display_errors=On
25+
26+
- uses: ramsey/composer-install@v3
27+
28+
- run: vendor/bin/phpunit

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
vendor/
33
composer.lock
4+
.phpunit.result.cache

‎composer.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"source": "https://github.com/rob006-software/ranges"
2222
},
2323
"require": {
24-
"php": "^7.1"
24+
"php": "^7.4 || ^8.0"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^7.3"
27+
"phpunit/phpunit": "^9.6"
2828
},
2929
"autoload": {
3030
"psr-4": {

‎phpunit.xml‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.3/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
forceCoversAnnotation="true"
66
beStrictAboutCoversAnnotation="true"
77
beStrictAboutOutputDuringTests="true"
88
beStrictAboutTodoAnnotatedTests="true"
9+
convertDeprecationsToExceptions="true"
910
verbose="true">
1011
<testsuites>
1112
<testsuite name="default">
1213
<directory suffix="Test.php">tests</directory>
1314
</testsuite>
1415
</testsuites>
1516

16-
<filter>
17-
<whitelist processUncoveredFilesFromWhitelist="true">
17+
<coverage processUncoveredFiles="true">
18+
<include>
1819
<directory suffix=".php">src</directory>
19-
</whitelist>
20-
</filter>
20+
</include>
21+
</coverage>
2122
</phpunit>

‎src/Range.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
*/
2525
class Range implements RangeInterface {
2626

27-
private $from;
28-
private $to;
27+
private ?int $from;
28+
private ?int $to;
2929

3030
/**
3131
* Range constructor.

‎src/RangesCollection.php‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class RangesCollection implements RangesCollectionInterface, Iterator, Countable
3131
/**
3232
* @var RangeInterface[]
3333
*/
34-
private $ranges = [];
35-
private $position = 0;
34+
private array $ranges = [];
35+
private int $position = 0;
3636

3737
/**
3838
* RangesCollection constructor.
@@ -125,27 +125,27 @@ public function getRanges(): array {
125125
return $this->ranges;
126126
}
127127

128-
public function rewind() {
128+
public function rewind(): void {
129129
$this->position = 0;
130130
}
131131

132-
public function current() {
133-
return $this->ranges[$this->position];
132+
public function current(): ?RangeInterface {
133+
return $this->ranges[$this->position] ?? null;
134134
}
135135

136-
public function key() {
136+
public function key(): int {
137137
return $this->position;
138138
}
139139

140-
public function next() {
140+
public function next(): void {
141141
$this->position++;
142142
}
143143

144-
public function valid() {
144+
public function valid(): bool {
145145
return isset($this->ranges[$this->position]);
146146
}
147147

148-
public function count() {
148+
public function count(): int {
149149
return count($this->ranges);
150150
}
151151
}

‎src/exceptions/RangeSplitException.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
*/
2424
class RangeSplitException extends RangeException {
2525

26-
private $ranges;
26+
/**
27+
* @var RangeInterface[]
28+
*/
29+
private array $ranges;
2730

2831
public function __construct(
2932
string $message,
3033
RangeInterface $range1,
3134
RangeInterface $range2,
3235
int $code = 0,
33-
Throwable $previous = null
36+
?Throwable $previous = null
3437
) {
3538
$this->ranges = [$range1, $range2];
3639

0 commit comments

Comments
 (0)