Passed
Push — master ( 2ee0d1...1e8995 )
by Tomasz
03:21
created

Response   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createValidResponse() 0 8 1
A getProfileName() 0 3 1
A getBody() 0 3 1
A createInvalidResponse() 0 7 1
A getStatus() 0 3 1
A getVersionNumber() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Aggrego\Domain\Api\Domain\Query\GetUnit;
6
7
use Aggrego\Domain\Model\Unit\Unit;
8
9
class Response
10
{
11
    public const INVALID = 'invalid';
12
    public const DONE = 'done';
13
14
    /** @var string */
15
    private $profile;
16
17
    /** @var string */
18
    private $versionNumber;
19
20
    /** @var string */
21
    private $status;
22
23
    /** @var string */
24
    private $body;
25
26
    private function __construct(string $profile, string $versionNumber, string $status, string $body)
27
    {
28
        $this->profile = $profile;
29
        $this->versionNumber = $versionNumber;
30
        $this->status = $status;
31
        $this->body = $body;
32
    }
33
34
    public static function createInvalidResponse(Query $query): self
35
    {
36
        return new self(
37
            $query->getProfile()->getName()->getValue(),
38
            $query->getProfile()->getVersion()->getValue(),
39
            self::INVALID,
40
            ''
41
        );
42
    }
43
44
    public static function createValidResponse(Unit $unit): self
45
    {
46
        $profile = $unit->getProfile();
47
        return new self(
48
            $profile->getName()->getValue(),
49
            $profile->getVersion()->getValue(),
50
            self::DONE,
51
            $unit->getData()->getValue()
52
        );
53
    }
54
55
    public function getProfileName(): string
56
    {
57
        return $this->profile;
58
    }
59
60
    public function getVersionNumber(): string
61
    {
62
        return $this->versionNumber;
63
    }
64
65
    public function getStatus(): string
66
    {
67
        return $this->status;
68
    }
69
70
    public function getBody(): string
71
    {
72
        return (string)$this->body;
73
    }
74
}
75