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

Viewport   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 120
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getNorthEast() 0 4 1
A setNorthEast() 0 6 1
A getSouthWest() 0 4 1
A setSouthWest() 0 6 1
A create() 0 4 1
A toArray() 0 7 1
1
<?php namespace Arcanedev\GeoLocation\Entities\Coordinates;
2
3
use Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position as PositionContract;
4
use Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Viewport as ViewportContract;
5
use Arcanedev\GeoLocation\Traits\CanBeJsonable;
6
7
/**
8
 * Class     Viewport
9
 *
10
 * @package  Arcanedev\GeoLocation\Entities
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class Viewport implements ViewportContract
14
{
15
    /* -----------------------------------------------------------------
16
     |  Traits
17
     | -----------------------------------------------------------------
18
     */
19
20
    use CanBeJsonable;
21
22
    /* -----------------------------------------------------------------
23
     |  Properties
24
     | -----------------------------------------------------------------
25
     */
26
27
    /** @var  \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position */
28
    protected $northeast;
29
30
    /** @var  \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position */
31
    protected $southwest;
32
33
    /* -----------------------------------------------------------------
34
     |  Constructor
35
     | -----------------------------------------------------------------
36
     */
37
38
    /**
39
     * Viewport constructor.
40
     *
41
     * @param  \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position  $northeast
42
     * @param  \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position  $southwest
43
     */
44 42
    public function __construct(PositionContract $northeast, PositionContract $southwest)
45
    {
46 42
        $this->setNorthEast($northeast)->setSouthWest($southwest);
47 42
    }
48
49
    /* -----------------------------------------------------------------
50
     |  Getters & Setters
51
     | -----------------------------------------------------------------
52
     */
53
54
    /**
55
     * Get the North/East coordinates.
56
     *
57
     * @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position
58
     */
59 6
    public function getNorthEast()
60
    {
61 6
        return $this->northeast;
62
    }
63
64
    /**
65
     * Set the North/East coordinates.
66
     *
67
     * @param  \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position  $northeast
68
     *
69
     * @return self
70
     */
71 42
    public function setNorthEast(PositionContract $northeast)
72
    {
73 42
        $this->northeast = $northeast;
74
75 42
        return $this;
76
    }
77
78
    /**
79
     * Get the South/West coordinates.
80
     *
81
     * @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position
82
     */
83 6
    public function getSouthWest()
84
    {
85 6
        return $this->southwest;
86
    }
87
88
    /**
89
     * Set the South/West coordinates.
90
     *
91
     * @param  \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position  $southwest
92
     *
93
     * @return self
94
     */
95 42
    public function setSouthWest(PositionContract $southwest)
96
    {
97 42
        $this->southwest = $southwest;
98
99 42
        return $this;
100
    }
101
102
    /* -----------------------------------------------------------------
103
     |  Main Methods
104
     | -----------------------------------------------------------------
105
     */
106
107
    /**
108
     * Create a new viewport instance.
109
     *
110
     * @param  \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position  $northeast
111
     * @param  \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position  $southwest
112
     *
113
     * @return self
114
     */
115 39
    public static function create(PositionContract $northeast, PositionContract $southwest)
116
    {
117 39
        return new static($northeast, $southwest);
118
    }
119
120
    /**
121
     * Get the instance as an array.
122
     *
123
     * @return array
124
     */
125 21
    public function toArray()
126
    {
127
        return [
128 21
            'northeast' => $this->northeast->toArray(),
129 21
            'southwest' => $this->southwest->toArray(),
130 7
        ];
131
    }
132
}
133