Passed
Branch add-cache (e7677a)
by Michael
02:58 queued 36s
created

KeyConflictException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
crap 2
1
<?php
2
3
namespace micmania1\config\Exceptions;
4
5
use Exception;
6
7
class KeyConflictException extends Exception
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $key;
13
14
    /**
15
     * @var array
16
     */
17
    protected $mine;
18
19
    /**
20
     * @var array
21
     */
22
    protected $theirs;
23
24
    public function __construct($key, $mine, $theirs)
25
    {
26
        $this->key = $key;
27
        $this->mine = $mine;
28
        $this->theirs = $theirs;
29
30
        parent::__construct($this->__toString());
31
    }
32
33
    public function __toString()
34
    {
35
        $error = <<<'ERROR'
36
Key clash on key '%s'.
37
38
Mine:
39
%s
40
41
Thiers:
42
%s
43
44
ERROR;
45
46
        return sprintf(
47
            $error,
48
            $this->key,
49
            print_r($this->mine, true),
50
            print_r($this->theirs, true)
51
        );
52
    }
53
}
54