Sentry   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doWrite() 0 8 1
A __construct() 0 5 1
1
<?php
2
3
/**
4
 * Bright Answer ZendSentry
5
 *
6
 * This source file is part of the Bright Answer ZendSentry package
7
 *
8
 * @package    ZendSentry\Log\Writer\Sentry
9
 * @license    MIT License {@link /docs/LICENSE}
10
 * @copyright  Copyright (c) 2018, Bright Answer OÜ
11
 */
12
13
namespace ZendSentry\Log\Writer;
14
15
use Zend\Log\Writer\AbstractWriter;
16
use Raven_Client as Raven;
17
18
/**
19
 * @package    ZendSentry\Log\Wrier\Sentry
20
 */
21
class Sentry extends AbstractWriter
22
{
23
    protected $raven;
24
    /**
25
     * Translates Zend Framework log levels to Raven log levels.
26
     */
27
    private $logLevels = [
28
        'DEBUG'  => Raven::DEBUG,
29
        'INFO'   => Raven::INFO,
30
        'NOTICE' => Raven::INFO,
31
        'WARN'   => Raven::WARNING,
32
        'ERR'    => Raven::ERROR,
33
        'CRIT'   => Raven::FATAL,
34
        'ALERT'  => Raven::FATAL,
35
        'EMERG'  => Raven::FATAL,
36
    ];
37
38
    /**
39
     * Sentry constructor.
40
     *
41
     * @param Raven $raven
42
     * @param null  $options
43
     */
44
    public function __construct(Raven $raven, $options = null)
45
    {
46
        $this->raven = $raven;
47
        parent::__construct($options);
48
    }
49
50
    /**
51
     * Write a message to the log
52
     *
53
     * @param array $event log data event
54
     *
55
     * @return string $eventID the event ID
56
     */
57
    protected function doWrite(array $event): string
58
    {
59
        $extra              = [];
60
        $extra['timestamp'] = $event['timestamp'];
61
        $eventID            = $this->raven->captureMessage($event['message'], [], $this->logLevels[$event['priorityName']], false, $event['extra']);
62
63
        return $eventID;
64
    }
65
}