Passed
Push — master ( 025a78...0027ff )
by Sebastian
03:09
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AppUtils;
6
7
class ConvertHelper_ThrowableInfo_StringConverter
8
{
9
    /**
10
     * @var ConvertHelper_ThrowableInfo
11
     */
12
    private $info;
13
14
    public function __construct(ConvertHelper_ThrowableInfo $info)
15
    {
16
        $this->info = $info;
17
    }
18
19
    public function toString() : string
20
    {
21
        return
22
            $this->renderMessage() .
23
            $this->renderCalls() .
24
            $this->renderPrevious();
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    private function renderMessage() : string
31
    {
32
        $string = 'Exception';
33
34
        if ($this->info->hasCode())
35
        {
36
            $string .= ' #' . $this->info->getCode();
37
        }
38
39
        $string .=
40
            ': ' .
41
            $this->info->getMessage() .
42
            PHP_EOL;
43
44
        return $string;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    private function renderCalls() : string
51
    {
52
        $calls = $this->info->getCalls();
53
54
        $string = '';
55
56
        foreach ($calls as $call)
57
        {
58
            $string .= $call->toString() . PHP_EOL;
59
        }
60
61
        return $string;
62
    }
63
64
    /**
65
     * @return string
66
     * @throws ConvertHelper_Exception
67
     */
68
    private function renderPrevious() : string
69
    {
70
        if (!$this->info->hasPrevious())
71
        {
72
            return '';
73
        }
74
75
        return
76
            PHP_EOL .
77
            PHP_EOL .
78
            'Previous error:' .
79
            PHP_EOL .
80
            PHP_EOL .
81
            $this->info->getPrevious()->toString();
82
    }
83
}
84