Result   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 138
ccs 21
cts 21
cp 1
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A value() 0 6 1
A prefix() 0 6 1
A suffix() 0 6 1
A format() 0 6 1
A toArray() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arcanedev\LaravelMetrics\Results;
6
7
use Arcanedev\LaravelMetrics\Concerns\ConvertsToArray;
8
use Illuminate\Contracts\Support\{Arrayable, Jsonable};
9
use JsonSerializable;
10
11
/**
12
 * Class     Result
13
 *
14
 * @author   ARCANEDEV <[email protected]>
15
 */
16
abstract class Result implements Arrayable, Jsonable, JsonSerializable
17
{
18
    /* -----------------------------------------------------------------
19
     |  Traits
20
     | -----------------------------------------------------------------
21
     */
22
23 1
    use ConvertsToArray;
24
25
    /* -----------------------------------------------------------------
26
     |  Properties
27
     | -----------------------------------------------------------------
28
     */
29
30
    /**
31
     * The result value.
32
     *
33
     * @var mixed|null
34
     */
35
    public $value;
36
37
    /**
38
     * The result prefix
39
     *
40
     * @var string|null
41
     */
42
    public $prefix;
43
44
    /**
45
     * The result suffix.
46
     *
47
     * @var string|null
48
     */
49
    public $suffix;
50
51
    /**
52
     * The result format.
53
     *
54
     * @var string
55
     */
56
    public $format;
57
58
    /* -----------------------------------------------------------------
59
     |  Constructor
60
     | -----------------------------------------------------------------
61
     */
62
63
    /**
64
     * Result constructor.
65
     *
66
     * @param  mixed|null  $value
67
     */
68 248
    public function __construct($value = null)
69
    {
70 248
        $this->value($value);
71 248
    }
72
73
    /* -----------------------------------------------------------------
74
     |  Setters
75
     | -----------------------------------------------------------------
76
     */
77
78
    /**
79
     * Set the value.
80
     *
81
     * @param  mixed  $value
82
     *
83
     * @return $this
84
     */
85 248
    public function value($value)
86
    {
87 248
        $this->value = $value;
88
89 248
        return $this;
90
    }
91
92
    /**
93
     * Set the result prefix.
94
     *
95
     * @param  string  $prefix
96
     *
97
     * @return $this
98
     */
99 48
    public function prefix(string $prefix)
100
    {
101 48
        $this->prefix = $prefix;
102
103 48
        return $this;
104
    }
105
106
    /**
107
     * Set the result suffix.
108
     *
109
     * @param  string  $suffix
110
     *
111
     * @return $this
112
     */
113 48
    public function suffix(string $suffix)
114
    {
115 48
        $this->suffix = $suffix;
116
117 48
        return $this;
118
    }
119
120
    /**
121
     * Set the result format.
122
     *
123
     * @param  string  $format
124
     *
125
     * @return $this
126
     */
127 48
    public function format(string $format)
128
    {
129 48
        $this->format = $format;
130
131 48
        return $this;
132
    }
133
134
    /* -----------------------------------------------------------------
135
     |  Other Methods
136
     | -----------------------------------------------------------------
137
     */
138
139
    /**
140
     * Get the instance as an array.
141
     *
142
     * @return array
143
     */
144 72
    public function toArray(): array
145
    {
146
        return [
147 72
            'value'  => $this->value,
148 72
            'format' => $this->format,
149 72
            'prefix' => $this->prefix,
150 72
            'suffix' => $this->suffix,
151
        ];
152
    }
153
}
154