Completed
Push — master ( 0ecc5d...19edd4 )
by Marcus
03:36
created

BoundsFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A expandFromCenterCoordinate() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Location\Factory;
6
7
use InvalidArgumentException;
8
use Location\Bearing\BearingInterface;
9
use Location\Bounds;
10
use Location\Coordinate;
11
12
/**
13
 * Bounds Factory
14
 */
15
class BoundsFactory
16
{
17
    /**
18
     * Creates a Bounds instance which corners have the given distance from its center.
19
     *
20
     * @param Coordinate $center
21
     * @param float $distance in meters
22
     * @param BearingInterface $bearing
23
     * @return Bounds
24
     * @throws InvalidArgumentException if bounds crosses the 180/-180 degrees meridian.
25
     */
26
    public static function expandFromCenterCoordinate(
27
        Coordinate $center,
28
        float $distance,
29
        BearingInterface $bearing
30
    ): Bounds {
31
        $northWest = $bearing->calculateDestination($center, 315, $distance);
32
        $southEast = $bearing->calculateDestination($center, 135, $distance);
33
34
        return new Bounds($northWest, $southEast);
35
    }
36
}
37