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

Result::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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