MetricPusher::push()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 3
b 0
f 0
nc 3
nop 1
dl 0
loc 19
rs 9.4285
1
<?php
2
3
/*
4
 * This file is part of the hogosha-monitor package
5
 *
6
 * Copyright (c) 2016 Guillaume Cavana
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Feel free to edit as you please, and have fun.
12
 *
13
 * @author Guillaume Cavana <[email protected]>
14
 */
15
16
namespace Hogosha\Monitor\Pusher;
17
18
use GuzzleHttp\Exception\BadResponseException;
19
use Hogosha\Monitor\Guesser\StatusGuesser;
20
use Hogosha\Monitor\Model\Result;
21
use Hogosha\Sdk\Resource\Factory\ResourceFactory;
22
23
/**
24
 * Class MetricPusher.
25
 */
26
class MetricPusher extends AbstractPusher
27
{
28
    /**
29
     * {@inheridoc}.
30
     */
31
    public function push(Result $result)
32
    {
33
        $statusGuesser = new StatusGuesser();
34
35
        if ($statusGuesser->isOk($result)) {
36
            $resourceFactory = new ResourceFactory($this->client);
37
            $metricResource = $resourceFactory->get('metricPoint');
38
39
            try {
40
                $metricResource->createMetricPoint([
41
                    'metric' => $result->getUrl()->getMetricUuid(),
42
                    'value' => $result->getReponseTime() * 1000,
43
                    'datetime' => date('Y-m-d H:i:s'),
44
                ]);
45
            } catch (BadResponseException $e) {
46
                throw $e;
47
            }
48
        }
49
    }
50
}
51