Completed
Pull Request — master (#4)
by ARCANEDEV
03:32
created

Duration   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 137
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1
ccs 20
cts 20
cp 1
rs 10

8 Methods

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