Passed
Push — master ( 1457de...9c6417 )
by Tomasz
02:07
created

Result   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 40
rs 10
c 0
b 0
f 0

5 Methods

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