Passed
Push — master ( a76ba3...5b1507 )
by Tomasz
01:33
created

Result::getPayload()   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\Response;
6
use Aggrego\Domain\Board\Board;
7
8
class Result implements Response
9
{
10
    private const SUCCESS_KEY = 'success';
11
12
    /** @var array */
13
    private $payload;
14
15
    private function __construct(array $data)
16
    {
17
        $this->payload = $data;
18
    }
19
20
    public static function ok(Board $board): self
21
    {
22
        return new self(
23
            [
24
                self::SUCCESS_KEY => true,
25
                'board_uuid' => $board->getUuid()->getValue()
26
            ]
27
        );
28
    }
29
30
    public static function fail(string $reason): self
31
    {
32
        return new self(
33
            [
34
                self::SUCCESS_KEY => false,
35
                'error' => $reason
36
            ]
37
        );
38
    }
39
40
    public function isSuccess(): bool
41
    {
42
        return $this->payload[self::SUCCESS_KEY];
43
    }
44
45
    public function getPayload(): array
46
    {
47
        return $this->payload;
48
    }
49
}
50