ServerRepository::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Bencagri\Artisan\Deployer\Server;
5
6
7
class ServerRepository
8
{
9
    /** @var Server[] $servers */
10
    private $servers = [];
11
12
    public function __toString() : string
13
    {
14
        return implode(', ', $this->servers);
15
    }
16
17
    public function add(Server $server) : void
18
    {
19
        $this->servers[] = $server;
20
    }
21
22
    public function findAll() : array
23
    {
24
        return $this->servers;
25
    }
26
27
    /**
28
     * @return Server[]
29
     */
30
    public function findByRoles(array $roles) : array
31
    {
32
        return array_filter($this->servers, function (Server $server) use ($roles) {
33
            return !empty(array_intersect($roles, $server->getRoles()));
34
        });
35
    }
36
}
37