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

WaypointType   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

1 Method

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