Completed
Push — master ( ac3cad...7fabe3 )
by Artem
03:23
created

SentryHelperTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 33
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendExceptionToSentry() 0 8 2
A sendMessageToSentry() 0 8 2
1
<?php
2
/*
3
 * This file is part of the FreshCommonApiBundle
4
 *
5
 * (c) Artem Genvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fresh\CommonApiBundle\Helper\Logger;
12
13
/**
14
 * SentryHelperTrait.
15
 *
16
 * @author Artem Genvald <[email protected]>
17
 */
18
trait SentryHelperTrait
19
{
20
    use BaseLoggerTrait;
21
22
    /**
23
     * Send exception to Sentry.
24
     *
25
     * @param \Exception $e Exception
26
     */
27
    protected function sendExceptionToSentry(\Exception $e)
28
    {
29
        if ($this->has('sentry.client')) {
30
            /** @var \Sentry\SentryBundle\SentrySymfonyClient $sentryClient */
31
            $sentryClient = $this->get('sentry.client');
32
            $sentryClient->captureException($e);
33
        }
34
    }
35
36
    /**
37
     * Send message to Sentry.
38
     *
39
     * @param string $message Message
40
     * @param string $level   Level
41
     */
42
    protected function sendMessageToSentry($message, $level)
43
    {
44
        if ($this->has('sentry.client')) {
45
            /** @var \Sentry\SentryBundle\SentrySymfonyClient $sentryClient */
46
            $sentryClient = $this->get('sentry.client');
47
            $sentryClient->captureMessage($message, [], $level);
48
        }
49
    }
50
}
51