ServerRepository   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A findByRoles() 0 4 1
A findAll() 0 3 1
A __toString() 0 3 1
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