Completed
Push — master ( 328402...1cd18c )
by Julien
587:13 queued 584:54
created

ReverseProxyNewVirtualHostPayload   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 5 1
A getBaseVirtualHost() 0 3 1
A getService() 0 3 1
A __construct() 0 4 1
A fromArray() 0 3 1
1
<?php
2
3
namespace TheAentMachine\Aent\Payload\ReverseProxy;
4
5
use TheAentMachine\Aent\Payload\JsonPayloadInterface;
6
use TheAentMachine\Service\Exception\ServiceException;
7
use TheAentMachine\Service\Service;
8
9
final class ReverseProxyNewVirtualHostPayload implements JsonPayloadInterface
10
{
11
    /** @var string */
12
    private $baseVirtualHost;
13
14
    /** @var Service */
15
    private $service;
16
17
    /**
18
     * ReverseProxyNewVirtualHostPayload constructor.
19
     * @param string $baseVirtualHost
20
     * @param Service $service
21
     */
22
    public function __construct(string $baseVirtualHost, Service $service)
23
    {
24
        $this->baseVirtualHost = $baseVirtualHost;
25
        $this->service = $service;
26
    }
27
28
    /**
29
     * @return mixed[]
30
     * @throws ServiceException
31
     */
32
    public function toArray(): array
33
    {
34
        return [
35
            'BASE_VIRTUAL_HOST' => $this->baseVirtualHost,
36
            'SERVICE' => $this->service->jsonSerialize(),
37
        ];
38
    }
39
40
    /**
41
     * @param mixed[] $assoc
42
     * @return self
43
     * @throws ServiceException
44
     */
45
    public static function fromArray(array $assoc): self
46
    {
47
        return new self($assoc['BASE_VIRTUAL_HOST'], Service::parsePayload($assoc['SERVICE']));
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getBaseVirtualHost(): string
54
    {
55
        return $this->baseVirtualHost;
56
    }
57
58
    /**
59
     * @return Service
60
     */
61
    public function getService(): Service
62
    {
63
        return $this->service;
64
    }
65
}
66