Completed
Branch dev-record-extra-information (673ac4)
by Tyler
03:54
created

LERN::record()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 5
rs 9.4285
ccs 3
cts 3
cp 1
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Tylercd100\LERN;
4
5
use Exception;
6
use Tylercd100\LERN\Components\Notifier;
7
use Tylercd100\LERN\Components\Recorder;
8
use Monolog\Handler\HandlerInterface;
9
10
/**
11
* The master class
12
*/
13
class LERN 
14
{
15
    /**
16
     * @var Exception
17
     */
18
    private $exception;
19
20
    /**
21
     * @var Tylercd100\LERN\Components\Notifier
22
     */
23
    private $notifier;
24
25
    /**
26
     * @var Tylercd100\LERN\Components\Recorder
27
     */
28
    private $recorder;
29
    
30
    /**
31
     * @param Notifier|null $notifier Notifier instance
32
     * @param Recorder|null $recorder Recorder instance
33
     */
34 21
    public function __construct(Notifier $notifier = null, Recorder $recorder = null)
35
    {
36 21
        if (empty($notifier)) {
37 9
            $notifier = new Notifier();
38 9
        }
39 21
        $this->notifier = $notifier;
0 ignored issues
show
Documentation Bug introduced by
It seems like $notifier of type object<Tylercd100\LERN\Components\Notifier> is incompatible with the declared type object<Tylercd100\LERN\T...RN\Components\Notifier> of property $notifier.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
41 21
        if (empty($recorder)) {
42 21
            $recorder = new Recorder();
43 21
        }
44 21
        $this->recorder = $recorder;
0 ignored issues
show
Documentation Bug introduced by
It seems like $recorder of type object<Tylercd100\LERN\Components\Recorder> is incompatible with the declared type object<Tylercd100\LERN\T...RN\Components\Recorder> of property $recorder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45 21
    }
46
47
    /**
48
     * Will execute record and notify methods
49
     * @param  Exception $e   The exception to use
50
     * @return ExceptionModel the recorded Eloquent Model
51
     */
52 3
    public function handle(Exception $e)
53
    {
54 3
        $this->exception = $e;
55 3
        $this->notify($e);
56 3
        return $this->record($e);
57
    }
58
59
    /**
60
     * Stores the exception in the database
61
     * @param  Exception $e   The exception to use
62
     * @return Tylercd100\LERN\Models\ExceptionModel The recorded Exception as an Eloquent Model
63
     */
64 3
    public function record(Exception $e)
65
    {
66 3
        $this->exception = $e;
67 3
        return $this->recorder->record($e);
68
    }
69
70
    /**
71
     * Will send the exception to all monolog handlers
72
     * @param  Exception $e The exception to use
73
     * @return void
74
     */
75 3
    public function notify(Exception $e)
76
    {
77 3
        $this->exception = $e;
78 3
        $this->notifier->send($e);
79 3
    }
80
81
    /**
82
     * Pushes on another Monolog Handler
83
     * @param  HandlerInterface $handler The handler instance to add on
84
     * @return Notifier                  Returns this
85
     */
86 3
    public function pushHandler(HandlerInterface $handler) {
87 3
        $this->notifier->pushHandler($handler);
88 3
        return $this;
89
    }
90
91
    /**
92
     * Get Notifier
93
     * @return Notifier 
94
     */
95 3
    public function getNotifier()
96
    {
97 3
        return $this->notifier;
98
    }
99
100
    /**
101
     * Set Notifier
102
     * @param Notifier $notifier A Notifier instance to use
103
     */
104 3
    public function setNotifier(Notifier $notifier)
105
    {
106 3
        $this->notifier = $notifier;
0 ignored issues
show
Documentation Bug introduced by
It seems like $notifier of type object<Tylercd100\LERN\Components\Notifier> is incompatible with the declared type object<Tylercd100\LERN\T...RN\Components\Notifier> of property $notifier.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
107 3
        return $this;
108
    }
109
110
    /**
111
     * Get Recorder
112
     * @return Recorder 
113
     */
114
    public function getRecorder()
115
    {
116
        return $this->recorder;
117
    }
118
119
    /**
120
     * Set Recorder
121
     * @param Recorder $recorder A Recorder instance to use
122
     */
123
    public function setRecorder(Recorder $recorder)
124
    {
125
        $this->recorder = $recorder;
0 ignored issues
show
Documentation Bug introduced by
It seems like $recorder of type object<Tylercd100\LERN\Components\Recorder> is incompatible with the declared type object<Tylercd100\LERN\T...RN\Components\Recorder> of property $recorder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
126
        return $this;
127
    }
128
129
    /**
130
     * Set a string or a closure to be called that will generate the message body for the notification
131
     * @param function|string $cb This closure function will be passed an Exception and must return a string
132
     */
133 3
    public function setMessage($cb)
134
    {
135 3
        $this->notifier->setMessage($cb);
136 3
        return $this;
137
    }
138
139
    /**
140
     * Set a string or a closure to be called that will generate the subject line for the notification
141
     * @param function|string $cb This closure function will be passed an Exception and must return a string
142
     */
143 3
    public function setSubject($cb)
144
    {
145 3
        $this->notifier->setSubject($cb);
146 3
        return $this;
147
    }
148
149
}