Completed
Push — master ( 26ec36...6b634b )
by Marcus
03:27
created

GetBoundsTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getBounds() 0 20 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Location;
5
6
/**
7
 * Trait GetBoundsTrait
8
 *
9
 * @package Location
10
 *
11
 * @property Coordinate[] $points
12
 */
13
trait GetBoundsTrait
14
{
15
    /**
16
     * @return Bounds
17
     */
18
    public function getBounds(): Bounds
19
    {
20
        $latMin = 90.0;
21
        $latMax = -90.0;
22
        $lngMin = 180.0;
23
        $lngMax = -180.0;
24
25
        /** @var Coordinate $point */
26
        foreach ($this->getPoints() as $point) {
0 ignored issues
show
Bug introduced by Marcus Jaschen
It seems like getPoints() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
27
            $latMin = min($point->getLat(), $latMin);
28
            $lngMin = min($point->getLng(), $lngMin);
29
            $latMax = max($point->getLat(), $latMax);
30
            $lngMax = max($point->getLng(), $lngMax);
31
        }
32
33
        return new Bounds(
34
            new Coordinate($latMax, $lngMin),
35
            new Coordinate($latMin, $lngMax)
36
        );
37
    }
38
}
39