Completed
Push — development ( daed94...13a157 )
by Thomas
18s
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
class WaypointType
8
{
9
    /**
10
     * Opencaching waypoint.
11
     *
12
     * @var string
13
     */
14
    const OC = 'oc';
15
16
    /**
17
     * Geocaching waypoint.
18
     *
19
     * @var string
20
     */
21
    const GC = 'gc';
22
23
    /**
24
     * Guesses the waypoint type by given waypoint.
25
     *
26
     * @param string $waypoint
27
     *
28
     * @return string
29
     *
30
     * @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...
31
     */
32
    public static function guess($waypoint)
33
    {
34
        $waypointType = null;
35
36
        if (stripos($waypoint, self::OC) === 0) {
37
            $waypointType = self::OC;
38
        } elseif (stripos($waypoint, self::GC) === 0) {
39
            $waypointType = self::GC;
40
        }
41
42
        if ($waypointType === null) {
43
            throw new UnknownWaypointTypeException(
44
                sprintf(
45
                    'Could not guess the waypoint type of the waypoint "%s"',
46
                    $waypoint
47
                )
48
            );
49
        }
50
51
        return $waypointType;
52
    }
53
}
54