File   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 19 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Workout\Loader;
6
7
use Assert\Assertion;
8
use SportTrackerConnector\Core\Workout\Loader\GPX;
9
use SportTrackerConnector\Core\Workout\Loader\LoaderInterface;
10
use SportTrackerConnector\Core\Workout\Loader\TCX;
11
use SportTrackerConnector\Core\Workout\Workout;
12
13
class File implements LoaderInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function load(string $filePath): Workout
19
    {
20
        Assertion::file($filePath);
21
        Assertion::readable($filePath);
22
23
        $extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
24
        switch ($extension) {
25
            case 'gpx':
26
                $loader = new GPX();
27
                break;
28
            case 'tcx':
29
                $loader = new TCX();
30
                break;
31
            default:
32
                throw new \RuntimeException(sprintf('No loader for file "%s"', $filePath));
33
        }
34
35
        return $loader->load(file_get_contents($filePath));
36
    }
37
}
38