Completed
Push — master ( aec035...22a1ab )
by Marcus
02:38
created

LineCorridor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A createCorridor() 0 16 1
1
<?php
2
3
namespace Location\Utility\Corridor;
4
5
use Location\Bearing\BearingInterface;
6
use Location\Line;
7
use Location\Polygon;
8
9
class LineCorridor
10
{
11
    /**
12
     * @var float distance between line and the corridor border, in meters
13
     */
14
    private $distance;
15
16
    /**
17
     * @var \Location\Bearing\BearingInterface
18
     */
19
    private $bearingCalculator;
20
21
    /**
22
     * LineCorridor constructor.
23
     *
24
     * @param float $distance
25
     */
26
    public function __construct($distance, BearingInterface $bearingCalculator)
27
    {
28
        if ($distance <= 0.0) {
29
            throw new \InvalidArgumentException("distance must be greater than 0");
30
        }
31
32
        $this->distance          = $distance;
33
        $this->bearingCalculator = $bearingCalculator;
34
    }
35
36
    public function createCorridor(Line $line)
0 ignored issues
show
Unused Code introduced by Marcus Jaschen
The parameter $line is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
    {
38
        throw new \RuntimeException("Method not implemented yet.");
39
40
        $corridor = new Polygon();
0 ignored issues
show
Unused Code introduced by Marcus Jaschen
$corridor = new \Location\Polygon(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
41
42
        $bearingForward = $line->getBearing($this->bearingCalculator);
43
        $bearingReverse = $line->getReverse()->getBearing($this->bearingCalculator);
44
45
        $corridor->addPoint($this->bearingCalculator->calculateDestination($line->getPoint1(), fmod($bearingForward + 135, 360), $this->distance));
46
        $corridor->addPoint($this->bearingCalculator->calculateDestination($line->getPoint1(), fmod($bearingForward - 135, 360), $this->distance));
47
        $corridor->addPoint($this->bearingCalculator->calculateDestination($line->getPoint2(), fmod($bearingReverse - 135, 360), $this->distance));
48
        $corridor->addPoint($this->bearingCalculator->calculateDestination($line->getPoint2(), fmod($bearingReverse + 135, 360), $this->distance));
49
50
        return $corridor;
51
    }
52
}
53