YamlRouteProvider::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace MatthiasMullie\Api\Routes\Providers;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
/**
8
 * @author Matthias Mullie <[email protected]>
9
 * @copyright Copyright (c) 2016, Matthias Mullie. All rights reserved
10
 * @license LICENSE MIT
11
 */
12
class YamlRouteProvider extends ArrayRouteProvider implements RouteProviderInterface
13
{
14
    /**
15
     * @param string $path Path to route data
16
     *
17
     * @throws Exception
18
     */
19
    public function __construct(string $path)
20
    {
21
        if (!class_exists('Symfony\Component\Yaml\Yaml')) {
22
            throw new Exception('Yaml not installed. composer require symfony/yaml');
23
        }
24
25
        $contents = file_get_contents($path);
26
        $data = Yaml::parse($contents);
27
        parent::__construct($data);
28
    }
29
}
30