1 | <?php |
||
12 | class Recorder { |
||
13 | |||
14 | /** |
||
15 | * @var mixed |
||
16 | */ |
||
17 | protected $config = []; |
||
18 | |||
19 | /** |
||
20 | * The constructor |
||
21 | */ |
||
22 | 21 | public function __construct() { |
|
25 | |||
26 | /** |
||
27 | * Records an Exception to the database |
||
28 | * @param Exception $e The exception you want to record |
||
29 | * @return ExceptionModel |
||
30 | */ |
||
31 | 3 | public function record(Exception $e) |
|
32 | { |
||
33 | $opts = [ |
||
34 | 3 | 'class' => get_class($e), |
|
35 | 3 | 'file' => $e->getFile(), |
|
36 | 3 | 'line' => $e->getLine(), |
|
37 | 3 | 'code' => $e->getCode(), |
|
38 | 3 | 'message' => $e->getMessage(), |
|
39 | 3 | 'trace' => $e->getTraceAsString(), |
|
40 | 3 | ]; |
|
41 | |||
42 | |||
43 | 3 | $configDependant = ['user_id','status_code','method','data','url']; |
|
44 | |||
45 | 3 | foreach ($configDependant as $key) { |
|
46 | 3 | if($this->canCollect($key)){ |
|
47 | 3 | $opts[$key] = $this->collect($key,$e); |
|
48 | 3 | } |
|
49 | 3 | } |
|
50 | |||
51 | 3 | return ExceptionModel::create($opts); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Checks the config to see if you can collect certain information |
||
56 | * @param string $type the config value you want to check |
||
57 | * @return boolean |
||
58 | */ |
||
59 | 3 | private function canCollect($type) { |
|
65 | |||
66 | 3 | protected function collect($key,Exception $e = null){ |
|
82 | |||
83 | /** |
||
84 | * Gets the ID of the User that is logged in |
||
85 | * @return integer|null The ID of the User or Null if not logged in |
||
86 | */ |
||
87 | 3 | protected function getUserId() { |
|
95 | |||
96 | /** |
||
97 | * Gets the Method of the Request |
||
98 | * @return string|null Possible values are null or GET, POST, DELETE, PUT, etc... |
||
99 | */ |
||
100 | 3 | protected function getMethod() { |
|
108 | |||
109 | /** |
||
110 | * Gets the input data of the Request |
||
111 | * @return array|null The Input data or null |
||
112 | */ |
||
113 | 3 | protected function getData() { |
|
121 | |||
122 | /** |
||
123 | * Gets the URL of the Request |
||
124 | * @return string|null Returns a URL string or null |
||
125 | */ |
||
126 | 3 | protected function getUrl() { |
|
134 | |||
135 | /** |
||
136 | * Gets the status code of the Exception |
||
137 | * @param Exception $e The Exception to check |
||
138 | * @return string|integer The status code value |
||
139 | */ |
||
140 | 3 | protected function getStatusCode(Exception $e) { |
|
147 | } |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):