TrendResult   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

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