Completed
Push — master ( 45aada...26ef87 )
by Matthew
02:32
created

MapMetricsLoader   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 2
c 5
b 0
f 3
lcom 1
cbo 3
dl 0
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A readLatest() 0 21 1
1
<?php
2
3
namespace Ps2alerts\Api\Loader\Metrics;
4
5
use Ps2alerts\Api\Loader\Metrics\AbstractMetricsLoader;
6
use Ps2alerts\Api\Repository\Metrics\MapRepository;
7
use Ps2alerts\Api\QueryObjects\QueryObject;
8
9
class MapMetricsLoader extends AbstractMetricsLoader
10
{
11
    /**
12
     * @var \Ps2alerts\Api\Repository\Metrics\MapRepository
13
     */
14
    protected $repository;
15
16
    /**
17
     * Construct
18
     *
19
     * @param \Ps2alerts\Api\Repository\Metrics\MapRepository $repository
20
     */
21
    public function __construct(MapRepository $repository)
22
    {
23
        $this->repository = $repository;
24
        $this->setType('Map');
25
    }
26
27
    /**
28
     * Reads latest map result from an alert
29
     *
30
     * @param  string $id
31
     *
32
     * @return array
33
     */
34
    public function readLatest($id)
35
    {
36
        $redisKey = "{$this->getCacheNamespace()}{$id}:{$this->getType()}:latest";
37
38
        $queryObject = new QueryObject;
39
        $queryObject->addWhere([
40
            'col'   => 'result',
41
            'value' => $id
42
        ]);
43
44
        $queryObject->setOrderBy('result');
45
        $queryObject->setOrderByDirection('desc');
46
        $queryObject->setLimit(1);
47
48
        $this->setCacheExpireTime(60);
49
50
        return $this->cacheAndReturn(
51
            $this->repository->read($queryObject),
52
            $redisKey
53
        );
54
    }
55
}
56