Passed
Push — master ( 2ee0d1...1e8995 )
by Tomasz
03:21
created

Factory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Aggrego\Domain\Api\Application\Profile\UnitTransformation;
6
7
use Aggrego\Domain\Api\Application\Profile\UnitTransformation\Exception\TransformationNotFoundException;
8
use Aggrego\Domain\Profile\Profile;
9
use Assert\Assertion;
10
11
class Factory
12
{
13
    /** @var Watchman[] */
14
    private $watchmen;
15
16
    public function __construct(array $watchmen)
17
    {
18
        Assertion::allImplementsInterface($watchmen, Watchman::class);
19
        $this->watchmen = $watchmen;
20
    }
21
22
    public function factory(Profile $profile): Transformation
23
    {
24
        foreach ($this->watchmen as $watchman) {
25
            if ($watchman->isSupported($profile)) {
26
                return $watchman->passTransformation($profile);
27
            }
28
        }
29
        throw new TransformationNotFoundException();
30
    }
31
}
32