Passed
Pull Request — master (#295)
by Fabien
02:25
created

Loader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromPath() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\Configuration;
6
7
use InvalidArgumentException;
8
use Symfony\Component\Yaml\Yaml;
9
10
class Loader
11
{
12
13
    /**
14
     * @param string $confPath Path of the configuration file to load.
15
     * @throws InvalidArgumentException If the configuration file cannot be read.
16
     */
17
    public static function fromPath(string $confPath): Config
18
    {
19
        $originalConfPath = $confPath;
20
21
        if (\is_dir($confPath)) {
22
            $confPath = \rtrim($confPath, '/\\') . '/churn.yml';
23
        }
24
25
        if (!\is_readable($confPath)) {
26
            throw new InvalidArgumentException('The configuration file can not be read at ' . $originalConfPath);
27
        }
28
29
        $content = (string) \file_get_contents($confPath);
30
31
        return Config::create(Yaml::parse($content) ?? []);
32
    }
33
}
34