Completed
Branch Version3 (6a4ebc)
by Sam
01:27
created

DecodeException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 24
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A binaryToHex() 0 8 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)
19
    {
20 2
        $message = sprintf('Unable to decode %s record rdata from binary data "%s"', $type, $this->binaryToHex($rdata));
21 2
        parent::__construct($message);
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