GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 5ac723...c719eb )
by Stan
07:02
created

AbstractLoader::loadFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Teebot\Configuration;
4
5
use Symfony\Component\Config\Definition\Processor;
6
use Symfony\Component\Config\Exception\FileLoaderLoadException;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\Yaml\Yaml;
9
use Dotenv\Dotenv;
10
use Dotenv\Exception\InvalidPathException;
11
12
abstract class AbstractLoader
13
{
14
    const FILE_NAME = 'config%s.yml';
15
16
    /**
17
     * @var string $path
18
     */
19
    protected $path;
20
21
    /**
22
     * @var string $fileName
23
     */
24
    protected $fileName;
25
26
    public function __construct($path)
27
    {
28
        $this->initEnv($path);
29
30
        $this->path     = $path;
31
        $this->fileName = $this->getFileName();
32
    }
33
34
    public function load()
35
    {
36
        $configFile = $this->getConfigFile();
37
        $data       = Yaml::parse(file_get_contents($configFile));
38
39
        return $this->loadFromArray($data);
40
    }
41
42
    public function loadFromArray($configData)
43
    {
44
        $config = $this->processConfig($configData);
45
46
        return $this->initContainer($config);
47
    }
48
49
    protected function getFileName()
50
    {
51
        $env = getenv('ENV') ? '_' . getenv('ENV') : '';
52
53
        return sprintf(static::FILE_NAME, $env);
54
    }
55
56
    protected function initEnv($path)
57
    {
58
        try {
59
            $dotenv = new Dotenv($path);
60
            $dotenv->load();
61
        } catch (InvalidPathException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
62
        }
63
    }
64
65
    protected function getConfigFile()
66
    {
67
        $locator    = new FileLocator($this->path);
68
        $configFile = $locator->locate($this->fileName, null, true);
69
70
        if (!is_readable($configFile)) {
71
            throw new FileLoaderLoadException('Config file is not readable!');
72
        }
73
74
        return $configFile;
75
    }
76
77
    protected function processConfig($data)
78
    {
79
        $processor       = new Processor();
80
        $configuration   = $this->getConfiguration();
81
        $processedConfig = $processor->processConfiguration($configuration, $data);
82
83
        return $processedConfig;
84
    }
85
86
    abstract protected function getConfiguration();
87
88
    abstract protected function initContainer($config);
89
}
90