Completed
Push — master ( c2add9...d388c3 )
by ARCANEDEV
14s
created

AbstractMeasure   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
wmc 8
lcom 1
cbo 1
dl 0
loc 137
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

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\Measures;
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     AbstractMeasure
10
 *
11
 * @package  Arcanedev\GeoLocation\Entities\Measures
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
abstract class AbstractMeasure implements Arrayable, Jsonable, JsonSerializable
15
{
16
    /* -----------------------------------------------------------------
17
     |  Traits
18
     | -----------------------------------------------------------------
19
     */
20
21
    use CanBeJsonable;
22
23
    /* -----------------------------------------------------------------
24
     |  Properties
25
     | -----------------------------------------------------------------
26
     */
27
28
    /**
29
     * The text value.
30
     *
31
     * @var string
32
     */
33
    protected $text;
34
35
    /**
36
     * The numeric value.
37
     *
38
     * @var int
39
     */
40
    protected $value;
41
42
    /* -----------------------------------------------------------------
43
     |  Main Methods
44
     | -----------------------------------------------------------------
45
     */
46
47
    /**
48
     * AbstractMeasure constructor.
49
     *
50
     * @param  string     $text
51
     * @param  float|int  $value
52
     */
53 87
    public function __construct($text, $value)
54
    {
55 87
        $this->text  = $text;
56 87
        $this->value = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value can also be of type double. However, the property $value is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
57 87
    }
58
59
    /* -----------------------------------------------------------------
60
     |  Getters & Setters
61
     | -----------------------------------------------------------------
62
     */
63
64
    /**
65
     * Get the text (alias).
66
     *
67
     * @see getText
68
     *
69
     * @return string
70
     */
71 45
    public function text()
72
    {
73 45
        return $this->getText();
74
    }
75
76
    /**
77
     * Get the text.
78
     *
79
     * @return string
80
     */
81 45
    public function getText()
82
    {
83 45
        return $this->text;
84
    }
85
86
    /**
87
     * Get the value (alias).
88
     *
89
     * @see getValue
90
     *
91
     * @return float|int
92
     */
93 48
    public function value()
94
    {
95 48
        return $this->getValue();
96
    }
97
98
    /**
99
     * Get the value.
100
     *
101
     * @return float|int
102
     */
103 48
    public function getValue()
104
    {
105 48
        return $this->value;
106
    }
107
108
    /* -----------------------------------------------------------------
109
     |  Main Methods
110
     | -----------------------------------------------------------------
111
     */
112
113
    /**
114
     * Make a distance instance.
115
     *
116
     * @param  string  $text
117
     * @param  int     $value
118
     *
119
     * @return static
120
     */
121 75
    public static function make($text, $value)
122
    {
123 75
        return new static($text, $value);
124
    }
125
126
    /**
127
     * Make a distance instance from array.
128
     *
129
     * @param  array  $data
130
     *
131
     * @return static
132
     */
133 57
    public static function makeFromArray(array $data)
134
    {
135 57
        return static::make($data['text'], $data['value']);
136
    }
137
138
    /**
139
     * Get the instance as an array.
140
     *
141
     * @return array
142
     */
143 24
    public function toArray()
144
    {
145
        return [
146 24
            'text'  => $this->text(),
147 24
            'value' => $this->value(),
148 8
        ];
149
    }
150
}
151