SnsEventHandler::getDefaultFormatter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of Monolog Extensions
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/MonologExtensions/blob/master/LICENSE
11
 * @link http://github.com/graze/MonologExtensions
12
 */
13
14
namespace Graze\Monolog\Handler;
15
16
use Aws\Sns\SnsClient;
17
use Graze\Monolog\Formatter\JsonDateAwareFormatter;
18
use Monolog\Handler\AbstractProcessingHandler;
19
20
class SnsEventHandler extends AbstractProcessingHandler
21
{
22
    const DATE_FORMAT = 'Y-m-d\TH:i:s.uO';
23
24
    /** @var SnsClient */
25
    private $client;
26
    /** @var string */
27
    private $topic;
28
29
    /**
30
     * @param SnsClient $client
31
     * @param string    $topic aws TopicArn
32
     */
33 5
    public function __construct(SnsClient $client, $topic)
34
    {
35 5
        $this->client = $client;
36 5
        $this->topic = $topic;
37 5
        parent::__construct();
38 5
    }
39
40
    /**
41
     * Event handlers handle all events by default
42
     *
43
     * @param array $record
44
     *
45
     * @return bool always returns true
46
     */
47 2
    public function isHandling(array $record)
48
    {
49 2
        return true;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     *
55
     * @param array $record
56
     */
57 1
    protected function write(array $record)
58
    {
59 1
        $this->client->publish([
60 1
            'TopicArn' => $this->topic,
61 1
            'Message'  => $record['formatted'],
62
        ]);
63 1
    }
64
65
    /**
66
     * @return JsonDateAwareFormatter
67
     */
68 1
    protected function getDefaultFormatter()
69
    {
70 1
        return new JsonDateAwareFormatter(self::DATE_FORMAT);
71
    }
72
}
73