Builder::isSupported()   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
 * 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\DataDomainBoard\Board;
15
16
use Aggrego\DataDomainBoard\Board\Board as DataBoard;
17
use Aggrego\DataDomainBoard\Board\Prototype\Board as DataBoardPrototype;
18
use Aggrego\DataDomainBoard\Board\Prototype\Metadata as DataBoardMetadata;
19
use Aggrego\Domain\Board\Board as DomainBoard;
20
use Aggrego\Domain\Board\Builder as FactoryInterface;
21
use Aggrego\Domain\Board\Exception\UnsupportedPrototypeBuilderException;
22
use Aggrego\Domain\Board\Key;
23
use Aggrego\Domain\Board\Prototype\Board as PrototypeBoard;
24
use Aggrego\Domain\Board\Prototype\Metadata;
25
use Aggrego\Domain\Board\Prototype\Metadata as DomainMetadata;
26
use Aggrego\Domain\Board\Uuid;
27
use Aggrego\Domain\Profile\Profile;
28
use Assert\Assertion;
29
use Assert\AssertionFailedException;
30
31
class Builder implements FactoryInterface
32
{
33
    public function isSupported(PrototypeBoard $board): bool
34
    {
35
        return $board instanceof DataBoardPrototype;
36
    }
37
38
    /**
39
     * @param Uuid $uuid
40
     * @param Key $key
41
     * @param Profile $profile
42
     * @param DomainMetadata|DataBoardMetadata $metadata
43
     * @param Uuid|null $parentUuid
44
     * @return DomainBoard
45
     */
46
    public function build(
47
        Uuid $uuid,
48
        Key $key,
49
        Profile $profile,
50
        DomainMetadata $metadata,
51
        ?Uuid $parentUuid
52
    ): DomainBoard {
53
        try {
54
            Assertion::isInstanceOf($metadata, DataBoardMetadata::class);
55
        } catch (AssertionFailedException $e) {
56
            throw new UnsupportedPrototypeBuilderException($e->getMessage(), $e->getCode(), $e);
57
        }
58
        /** @var DataBoardMetadata $metadata */
59
        return new DataBoard($uuid, $key, $profile, $metadata, $parentUuid);
60
    }
61
}
62