Component::init()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4222
c 0
b 0
f 0
cc 5
nc 4
nop 0
1
<?php
2
/**
3
 * Health monitoring for Yii2 applications
4
 *
5
 * @link      https://github.com/hiqdev/yii2-monitoring
6
 * @package   yii2-monitoring
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\monitoring;
12
13
use Sentry\SentrySdk;
14
use Yii;
15
16
class Component extends \yii\base\Component
17
{
18
    public function init()
19
    {
20
        if (!class_exists(SentrySdk::class)) {
21
            return;
22
        }
23
        if (!empty(SentrySdk::getCurrentHub()->getClient())) {
24
            return;
25
        }
26
27
        $params = Yii::$app->params;
28
        if (empty($params['sentry.dsn']) || empty($params['sentry.enabled'])) {
29
            return;
30
        }
31
32
        \Sentry\init(['dsn' => $params['sentry.dsn']]);
33
    }
34
}
35