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.
Test Failed
Pull Request — master (#1904)
by Anton
02:21
created

HostSelector::getByHostnames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
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
class HostSelector
11
{
12
    private $hosts;
13
14 5
    public function __construct(HostCollection $hosts)
15
    {
16 5
        $this->hosts = $hosts;
17 5
    }
18
19
    /**
20
     * @param string $hosts
21
     * @param string $roles
22
     * @return Host[]
23
     */
24
    public function select($hosts, $roles)
25
    {
26
        if (!empty($hosts)) {
27
            return $this->getByHostnames($hosts);
28
        }
29
        if (!empty($roles)) {
30
            return $this->getByRoles($roles);
31
        }
32
        return $this->getAll();
33
    }
34
35
    /**
36
     * @return Host[]
37
     */
38 1
    public function getAll()
39
    {
40 1
        $hosts = [];
41 1
        foreach ($this->hosts as $host) {
42 1
            $hosts[] = $host;
43
        }
44 1
        return $hosts;
45
    }
46
47
    /**
48
     * @param string $hostnames
49
     * @return Host[]
50
     */
51 1
    public function getByHostnames(string $hostnames)
52
    {
53 1
        $hostnames = Range::expand(array_map('trim', explode(',', $hostnames)));
54 1
        return array_map([$this->hosts, 'get'], $hostnames);
55
    }
56
57
    /**
58
     * @param string $roles
59
     * @return Host[]
60
     */
61 2
    public function getByRoles(string $roles)
62
    {
63 2
        if (is_string($roles)) {
64 2
            $roles = array_map('trim', explode(',', $roles));
65
        }
66
67 2
        $hosts = [];
68 2
        foreach ($this->hosts as $host) {
69 2
            foreach ($host->get('roles', []) as $role) {
70 1
                if (in_array($role, $roles, true)) {
71 1
                    $hosts[] = $host;
72
                }
73
            }
74
        }
75
76 2
        return $hosts;
77
    }
78
}
79