CoordinateLogic   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 25
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A findClosest() 0 17 4
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