Completed
Push — master ( e8d58e...20c4ee )
by ARCANEDEV
04:06
created

TrendResult   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 63
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A showLatestValue() 0 6 1
A trend() 0 6 1
A toArray() 0 7 1
1
<?php namespace Arcanedev\LaravelMetrics\Results;
2
3
/**
4
 * Class     TrendResult
5
 *
6
 * @package  Arcanedev\LaravelMetrics\Results
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
class TrendResult extends Result
10
{
11
    /* -----------------------------------------------------------------
12
     |  Properties
13
     | -----------------------------------------------------------------
14
     */
15
16
    /**
17
     * The trend data of the result.
18
     *
19
     * @var array
20
     */
21
    public $trend = [];
22
23
    /* -----------------------------------------------------------------
24
     |  Setters
25
     | -----------------------------------------------------------------
26
     */
27
28
    /**
29
     * Set the latest value of the trend as the primary value.
30
     *
31
     * @return $this
32
     */
33 4
    public function showLatestValue()
34
    {
35 4
        return $this->value(
36 4
            last($this->trend)['value'] ?? null
37
        );
38
    }
39
40
    /**
41
     * Set the trend of data for the metric.
42
     *
43
     * @param  array  $trend
44
     *
45
     * @return $this
46
     */
47 24
    public function trend(array $trend)
48
    {
49 24
        $this->trend = $trend;
50
51 24
        return $this;
52
    }
53
54
    /* -----------------------------------------------------------------
55
     |  Other Methods
56
     | -----------------------------------------------------------------
57
     */
58
59
    /**
60
     * Get the instance as an array.
61
     *
62
     * @return array
63
     */
64 8
    public function toArray(): array
65
    {
66 8
        return array_merge(
67 8
            parent::toArray(),
68 8
            ['trend'  => $this->trend]
69
        );
70
    }
71
}
72