Completed
Push — master ( 3592ed...983069 )
by Guillaume
02:39
created

MetricPusher::push()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
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 Hogosha\Monitor\Model\Result;
19
use Hogosha\Sdk\Resource\Factory\ResourceFactory;
20
21
/**
22
 * Class MetricPusher.
23
 */
24
class MetricPusher extends AbstractPusher
25
{
26
    /**
27
     * {@inheridoc}.
28
     */
29
    public function push(Result $result)
30
    {
31
        $resourceFactory = new ResourceFactory($this->getClient());
32
        $metricResource = $resourceFactory->get('metricPoint');
33
34
        try {
35
            $metricResource->createMetricPoint([
36
                'metric' => $result->getUrl()->getMetricUuid(),
37
                'value' => $result->getReponseTime() * 1000,
38
                'datetime' => date('Y-m-d H:i:s'),
39
            ]);
40
        } catch (\Exception $e) {
41
            echo sprintf('An error has occured %s', $e->getMessage());
42
        }
43
    }
44
}
45