AgentServiceRegister   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 16
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A service() 0 16 1
A result() 0 4 1
1
<?php
2
/**
3
 * /agent/service/register
4
 * User: moyo
5
 * Date: 24/08/2017
6
 * Time: 4:54 PM
7
 */
8
9
namespace Carno\Consul\APIs;
10
11
use Carno\Consul\Types\Result;
12
use Carno\Consul\Types\Service;
13
use Carno\Promise\Promised;
14
15
class AgentServiceRegister extends AbstractGate
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $method = 'PUT';
21
22
    /**
23
     * @var string
24
     */
25
    protected $uri = '/agent/service/register';
26
27
    /**
28
     * @var Service
29
     */
30
    private $service = null;
31
32
    /**
33
     * @param Service $service
34
     * @return self
35
     */
36
    public function service(Service $service) : self
37
    {
38
        $this->service = $service;
39
40
        $endpoint = $service->endpoint();
41
42
        $this->setPayload([
43
            'ID' => $service->id(),
44
            'Name' => $service->name(),
45
            'Tags' => $endpoint->getTags(),
46
            'Address' => $endpoint->address()->host(),
47
            'Port' => $endpoint->address()->port(),
48
            'Check' => $service->getKeepalive(),
49
        ]);
50
51
        return $this;
52
    }
53
54
    /**
55
     * @return Promised|Result
56
     */
57
    public function result()
58
    {
59
        return $this->simpleHCodeResult()->then(function (Result $result) {
60
            return $this->service->registered($this->agent(), $this->assigned(), $result);
61
        });
62
    }
63
}
64