Passed
Push — master ( 04da79...785494 )
by Tomasz
01:35
created

Response::ok()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * This file is part of the Aggrego.
5
 * (c) Tomasz Kunicki <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
namespace Aggrego\Neo4jIntegration\Api\Command\RunCommand;
13
14
use Aggrego\CommandConsumer\Name;
15
use Aggrego\CommandConsumer\Response as CommandConsumerResponse;
16
17
class Response implements CommandConsumerResponse
18
{
19
    private const NAME = 'neo4j_integration.create_node.response';
20
21
    private const SUCCESS_KEY = 'success';
22
23
    /** @var array */
24
    private $payload;
25
26
    private function __construct(array $data)
27
    {
28
        $this->payload = $data;
29
    }
30
31
    public function getName(): Name
32
    {
33
        return new Name(self::NAME);
34
    }
35
36
    public static function ok(): self
37
    {
38
        return new self(
39
            [
40
                self::SUCCESS_KEY => true
41
            ]
42
        );
43
    }
44
45
    public static function fail(string $reason): self
46
    {
47
        return new self(
48
            [
49
                self::SUCCESS_KEY => false,
50
                'error' => $reason
51
            ]
52
        );
53
    }
54
55
    public function isSuccess(): bool
56
    {
57
        return $this->payload[self::SUCCESS_KEY];
58
    }
59
60
    public function getPayload(): array
61
    {
62
        return $this->payload;
63
    }
64
}
65