Passed
Push — master ( 5b1507...1f04af )
by Tomasz
01:43
created

Result   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 47
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isSuccess() 0 3 1
A __construct() 0 3 1
A ok() 0 6 1
A fail() 0 6 1
A getPayload() 0 3 1
A getName() 0 3 1
1
<?php
2
3
namespace Aggrego\Domain\Api\Command\CreateBoard;
4
5
use Aggrego\CommandConsumer\Name;
6
use Aggrego\CommandConsumer\Response;
7
use Aggrego\Domain\Board\Board;
8
9
class Result implements Response
10
{
11
    public const NAME = 'domain.create_board.response';
12
13
    private const SUCCESS_KEY = 'success';
14
15
    /** @var array */
16
    private $payload;
17
18
    private function __construct(array $data)
19
    {
20
        $this->payload = $data;
21
    }
22
23
    public static function ok(Board $board): self
24
    {
25
        return new self(
26
            [
27
                self::SUCCESS_KEY => true,
28
                'board_uuid' => $board->getUuid()->getValue()
29
            ]
30
        );
31
    }
32
33
    public static function fail(string $reason): self
34
    {
35
        return new self(
36
            [
37
                self::SUCCESS_KEY => false,
38
                'error' => $reason
39
            ]
40
        );
41
    }
42
43
    public function isSuccess(): bool
44
    {
45
        return $this->payload[self::SUCCESS_KEY];
46
    }
47
48
    public function getPayload(): array
49
    {
50
        return $this->payload;
51
    }
52
53
    public function getName(): Name
54
    {
55
        return new Name(self::NAME);
56
    }
57
}
58