Blob::md5()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\RfcLinc\Updater;
6
7
class Blob
8
{
9
    /** @var string */
10
    private $name;
11
12
    /** @var string */
13
    private $url;
14
15
    /** @var string */
16
    private $contentMd5;
17
18
    /** @var string */
19
    private $md5;
20
21 5
    public function __construct(
22
        string $name,
23
        string $url,
24
        string $contentMd5
25
    ) {
26 5
        $this->name = $name;
27 5
        $this->url = $url;
28 5
        $this->contentMd5 = $contentMd5;
29 5
        $this->md5 = $this->convertMd5BlobToMd5Standard($contentMd5);
30 5
    }
31
32 9
    public static function convertMd5BlobToMd5Standard(string $stringBase64): string
33
    {
34
        // base64 -> decoded string -> split to bytes -> map to hex -> implode all hex
35 9
        return implode(
36 9
            array_map(
37 9
                function (string $input): string {
38 9
                    return bin2hex($input);
39 9
                },
40 9
                str_split(
41 9
                    base64_decode($stringBase64) ? : '' // base64 can return FALSE
42 9
                ) ? : [] // str_split can return FALSE
43
            )
44
        );
45
    }
46
47 2
    public function name(): string
48
    {
49 2
        return $this->name;
50
    }
51
52 3
    public function url(): string
53
    {
54 3
        return $this->url;
55
    }
56
57 1
    public function contentMd5(): string
58
    {
59 1
        return $this->contentMd5;
60
    }
61
62 3
    public function md5(): string
63
    {
64 3
        return $this->md5;
65
    }
66
}
67