BoundingBoxPosition::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.6111
cc 5
nc 3
nop 2
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PrinsFrank\PhpGeoSVG\Geometry\BoundingBox;
6
7
use PrinsFrank\PhpGeoSVG\Exception\InvalidBoundingBoxPositionException;
8
9
/**
10
 * When crossing the 180th meridian with a bounding box, the bounding box wraps resulting in otherwise invalid coordinates.
11
 * This class purposefully doesn't extend the default position class as otherwise this class could be used in parameters for the position class.
12
 */
13
class BoundingBoxPosition
14
{
15
    public const MIN_LONGITUDE = -360;
16
    public const MAX_LONGITUDE = 360;
17
18
    public const MIN_LATITUDE = -90;
19
    public const MAX_LATITUDE = 90;
20
21
    /**
22
     * @throws InvalidBoundingBoxPositionException
23
     */
24 5
    public function __construct(public float $longitude, public float $latitude)
25
    {
26 5
        if ($this->longitude > static::MAX_LONGITUDE || $this->longitude < static::MIN_LONGITUDE) {
27 2
            throw new InvalidBoundingBoxPositionException('The longitude should be between ' . static::MIN_LONGITUDE . ' and ' . static::MAX_LONGITUDE . ', "' . $this->longitude . '" provided.');
28
        }
29
30 3
        if ($this->latitude > static::MAX_LATITUDE || $this->latitude < static::MIN_LATITUDE) {
31 2
            throw new InvalidBoundingBoxPositionException('The latitude should be between ' . static::MIN_LATITUDE . ' and ' . static::MAX_LATITUDE . ', "' . $this->latitude . '" provided.');
32
        }
33
    }
34
}
35