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.
Passed
Push — master ( 1e26ef...49c694 )
by Anton
02:24
created

FileLoader::getHosts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Host;
9
10
use Deployer\Exception\Exception;
11
use Symfony\Component\Yaml\Yaml;
12
13
class FileLoader
14
{
15
    /**
16
     * @var Host[]
17
     */
18
    private $hosts = [];
19
20
    /**
21
     * @param string $file
22
     * @return $this
23
     * @throws Exception
24
     */
25 2
    public function load($file)
26
    {
27 2
        if (!file_exists($file) || !is_readable($file)) {
28
            throw new Exception("File `$file` doesn't exists or doesn't readable.");
29
        }
30
31 2
        $data = Yaml::parse(file_get_contents($file));
32
33 2
        if (!is_array($data)) {
34
            throw new Exception("Hosts file `$file` should contains array of hosts.");
35
        }
36
37 2
        foreach ($data as $hostname => $config) {
38 2
            if (preg_match('/^\./', $hostname)) {
39 2
                continue;
40
            }
41
42 2
            if (isset($config['local'])) {
43 2
                $host = new Localhost($hostname);
44
            } else {
45 2
                $host = new Host($hostname);
46
                $methods = [
47 2
                    'hostname',
48
                    'user',
49
                    'port',
50
                    'configFile',
51
                    'identityFile',
52
                    'forwardAgent',
53
                    'multiplexing',
54
                    'sshOptions',
55
                    'sshFlags',
56
                    'shellCommand',
57
                ];
58
59 2
                foreach ($methods as $method) {
60 2
                    if (isset($config[$method])) {
61 2
                        $host->$method($config[$method]);
62
                    }
63
                }
64
            }
65
66 2
            if (is_array($config)) {
67 2
                foreach ($config as $name => $value) {
68 2
                    $host->set($name, $value);
69
                }
70
            }
71
72 2
            $this->hosts[$hostname] = $host;
73
        }
74
75 2
        return $this;
76
    }
77
78
    /**
79
     * @return Host[]
80
     */
81 2
    public function getHosts()
82
    {
83 2
        return $this->hosts;
84
    }
85
}
86