Factory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 8 3
A __construct() 0 4 1
1
<?php
2
/**
3
 *
4
 * This file is part of the Aggrego.
5
 * (c) Tomasz Kunicki <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
declare(strict_types = 1);
13
14
namespace Aggrego\Domain\Profile\BoardConstruction;
15
16
use Aggrego\Domain\Profile\BoardConstruction\Exception\BuilderNotFoundException;
17
use Aggrego\Domain\Profile\Profile;
18
use Assert\Assertion;
19
20
class Factory
21
{
22
    /**
23
     * @var Watchman[]
24
     */
25
    private $watchmen;
26
27
    public function __construct(array $watchmen)
28
    {
29
        Assertion::allImplementsInterface($watchmen, Watchman::class);
30
        $this->watchmen = $watchmen;
31
    }
32
33
    public function factory(Profile $profile): Builder
34
    {
35
        foreach ($this->watchmen as $watchman) {
36
            if ($watchman->isSupported($profile)) {
37
                return $watchman->passBuilder($profile);
38
            }
39
        }
40
        throw new BuilderNotFoundException();
41
    }
42
}
43