GetBoundsTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
getPoints() 0 1 ?
A getBounds() 0 19 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Location;
6
7
/**
8
 * Trait GetBoundsTrait
9
 *
10
 * @package Location
11
 *
12
 * @property Coordinate[] $points
13
 */
14
trait GetBoundsTrait
15
{
16
    /**
17
     * @return Coordinate[]
18
     */
19
    abstract public function getPoints(): array;
20
21
    /**
22
     * @return Bounds
23
     */
24
    public function getBounds(): Bounds
25
    {
26
        $latMin = 90.0;
27
        $latMax = -90.0;
28
        $lngMin = 180.0;
29
        $lngMax = -180.0;
30
31
        foreach ($this->getPoints() as $point) {
32
            $latMin = min($point->getLat(), $latMin);
33
            $lngMin = min($point->getLng(), $lngMin);
34
            $latMax = max($point->getLat(), $latMax);
35
            $lngMax = max($point->getLng(), $lngMax);
36
        }
37
38
        return new Bounds(
39
            new Coordinate($latMax, $lngMin),
40
            new Coordinate($latMin, $lngMax)
41
        );
42
    }
43
}
44