CoordinateLogic::findClosest()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 11
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 3
nop 1
crap 20
1
<?php
2
3
namespace GeoBase\Countries\Coordinate;
4
5
use League\Geotools\Coordinate\CoordinateInterface;
6
use League\Geotools\Geotools;
7
8
abstract class CoordinateLogic implements CoordinateInterface
9
{
10
    /**
11
     * @param CoordinateCollectionInterface $collection
12
     *
13
     * @return CoordinateInterface
14
     */
15
    public function findClosest(CoordinateCollectionInterface $collection)
16
    {
17
        $geotools = new Geotools();
18
        $match = null;
19
        $matchDistance = null;
20
21
        foreach ($collection as $coordinate) {
0 ignored issues
show
Bug introduced by
The expression $collection of type object<GeoBase\Countries...ateCollectionInterface> is not traversable.
Loading history...
22
            $distance = $geotools->distance()->setFrom($this)->setTo($coordinate);
23
            $flatDistance = $distance->flat();
24
            if ($matchDistance === null || $flatDistance < $matchDistance) {
25
                $match = $coordinate;
26
                $matchDistance = $flatDistance;
27
            }
28
        }
29
30
        return $match;
31
    }
32
}
33