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 | /** |
||
67 | * @param string $key |
||
68 | */ |
||
69 | 3 | protected function collect($key,Exception $e = null){ |
|
85 | |||
86 | /** |
||
87 | * Gets the ID of the User that is logged in |
||
88 | * @return integer|null The ID of the User or Null if not logged in |
||
89 | */ |
||
90 | 3 | protected function getUserId() { |
|
98 | |||
99 | /** |
||
100 | * Gets the Method of the Request |
||
101 | * @return string|null Possible values are null or GET, POST, DELETE, PUT, etc... |
||
102 | */ |
||
103 | 3 | protected function getMethod() { |
|
111 | |||
112 | /** |
||
113 | * Gets the input data of the Request |
||
114 | * @return array|null The Input data or null |
||
115 | */ |
||
116 | 3 | protected function getData() { |
|
124 | |||
125 | /** |
||
126 | * Gets the URL of the Request |
||
127 | * @return string|null Returns a URL string or null |
||
128 | */ |
||
129 | 3 | protected function getUrl() { |
|
137 | |||
138 | /** |
||
139 | * Gets the status code of the Exception |
||
140 | * @param Exception $e The Exception to check |
||
141 | * @return string|integer The status code value |
||
142 | */ |
||
143 | 3 | protected function getStatusCode(Exception $e) { |
|
150 | } |
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):