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

render()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 39
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 39
rs 9.1928
cc 5
nc 8
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AppUtils;
6
7
class ConvertHelper_ThrowableInfo_MessageRenderer
8
{
9
    /**
10
     * @var ConvertHelper_ThrowableInfo
11
     */
12
    private $info;
13
14
    /**
15
     * @var bool
16
     */
17
    private $developerInfo;
18
19
    public function __construct(ConvertHelper_ThrowableInfo $info, bool $developerInfo)
20
    {
21
        $this->info = $info;
22
        $this->developerInfo = $developerInfo;
23
    }
24
25
    /**
26
     * @return string
27
     * @throws ConvertHelper_Exception
28
     */
29
    public function render() : string
30
    {
31
        $finalCall = $this->info->getFinalCall();
32
33
        $message = sb()
34
            ->t('A %1$s exception occurred.', $this->info->getClass())
35
            ->eol()
36
            ->t('Code:')
37
            ->add($this->info->getCode())
38
            ->t('Message:')
39
            ->add($this->info->getMessage());
40
41
        if($this->developerInfo)
42
        {
43
            $message
44
                ->eol()
45
                ->t('Final call:')
46
                ->add($finalCall->toString());
47
        }
48
49
        if($this->developerInfo && $this->info->hasDetails())
50
        {
51
            $message
52
                ->t('Developer details:')
53
                ->eol()
54
                ->add($this->info->getDetails());
55
        }
56
57
        if($this->info->hasPrevious())
58
        {
59
            $message
60
                ->eol()
61
                ->eol()
62
                ->t('Previous exception:')
63
                ->eol()
64
                ->add($this->info->getPrevious()->renderErrorMessage($this->developerInfo));
65
        }
66
67
        return (string)$message;
68
    }
69
}
70