• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kornrunner / php-blurhash / 13845548032

13 Mar 2025 10:07PM UTC coverage: 100.0%. Remained the same
13845548032

push

github

web-flow
github: workflow: updates (#11)

136 of 136 relevant lines covered (100.0%)

4.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Base83.php
1
<?php
2

3
namespace kornrunner\Blurhash;
4

5
use InvalidArgumentException;
6

7
class Base83 {
8
    private const ALPHABET = [
9
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
10
        'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
11
        'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
12
        'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
13
        'u', 'v', 'w', 'x', 'y', 'z', '#', '$', '%', '*', '+', ',', '-', '.',
14
        ':', ';', '=', '?', '@', '[', ']', '^', '_', '{', '|', '}', '~'
15
    ];
16

17
    private const BASE = 83;
18

19
    public static function encode(int $value, int $length): string {
20
        if (intdiv($value, self::BASE ** $length) != 0) {
7✔
21
            throw new InvalidArgumentException('Specified length is too short to encode given value.');
1✔
22
        }
23

24
        $result = '';
6✔
25
        for ($i = 1; $i <= $length; $i++) {
6✔
26
            $digit   = intdiv($value, self::BASE ** ($length - $i)) % self::BASE;
6✔
27
            $result .= self::ALPHABET[$digit];
6✔
28
        }
29
        return $result;
6✔
30
    }
31

32
    public static function decode(string $hash): int {
33
        $result = 0;
10✔
34
        foreach (str_split($hash) as $char) {
10✔
35
            $result = $result * self::BASE + (int) array_search($char, self::ALPHABET, true);
10✔
36
        }
37
        return $result;
10✔
38
    }
39
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc