Passed
Push — master ( 87c83f...ac88b3 )
by Sam
03:00
created

DecodeException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A binaryToHex() 0 7 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Badcow DNS Library.
7
 *
8
 * (c) Samuel Williams <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Badcow\DNS\Rdata;
15
16
class DecodeException extends \Exception
17
{
18 2
    public function __construct(string $type, string $rdata, int $code = 0, \Throwable $previous = null)
19
    {
20 2
        $message = sprintf('Unable to decode %s record rdata from binary data "%s"', $type, $this->binaryToHex($rdata));
21 2
        parent::__construct($message, $code, $previous);
22 2
    }
23
24
    /**
25
     * Convert a binary string into hexadecimal values.
26
     *
27
     * @param string $rdata
28
     *
29
     * @return string
30
     */
31 2
    public function binaryToHex(string $rdata): string
32
    {
33
        $hex = array_map(function ($char) {
34 2
            return sprintf('0x%02x', ord($char));
35 2
        }, str_split($rdata));
36
37 2
        return implode(' ', $hex);
38
    }
39
}
40