MetricPusher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 25
rs 10
wmc 3
lcom 1
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A push() 0 19 3
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