Skip to content

Commit 6ec48e0

Browse files
committed
Improve IdnaInfo
1 parent 95bbff5 commit 6ec48e0

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/IdnaInfo.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,21 @@ final class IdnaInfo
3636

3737
private int $errors;
3838

39+
/**
40+
* @var array<int, string>
41+
*/
42+
private array $errorList;
43+
3944
private function __construct(string $result, bool $isTransitionalDifferent, int $errors)
4045
{
4146
$this->result = $result;
4247
$this->errors = $errors;
4348
$this->isTransitionalDifferent = $isTransitionalDifferent;
49+
$this->errorList = array_filter(
50+
self::ERRORS,
51+
fn (int $error): bool => 0 !== ($error & $this->errors),
52+
ARRAY_FILTER_USE_KEY
53+
);
4454
}
4555

4656
/**
@@ -76,18 +86,14 @@ public function errors(): int
7686

7787
public function error(int $error): ?string
7888
{
79-
return 0 === ($this->errors & $error) ? null : self::ERRORS[$error];
89+
return $this->errorList[$error] ?? null;
8090
}
8191

8292
/**
8393
* @return array<int, string>
8494
*/
8595
public function errorList(): array
8696
{
87-
return array_filter(
88-
self::ERRORS,
89-
fn (int $errorByte): bool => 0 !== ($errorByte & $this->errors),
90-
ARRAY_FILTER_USE_KEY
91-
);
97+
return $this->errorList;
9298
}
9399
}

0 commit comments

Comments
 (0)