Issues (5)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/LERN.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Tylercd100\LERN;
4
5
use Throwable;
6
use Monolog\Handler\HandlerInterface;
7
use Tylercd100\LERN\Components\Notifier;
8
use Tylercd100\LERN\Components\Recorder;
9
use Tylercd100\LERN\Exceptions\NotifierFailedException;
10
use Tylercd100\LERN\Exceptions\RecorderFailedException;
11
12
/**
13
* The master class
14
*/
15
class LERN 
16
{
17
    /**
18
     * @var Throwable
19
     */
20
    private $exception;
21
22
    /**
23
     * @var Notifier
24
     */
25
    private $notifier;
26
27
    /**
28
     * @var Recorder
29
     */
30
    private $recorder;
31
    
32
    /**
33
     * @param Notifier|null $notifier Notifier instance
34
     * @param Recorder|null $recorder Recorder instance
35
     */
36 36
    public function __construct(Notifier $notifier = null, Recorder $recorder = null)
37
    {
38 36
        $this->notifier = $this->buildNotifier($notifier);
39 36
        $this->recorder = $this->buildRecorder($recorder);
40 36
    }
41
42
    /**
43
     * Will execute record and notify methods
44
     * @param  Throwable $e   The exception to use
45
     * @return ExceptionModel the recorded Eloquent Model
46
     */
47 6
    public function handle(Throwable $e)
48
    {
49 6
        $this->exception = $e;
50 6
        $this->notify($e);
51 6
        return $this->record($e);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression $this->record($e); of type false|object adds false to the return on line 51 which is incompatible with the return type documented by Tylercd100\LERN\LERN::handle of type Tylercd100\LERN\ExceptionModel. It seems like you forgot to handle an error condition.
Loading history...
52
    }
53
54
    /**
55
     * Stores the exception in the database
56
     * @param  Throwable $e   The exception to use
57
     * @return \Tylercd100\LERN\Models\ExceptionModel|false The recorded Exception as an Eloquent Model
58
     */
59 6
    public function record(Throwable $e)
60
    {
61 6
        $this->exception = $e;
62 6
        return $this->recorder->record($e);
63
    }
64
65
    /**
66
     * Will send the exception to all monolog handlers
67
     * @param  Throwable $e The exception to use
68
     * @return void
69
     */
70 6
    public function notify(Throwable $e)
71
    {
72 6
        $this->exception = $e;
73 6
        $this->notifier->send($e);
74 6
    }
75
76
    /**
77
     * Pushes on another Monolog Handler
78
     * @param  HandlerInterface $handler The handler instance to add on
79
     * @return $this
80
     */
81 3
    public function pushHandler(HandlerInterface $handler) {
82 3
        $this->notifier->pushHandler($handler);
83 3
        return $this;
84
    }
85
86
    /**
87
     * Get Notifier
88
     * @return \Tylercd100\LERN\Components\Notifier 
89
     */
90 3
    public function getNotifier()
91
    {
92 3
        return $this->notifier;
93
    }
94
95
    /**
96
     * Set Notifier
97
     * @param \Tylercd100\LERN\Components\Notifier $notifier A Notifier instance to use
98
     * @return \Tylercd100\LERN\LERN
99
     */
100 3
    public function setNotifier(Notifier $notifier)
101
    {
102 3
        $this->notifier = $notifier;
103 3
        return $this;
104
    }
105
106
    /**
107
     * Get Recorder
108
     * @return \Tylercd100\LERN\Components\Recorder 
109
     */
110 3
    public function getRecorder()
111
    {
112 3
        return $this->recorder;
113
    }
114
115
    /**
116
     * Set Recorder
117
     * @param \Tylercd100\LERN\Components\Recorder $recorder A Recorder instance to use
118
     * @return \Tylercd100\LERN\LERN
119
     */
120 3
    public function setRecorder(Recorder $recorder)
121
    {
122 3
        $this->recorder = $recorder;
123 3
        return $this;
124
    }
125
126
    /**
127
     * Get the log level
128
     * @return string 
129
     */
130 3
    public function getLogLevel()
131
    {
132 3
        return $this->notifier->getLogLevel();
133
    }
134
135
    /**
136
     * Set the log level
137
     * @param string $level The log level
138
     * @return \Tylercd100\LERN\LERN
139
     */
140 6
    public function setLogLevel($level)
141
    {
142 6
        $this->notifier->setLogLevel($level);
143 6
        return $this;
144
    }
145
146
    /**
147
     * Set a string or a closure to be called that will generate the message body for the notification
148
     * @param function|string $cb This closure function will be passed an Throwable and must return a string
149
     * @return $this
150
     */
151 3
    public function setMessage($cb)
152
    {
153 3
        $this->notifier->setMessage($cb);
154 3
        return $this;
155
    }
156
157
    /**
158
     * Set a string or a closure to be called that will generate the subject line for the notification
159
     * @param function|string $cb This closure function will be passed an Throwable and must return a string
160
     * @return $this
161
     */
162 3
    public function setSubject($cb)
163
    {
164 3
        $this->notifier->setSubject($cb);
165 3
        return $this;
166
    }
167
168
    /**
169
     * Constructs a Notifier
170
     *
171
     * @param Notifier $notifier
172
     * @return Notifier
173
     */
174 36 View Code Duplication
    protected function buildNotifier(Notifier $notifier = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
    {
176 36
        $class = config('lern.notify.class');
177 36
        $class = !empty($class) ? $class : Notifier::class;
178 36
        if (empty($notifier)) {
179 21
            $notifier = new $class();
180
        }
181 36
        if ($notifier instanceof Notifier) {
182 36
            return $notifier;
183
        } else {
184
            throw new NotifierFailedException("LERN was expecting an instance of ".Notifier::class);
185
        }
186
    }
187
188
    /**
189
     * Constructs a Recorder
190
     *
191
     * @param Recorder $recorder
192
     * @return Recorder
193
     */
194 36 View Code Duplication
    protected function buildRecorder(Recorder $recorder = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
195
    {
196 36
        $class = config('lern.record.class');
197 36
        $class = !empty($class) ? $class : Recorder::class;
198 36
        if (empty($recorder)) {
199 36
            $recorder = new $class();
200
        }
201 36
        if ($recorder instanceof Recorder) {
202 36
            return $recorder;
203
        } else {
204
            throw new RecorderFailedException("LERN was expecting an instance of ".Recorder::class);
205
        }
206
    }
207
}
208