| Total Complexity | 8 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | class Component extends YiiComponent |
||
| 14 | { |
||
| 15 | public $config = []; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Get Honeybadger instance. |
||
| 19 | * |
||
| 20 | * @return Honeybadger |
||
| 21 | */ |
||
| 22 | 1 | protected function getHoneybadger(): Honeybadger |
|
| 23 | { |
||
| 24 | 1 | static $honeybadger; |
|
| 25 | |||
| 26 | 1 | if ($honeybadger) { |
|
| 27 | 1 | return $honeybadger; |
|
| 28 | } |
||
| 29 | |||
| 30 | 1 | $config = $this->config; |
|
| 31 | |||
| 32 | // Globally disable error handlers, record the errors via the logger |
||
| 33 | 1 | $config['handlers'] = [ |
|
| 34 | 1 | 'exception' => false, |
|
| 35 | 1 | 'error' => false, |
|
| 36 | 1 | 'shutdown' => false, |
|
| 37 | 1 | ]; |
|
| 38 | |||
| 39 | 1 | $context = ArrayHelper::remove($config, 'context'); |
|
| 40 | |||
| 41 | 1 | $honeybadger = Honeybadger::new($config); |
|
| 42 | |||
| 43 | 1 | if (!empty($context) && is_array($context)) { |
|
| 44 | 1 | foreach ($context as $key => $value) { |
|
| 45 | 1 | if ($value instanceof Closure) { |
|
| 46 | 1 | $context[$key] = call_user_func($value); |
|
| 47 | } |
||
| 48 | } |
||
| 49 | 1 | $honeybadger->context($context); |
|
|
|
|||
| 50 | } |
||
| 51 | |||
| 52 | 1 | return $honeybadger; |
|
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Send an exception to Honeybadger. |
||
| 57 | * |
||
| 58 | * @param Throwable $throwable |
||
| 59 | * @param array $additionalParams |
||
| 60 | * @return array |
||
| 61 | */ |
||
| 62 | 1 | public function notify(Throwable $throwable, array $additionalParams = []) |
|
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Send a custom notification to Honeybadger. |
||
| 69 | * |
||
| 70 | * @param array $payload |
||
| 71 | * @return array |
||
| 72 | */ |
||
| 73 | 1 | public function customNotification(array $payload) |
|
| 78 |