Skip to content

Commit e9eb903

Browse files
committed
Dropping support for PHP7 and PHP8.0
1 parent d8724b8 commit e9eb903

29 files changed

+171
-441
lines changed

.github/workflows/build.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,4 @@ jobs:
2323
- run: composer update --no-progress ${{ matrix.composer-flags }}
2424
- run: composer phpunit
2525
- run: composer phpstan
26-
if: ${{ matrix.php == '8.1' }}
27-
- run: composer psalm
28-
if: ${{ matrix.php == '8.1' }}
2926
- run: composer phpcs
30-
if: ${{ matrix.php == '8.1' }}

composer.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@
5353
"phpstan/phpstan-phpunit": "^1.1.1",
5454
"phpstan/phpstan-strict-rules": "^1.2.3",
5555
"phpunit/phpunit": "^9.5.20",
56-
"psalm/plugin-phpunit": "^0.16.1",
5756
"psr/http-factory": "^1.0",
5857
"psr/simple-cache": "^1.0",
59-
"symfony/cache": "^v5.0.0 || ^v6.0.0",
60-
"vimeo/psalm": "^4.23.0"
58+
"symfony/cache": "^v5.0.0 || ^v6.0.0"
6159
},
6260
"suggest": {
6361
"psr/http-client-implementation": "To use the storage functionnality which depends on PSR-18",
@@ -74,20 +72,17 @@
7472
"phpcs": "php-cs-fixer fix -vvv --diff --dry-run --allow-risky=yes --ansi",
7573
"phpcs:fix": "php-cs-fixer fix -vvv --allow-risky=yes --ansi",
7674
"phpstan": "phpstan analyse -l max -c phpstan.neon src --memory-limit=256M --ansi",
77-
"psalm": "psalm --show-info=true",
7875
"phpunit": "XDEBUG_MODE=coverage phpunit --coverage-text",
7976
"test": [
8077
"@phpunit",
8178
"@phpstan",
82-
"@psalm",
8379
"@phpcs"
8480
]
8581
},
8682
"scripts-descriptions": {
8783
"phpcs": "Runs coding style test suite",
8884
"phpcs:fix": "Fix the package coding style",
8985
"phpstan": "Runs complete codebase static analysis",
90-
"psalm": "Runs complete codebase static analysis",
9186
"phpunit": "Runs unit and functional testing",
9287
"test": "Runs the complete test suite"
9388
},

src/Domain.php

Lines changed: 23 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Pdp;
66

77
use Iterator;
8-
use TypeError;
8+
use Stringable;
99
use function array_count_values;
1010
use function array_keys;
1111
use function array_reverse;
@@ -14,13 +14,9 @@
1414
use function count;
1515
use function explode;
1616
use function filter_var;
17-
use function gettype;
1817
use function implode;
1918
use function in_array;
20-
use function is_object;
21-
use function is_scalar;
2219
use function ksort;
23-
use function method_exists;
2420
use function preg_match;
2521
use function rawurldecode;
2622
use function strtolower;
@@ -44,19 +40,11 @@ final class Domain implements DomainName
4440

4541
private const REGEXP_URI_DELIMITERS = '/[:\/?#\[\]@ ]/';
4642

47-
/**
48-
* @var array<int, string>
49-
*/
43+
/** @var array<int, string> */
5044
private array $labels;
51-
5245
private ?string $domain;
5346

54-
private string $type;
55-
56-
/**
57-
* @param null|mixed $domain
58-
*/
59-
private function __construct(string $type, $domain)
47+
private function __construct(private string $type, DomainNameProvider|Host|Stringable|string|int|null $domain)
6048
{
6149
$this->type = $type;
6250
$this->domain = $this->parseDomain($domain);
@@ -71,26 +59,17 @@ public static function __set_state(array $properties): self
7159
return new self($properties['type'], $properties['domain']);
7260
}
7361

74-
/**
75-
* @param null|mixed $domain
76-
*/
77-
public static function fromIDNA2003($domain): self
62+
public static function fromIDNA2003(DomainNameProvider|Host|Stringable|string|int|null $domain): self
7863
{
7964
return new self(self::IDNA_2003, $domain);
8065
}
8166

82-
/**
83-
* @param null|mixed $domain
84-
*/
85-
public static function fromIDNA2008($domain): self
67+
public static function fromIDNA2008(DomainNameProvider|Host|Stringable|string|int|null $domain): self
8668
{
8769
return new self(self::IDNA_2008, $domain);
8870
}
8971

90-
/**
91-
* @param mixed $domain a domain
92-
*/
93-
private function parseDomain($domain): ?string
72+
private function parseDomain(DomainNameProvider|Host|Stringable|string|int|null $domain): ?string
9473
{
9574
if ($domain instanceof DomainNameProvider) {
9675
$domain = $domain->domain();
@@ -110,25 +89,19 @@ private function parseDomain($domain): ?string
11089
*
11190
* For example: parse('wWw.uLb.Ac.be') should return ['www.ulb.ac.be', ['be', 'ac', 'ulb', 'www']];.
11291
*
113-
* @param mixed $domain a domain
114-
*
11592
* @throws SyntaxError If the host is not a domain
11693
* @throws SyntaxError If the domain is not a host
11794
*/
118-
private function parseValue($domain): ?string
95+
private function parseValue(Stringable|string|int|null $domain): ?string
11996
{
12097
if (null === $domain) {
12198
return null;
12299
}
123100

124-
if (is_object($domain) && method_exists($domain, '__toString')) {
101+
if ($domain instanceof Stringable) {
125102
$domain = (string) $domain;
126103
}
127104

128-
if (!is_scalar($domain)) {
129-
throw new TypeError('The domain must be a string, a stringable object, a Host object or NULL; `'.gettype($domain).'` given.');
130-
}
131-
132105
$domain = (string) $domain;
133106
if ('' === $domain) {
134107
return '';
@@ -235,10 +208,6 @@ public function labels(): array
235208
return $this->labels;
236209
}
237210

238-
/**
239-
* @psalm-suppress MoreSpecificReturnType
240-
* @psalm-suppress LessSpecificReturnStatement
241-
*/
242211
public function toAscii(): self
243212
{
244213
if (null === $this->domain) {
@@ -253,10 +222,6 @@ public function toAscii(): self
253222
return new self($this->type, $domain);
254223
}
255224

256-
/**
257-
* @psalm-suppress MoreSpecificReturnType
258-
* @psalm-suppress LessSpecificReturnStatement
259-
*/
260225
public function toUnicode(): self
261226
{
262227
if (null === $this->domain) {
@@ -273,12 +238,8 @@ public function toUnicode(): self
273238

274239
/**
275240
* Filter a subdomain to update the domain part.
276-
*
277-
* @param string|object|null $domain a domain
278-
*
279-
* @throws TypeError if the domain can not be converted
280241
*/
281-
private function normalize($domain): ?string
242+
private function normalize(DomainNameProvider|Host|Stringable|string|null $domain): ?string
282243
{
283244
if ($domain instanceof DomainNameProvider) {
284245
$domain = $domain->domain();
@@ -292,33 +253,32 @@ private function normalize($domain): ?string
292253
return $domain;
293254
}
294255

295-
if ((!is_string($domain) && !method_exists($domain, '__toString'))) {
296-
throw new TypeError('The label must be a '.Host::class.', a stringable object or a string, `'.gettype($domain).'` given.');
297-
}
298-
299256
$domain = (string) $domain;
300-
if (null === $this->domain) {
301-
return $domain;
302-
}
303-
304-
if (!$this->isAscii()) {
305-
return $this->domainToUnicode($domain);
306-
}
307257

308-
return $this->domainToAscii($domain);
258+
return match (true) {
259+
null === $this->domain => $domain,
260+
$this->isAscii() => $this->domainToAscii($domain),
261+
default => $this->domainToUnicode($domain),
262+
};
309263
}
310264

311-
public function prepend($label): self
265+
/**
266+
* @throws CannotProcessHost
267+
*/
268+
public function prepend(DomainNameProvider|Host|string|Stringable|null $label): self
312269
{
313270
return $this->withLabel(count($this->labels), $label);
314271
}
315272

316-
public function append($label): self
273+
/**
274+
* @throws CannotProcessHost
275+
*/
276+
public function append(DomainNameProvider|Host|string|Stringable|null $label): self
317277
{
318278
return $this->withLabel(- count($this->labels) - 1, $label);
319279
}
320280

321-
public function withLabel(int $key, $label): self
281+
public function withLabel(int $key, DomainNameProvider|Host|string|Stringable|null $label): self
322282
{
323283
$nbLabels = count($this->labels);
324284
if ($key < - $nbLabels - 1 || $key > $nbLabels) {

src/DomainName.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Iterator;
88
use IteratorAggregate;
9+
use Stringable;
910

1011
/**
1112
* @see https://tools.ietf.org/html/rfc1034#section-3.5
@@ -62,19 +63,15 @@ public function getIterator(): Iterator;
6263
* Prepends a label to the domain.
6364
*
6465
* @see ::withLabel
65-
*
66-
* @param string|null|object $label a domain label
6766
*/
68-
public function prepend($label): self;
67+
public function prepend(DomainNameProvider|Host|string|Stringable|null $label): self;
6968

7069
/**
7170
* Appends a label to the domain.
7271
*
7372
* @see ::withLabel
74-
*
75-
* @param string|null|object $label a domain label
7673
*/
77-
public function append($label): self;
74+
public function append(DomainNameProvider|Host|string|Stringable|null $label): self;
7875

7976
/**
8077
* Returns an instance with the specified label added at the specified key.
@@ -85,12 +82,12 @@ public function append($label): self;
8582
* If $key is non-negative, the added label will be the label at $key position from the start.
8683
* If $key is negative, the added label will be the label at $key position from the end.
8784
*
88-
* @param string|null|object $label a domain label
85+
* @param string|null|Stringable|Host|DomainNameProvider $label a domain label
8986
*
9087
* @throws CannotProcessHost If the key is out of bounds
9188
* @throws CannotProcessHost If the label is converted to the NULL value
9289
*/
93-
public function withLabel(int $key, $label): self;
90+
public function withLabel(int $key, DomainNameProvider|Host|string|Stringable|null $label): self;
9491

9592
/**
9693
* Returns an instance with the label at the specified key removed.

src/DomainTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function withLabelWorksProvider(): iterable
315315
public function testWithLabelFailsWithTypeError(): void
316316
{
317317
$this->expectException(TypeError::class);
318-
Domain::fromIDNA2008('example.com')->withLabel(1, new stdClass());
318+
Domain::fromIDNA2008('example.com')->withLabel(1, new stdClass()); /* @phpstan-ignore-line */
319319
}
320320

321321
public function testWithLabelFailsWithInvalidKey(): void

src/IdnaInfo.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,14 @@ final class IdnaInfo
3131
Idna::ERROR_CONTEXTO_PUNCTUATION => 'a label does not meet the IDNA CONTEXTO requirements for punctuation characters. Some punctuation characters "Would otherwise have been DISALLOWED" but are allowed in certain contexts',
3232
];
3333

34-
private string $result;
35-
36-
private bool $isTransitionalDifferent;
37-
38-
private int $errors;
39-
40-
/**
41-
* @var array<int, string>
42-
*/
43-
private array $errorList;
44-
45-
private function __construct(string $result, bool $isTransitionalDifferent, int $errors)
46-
{
47-
$this->result = $result;
48-
$this->errors = $errors;
49-
$this->isTransitionalDifferent = $isTransitionalDifferent;
34+
/** @var array<int, string> */
35+
public readonly array $errorList;
36+
37+
private function __construct(
38+
public readonly string $result,
39+
public readonly bool $isTransitionalDifferent,
40+
public readonly int $errors
41+
) {
5042
$this->errorList = array_filter(
5143
self::ERRORS,
5244
fn (int $error): bool => 0 !== ($error & $this->errors),

src/IdnaInfoTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public function testItCanBeInstantiatedFromArray(): void
2424
$infos = ['result' => '', 'isTransitionalDifferent' => false, 'errors' => 0];
2525
$result = IdnaInfo::fromIntl($infos);
2626

27-
self::assertSame('', $result->result());
28-
self::assertFalse($result->isTransitionalDifferent());
29-
self::assertSame(0, $result->errors());
27+
self::assertSame('', $result->result);
28+
self::assertFalse($result->isTransitionalDifferent);
29+
self::assertSame(0, $result->errors);
3030
self::assertNull($result->error(Idna::ERROR_BIDI));
31-
self::assertCount(0, $result->errorList());
31+
self::assertCount(0, $result->errorList);
3232
}
3333

3434
public function testInvalidSyntaxAfterIDNConversion(): void
@@ -38,9 +38,9 @@ public function testInvalidSyntaxAfterIDNConversion(): void
3838
} catch (SyntaxError $exception) {
3939
$result = $exception->idnaInfo();
4040
self::assertInstanceOf(IdnaInfo::class, $result);
41-
self::assertSame(Idna::ERROR_DISALLOWED, $result->errors());
41+
self::assertSame(Idna::ERROR_DISALLOWED, $result->errors);
4242
self::assertIsString($result->error(Idna::ERROR_DISALLOWED));
43-
self::assertCount(1, $result->errorList());
43+
self::assertCount(1, $result->errorList);
4444
}
4545
}
4646
}

0 commit comments

Comments
 (0)