Passed
Push — master ( eac84f...04da79 )
by Tomasz
01:29
created

Response   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A fail() 0 6 1
A getPayload() 0 3 1
A ok() 0 5 1
A isSuccess() 0 3 1
A __construct() 0 3 1
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\CreateNode;
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