BugsnagService::boot()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 10
cc 4
nc 3
nop 0
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sulao\ThinkBugsnag;
6
7
use Bugsnag\Client;
8
use Bugsnag\Handler;
9
use think\Service;
10
11
class BugsnagService extends Service
12
{
13 1
    public function boot()
14
    {
15 1
        $config = $this->app->config->get('bugsnag', []) + ['api_key' => null];
16 1
        $bugsnag = Client::make($config['api_key']);
17 1
        foreach ($config as $key => $value) {
18 1
            $method = 'set' . implode('', array_map('ucfirst', explode('_', $key)));
19 1
            if (method_exists($bugsnag, $method) && !is_null($value)) {
20 1
                $bugsnag->$method($value);
21
            }
22
        }
23 1
        Handler::register($bugsnag);
24 1
        $this->app->bind('bugsnag', $bugsnag);
25
    }
26
}
27