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\TransformBoard;
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.transform_board.response';
12
    private const SUCCESS_KEY = 'success';
13
14
    /** @var array */
15
    private $payload;
16
17
    private function __construct(array $data)
18
    {
19
        $this->payload = $data;
20
    }
21
22
    public static function ok(Board $board): self
23
    {
24
        return new self(
25
            [
26
                self::SUCCESS_KEY => true,
27
                'board_uuid' => $board->getUuid()->getValue()
28
            ]
29
        );
30
    }
31
32
    public static function fail(string $reason): self
33
    {
34
        return new self(
35
            [
36
                self::SUCCESS_KEY => false,
37
                'error' => $reason
38
            ]
39
        );
40
    }
41
42
    public function isSuccess(): bool
43
    {
44
        return $this->payload[self::SUCCESS_KEY];
45
    }
46
47
    public function getPayload(): array
48
    {
49
        return $this->payload;
50
    }
51
52
    public function getName(): Name
53
    {
54
        return new Name(self::NAME);
55
    }
56
}
57