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 fail() 0 6 1
A getPayload() 0 3 1
A __construct() 0 3 1
A ok() 0 5 1
A isSuccess() 0 3 1
A getName() 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\CreateRelationship;
13
14
use Aggrego\CommandConsumer\Name;
15
use Aggrego\CommandConsumer\Response as CommandConsumerResponse;
16
17
18
class Response implements CommandConsumerResponse
19
{
20
    private const NAME = 'neo4j_integration.create_relationship.response';
21
22
    private const SUCCESS_KEY = 'success';
23
24
    /** @var array */
25
    private $payload;
26
27
    private function __construct(array $data)
28
    {
29
        $this->payload = $data;
30
    }
31
32
    public function getName(): Name
33
    {
34
        return new Name(self::NAME);
35
    }
36
37
    public static function ok(): self
38
    {
39
        return new self(
40
            [
41
                self::SUCCESS_KEY => true
42
            ]
43
        );
44
    }
45
46
    public static function fail(string $reason): self
47
    {
48
        return new self(
49
            [
50
                self::SUCCESS_KEY => false,
51
                'error' => $reason
52
            ]
53
        );
54
    }
55
56
    public function isSuccess(): bool
57
    {
58
        return $this->payload[self::SUCCESS_KEY];
59
    }
60
61
    public function getPayload(): array
62
    {
63
        return $this->payload;
64
    }
65
}
66