Completed
Push — master ( 69bbac...c6a45b )
by Dragos
03:11
created

SportGuesser::getSportFromCode()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 14
nc 7
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace SportTrackerConnector\Core\Workout;
6
7
/**
8
 * Simple class that tries to guess the sport from text representation.
9
 */
10
class SportGuesser
11
{
12
    /**
13
     * Get the sport code from the tracker sport code.
14
     *
15
     * @param string $code The code from the tracker.
16
     * @return string
17
     */
18
    public static function sportFromCode(string $code) : string
19
    {
20
        switch (strtolower(trim($code))) {
21
            case SportMapperInterface::RUNNING:
22
            case 'run':
23
                return SportMapperInterface::RUNNING;
24
            case SportMapperInterface::CYCLING_SPORT:
25
            case 'cycling':
26
                return SportMapperInterface::CYCLING_SPORT;
27
            case SportMapperInterface::CYCLING_TRANSPORT:
28
                return SportMapperInterface::CYCLING_TRANSPORT;
29
            case SportMapperInterface::SWIMMING:
30
                return SportMapperInterface::SWIMMING;
31
            default:
32
                return SportMapperInterface::OTHER;
33
        }
34
    }
35
}
36