Skip to content

Commit 1b69598

Browse files
committed
Add support for PHP >= 8.1. Fix CS.
1 parent 11db634 commit 1b69598

22 files changed

+101
-96
lines changed

src/Algorithm/HslColorExtractor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ final class HslColorExtractor implements ColorExtractorInterface
2121
public function extractColor(Hash $hash): Color
2222
{
2323
$bytes = $hash->getBytes();
24-
$length = strlen($bytes);
24+
$length = \strlen($bytes);
2525

26-
$byte1 = ord($bytes[$length - 3]);
27-
$byte2 = ord($bytes[$length - 2]);
28-
$byte3 = ord($bytes[$length - 1]);
26+
$byte1 = \ord($bytes[$length - 3]);
27+
$byte2 = \ord($bytes[$length - 2]);
28+
$byte3 = \ord($bytes[$length - 1]);
2929

3030
$hue = (($byte1 << 8) | $byte2) % 360;
3131

3232
$saturationRange = self::MAX_SATURATION - self::MIN_SATURATION;
3333
$saturation = self::MIN_SATURATION + ($byte3 / 255) * $saturationRange;
3434

35-
$byte4 = $length >= 4 ? ord($bytes[$length - 4]) : $byte1;
35+
$byte4 = $length >= 4 ? \ord($bytes[$length - 4]) : $byte1;
3636
$lightnessRange = self::MAX_LIGHTNESS - self::MIN_LIGHTNESS;
3737
$lightness = self::MIN_LIGHTNESS + ($byte4 / 255) * $lightnessRange;
3838

@@ -72,7 +72,7 @@ private function hslToRgb(int $h, float $s, float $l): Color
7272
return new Color(
7373
(int) round(($r + $m) * 255),
7474
(int) round(($g + $m) * 255),
75-
(int) round(($b + $m) * 255)
75+
(int) round(($b + $m) * 255),
7676
);
7777
}
7878
}

src/Algorithm/LegacyColorExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class LegacyColorExtractor implements ColorExtractorInterface
1616
public function extractColor(Hash $hash): Color
1717
{
1818
$hex = $hash->hex;
19-
$length = strlen($hex);
19+
$length = \strlen($hex);
2020

2121
$r = hexdec($hex[$length - 3]) * 16;
2222
$g = hexdec($hex[$length - 2]) * 16;
@@ -25,7 +25,7 @@ public function extractColor(Hash $hash): Color
2525
return new Color(
2626
min(255, (int) $r),
2727
min(255, (int) $g),
28-
min(255, (int) $b)
28+
min(255, (int) $b),
2929
);
3030
}
3131
}

src/Algorithm/SymmetricGridGenerator.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function generate(Hash $hash, GridSize $gridSize): Grid
2828

2929
for ($row = 0; $row < $gridSize->rows; $row++) {
3030
for ($col = 0; $col < $halfCols; $col++) {
31-
$byteIndex = ($row * $halfCols + $col) % strlen($bytes);
32-
$byte = ord($bytes[$byteIndex]);
31+
$byteIndex = ($row * $halfCols + $col) % \strlen($bytes);
32+
$byte = \ord($bytes[$byteIndex]);
3333

3434
$filled = $byte >= 128;
3535

@@ -56,23 +56,26 @@ public function generate(Hash $hash, GridSize $gridSize): Grid
5656
$cells = $this->ensureMinimumFill($cells, $bytes, $gridSize, $filledCount, $minRequired);
5757
}
5858

59-
usort($cells, static fn (Cell $a, Cell $b): int =>
60-
$a->y === $b->y ? $a->x <=> $b->x : $a->y <=> $b->y
59+
usort(
60+
$cells,
61+
static fn (Cell $a, Cell $b): int =>
62+
$a->y === $b->y ? $a->x <=> $b->x : $a->y <=> $b->y,
6163
);
6264

6365
return new Grid($gridSize, $cells);
6466
}
6567

6668
/**
6769
* @param array<Cell> $cells
70+
*
6871
* @return array<Cell>
6972
*/
7073
private function ensureMinimumFill(
7174
array $cells,
7275
string $bytes,
7376
GridSize $gridSize,
7477
int $currentFilled,
75-
int $minRequired
78+
int $minRequired,
7679
): array {
7780
$needed = $minRequired - $currentFilled;
7881
$emptyCells = [];
@@ -97,7 +100,7 @@ private function ensureMinimumFill(
97100
continue;
98101
}
99102

100-
$byte = ord($bytes[$byteIndex % strlen($bytes)]);
103+
$byte = \ord($bytes[$byteIndex % \strlen($bytes)]);
101104
$byteIndex++;
102105

103106
if ($byte % 3 === 0) {

src/Exception/ExtensionNotLoadedException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ final class ExtensionNotLoadedException extends IdenticonException
88
{
99
public static function forExtension(string $extension): self
1010
{
11-
return new self(sprintf(
11+
return new self(\sprintf(
1212
'The PHP extension "%s" is not loaded. Please install or enable it.',
13-
$extension
13+
$extension,
1414
));
1515
}
1616
}

src/Exception/InvalidColorException.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ final class InvalidColorException extends IdenticonException
88
{
99
public static function invalidHex(string $hex): self
1010
{
11-
return new self(sprintf(
11+
return new self(\sprintf(
1212
'Invalid hexadecimal color: "%s". Expected format: #RGB, #RRGGBB, RGB, or RRGGBB.',
13-
$hex
13+
$hex,
1414
));
1515
}
1616

1717
public static function outOfRange(string $component, int $value): self
1818
{
19-
return new self(sprintf(
19+
return new self(\sprintf(
2020
'Color component "%s" value %d is out of range. Expected 0-255.',
2121
$component,
22-
$value
22+
$value,
2323
));
2424
}
2525

2626
public static function invalidArray(): self
2727
{
2828
return new self(
29-
'Invalid color array. Expected [r, g, b] or [r, g, b, a] or ["r" => r, "g" => g, "b" => b].'
29+
'Invalid color array. Expected [r, g, b] or [r, g, b, a] or ["r" => r, "g" => g, "b" => b].',
3030
);
3131
}
3232
}

src/Exception/InvalidGridSizeException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ final class InvalidGridSizeException extends IdenticonException
88
{
99
public static function columnsOutOfRange(int $columns, int $min, int $max): self
1010
{
11-
return new self(sprintf(
11+
return new self(\sprintf(
1212
'Grid columns %d is out of range. Expected %d-%d.',
1313
$columns,
1414
$min,
15-
$max
15+
$max,
1616
));
1717
}
1818

1919
public static function rowsOutOfRange(int $rows, int $min, int $max): self
2020
{
21-
return new self(sprintf(
21+
return new self(\sprintf(
2222
'Grid rows %d is out of range. Expected %d-%d.',
2323
$rows,
2424
$min,
25-
$max
25+
$max,
2626
));
2727
}
2828
}

src/Exception/InvalidSizeException.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ final class InvalidSizeException extends IdenticonException
88
{
99
public static function tooSmall(int $size, int $minimum): self
1010
{
11-
return new self(sprintf(
11+
return new self(\sprintf(
1212
'Size %d is too small. Minimum allowed: %d.',
1313
$size,
14-
$minimum
14+
$minimum,
1515
));
1616
}
1717

1818
public static function tooLarge(int $size, int $maximum): self
1919
{
20-
return new self(sprintf(
20+
return new self(\sprintf(
2121
'Size %d is too large. Maximum allowed: %d.',
2222
$size,
23-
$maximum
23+
$maximum,
2424
));
2525
}
2626

2727
public static function notPositive(int $size): self
2828
{
29-
return new self(sprintf(
29+
return new self(\sprintf(
3030
'Size must be a positive integer. Got: %d.',
31-
$size
31+
$size,
3232
));
3333
}
3434
}

src/Grid/Cell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public function __construct(
1010
public int $x,
1111
public int $y,
12-
public bool $filled
12+
public bool $filled,
1313
) {
1414
}
1515

src/Grid/Grid.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
public function __construct(
1515
public GridSize $gridSize,
16-
private array $cells
16+
private array $cells,
1717
) {
1818
}
1919

@@ -53,7 +53,7 @@ public function isFilled(int $x, int $y): bool
5353

5454
public function getFilledCount(): int
5555
{
56-
return count($this->getFilledCells());
56+
return \count($this->getFilledCells());
5757
}
5858

5959
public function getFillRatio(): float

src/Identicon.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function generate(
2828
string $string,
2929
int $size = 64,
3030
string|array|null $color = null,
31-
string|array|null $backgroundColor = null
31+
string|array|null $backgroundColor = null,
3232
): string {
3333
$builder = (new IdenticonBuilder())->size($size);
3434

@@ -54,10 +54,10 @@ public function getImageDataUri(string $string): string
5454
{
5555
$result = $this->process($string);
5656

57-
return sprintf(
57+
return \sprintf(
5858
'data:%s;base64,%s',
5959
$result['mimeType'],
60-
base64_encode($result['data'])
60+
base64_encode($result['data']),
6161
);
6262
}
6363

0 commit comments

Comments
 (0)