Passed
Pull Request — development (#682)
by Nick
07:09
created

WaypointType::guess()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 6
nop 1
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\GeoCache\Enum;
4
5
use Oc\GeoCache\Exception\UnknownWaypointTypeException;
6
7
/**
8
 * Class WaypointType
9
 *
10
 * @package Oc\GeoCache\Enum
0 ignored issues
show
introduced by
Unexpected tag type @package in doc block
Loading history...
11
 */
12
final class WaypointType
13
{
14
    /**
15
     * Opencaching waypoint.
16
     *
17
     * @var string
18
     */
19
    const OC = 'oc';
20
21
    /**
22
     * Geocaching waypoint.
23
     *
24
     * @var string
25
     */
26
    const GC = 'gc';
27
28
    /**
29
     * Guesses the waypoint type by given waypoint.
30
     *
31
     * @param string $waypoint
32
     *
33
     * @return string
34
     *
35
     * @throws UnknownWaypointTypeException Thrown when the waypoint type could not be guessed
0 ignored issues
show
introduced by
UnknownWaypointTypeException => \Oc\GeoCache\Exception\UnknownWaypointTypeException
Loading history...
Coding Style introduced by
@throws tag comment must end with a full stop
Loading history...
36
     */
37
    public static function guess($waypoint)
38
    {
39
        $waypointType = null;
40
41
        if (stripos($waypoint, self::OC) === 0) {
42
            $waypointType = self::OC;
43
        } elseif (stripos($waypoint, self::GC) === 0) {
44
            $waypointType = self::GC;
45
        }
46
47
        if ($waypointType === null) {
48
            throw new UnknownWaypointTypeException(
49
                sprintf(
50
                    'Could not guess the waypoint type of the waypoint "%s"',
51
                    $waypoint
52
                )
53
            );
54
        }
55
56
        return $waypointType;
57
    }
58
}
59