Message   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
lcom 2
cbo 0
dl 0
loc 91
ccs 27
cts 27
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setTitle() 0 10 1
A setBody() 0 19 1
A getBody() 0 4 1
A getTitle() 0 4 1
1
<?php
2
3
namespace FlyingLuscas\BugNotifier;
4
5
class Message
6
{
7
    /**
8
     * The title of the message.
9
     *
10
     * @var string
11
     */
12
    protected $title;
13
14
    /**
15
     * The body of the message.
16
     *
17
     * @var string
18
     */
19
    protected $body;
20
21
    /**
22
     * Create a new class instance.
23
     *
24
     * @param \Exception $e
25
     */
26 24
    public function __construct(\Exception $e)
27
    {
28 24
        $this->setTitle($e)->setBody($e);
29 24
    }
30
31
    /**
32
     * Set the title of the message.
33
     *
34
     * @param \Exception $e
35
     *
36
     * @return self
37
     */
38 24
    private function setTitle(\Exception $e)
39
    {
40 24
        $classname = class_basename(get_class($e));
41 24
        $filename = basename($e->getFile());
42 24
        $line = $e->getLine();
43
44 24
        $this->title = sprintf('%s in %s line %d', $classname, $filename, $line);
45
46 24
        return $this;
47
    }
48
49
    /**
50
     * Set the body of the message.
51
     *
52
     * @param \Exception $e
53
     *
54
     * @return self
55
     */
56 24
    private function setBody(\Exception $e)
57
    {
58 24
        $classname = get_class($e);
59 24
        $filename = $e->getFile();
60 24
        $line = $e->getLine();
61 24
        $message = $e->getMessage();
62 24
        $trace = $e->getTraceAsString();
63
64 24
        $at = new \DateTime(null, new \DateTimeZone(\Config::get('app.timezone')));
65
66 24
        $this->body = '['.$at->format('Y-m-d H:i:s').'] ';
67 24
        $this->body .= $classname.' in ';
68 24
        $this->body .= $filename.' ';
69 24
        $this->body .= 'line '.$line."\n\n";
70 24
        $this->body .= $message."\n\n";
71 24
        $this->body .= $trace;
72
73 24
        return $this;
74
    }
75
76
    /**
77
     * Get the body of the message.
78
     *
79
     * @return string
80
     */
81 12
    public function getBody()
82
    {
83 12
        return $this->body;
84
    }
85
86
    /**
87
     * Get the title of the message.
88
     *
89
     * @return string
90
     */
91 12
    public function getTitle()
92
    {
93 12
        return $this->title;
94
    }
95
}
96