ServersEndpoint::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
/*
4
 * This file is part of the CwdPowerDNS Client
5
 *
6
 * (c) 2018 cwd.at GmbH <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cwd\PowerDNSClient\Endpoints;
15
16
use Cwd\PowerDNSClient\Model\CacheFlushResult;
17
use Cwd\PowerDNSClient\Model\Config;
18
use Cwd\PowerDNSClient\Model\Server;
19
20
class ServersEndpoint extends AbstractEndpoint
21
{
22
    private const ENDPOINT = 'servers/%s';
23
24
    /**
25
     * @param null|string $serverId
26
     *
27
     * @return Server
28
     *
29
     * @throws \Http\Client\Exception
30
     */
31
    public function get(?string $serverId = null): Server
32
    {
33
        if (null === $serverId) {
34
            $serverId = $this->defaultServerId;
35
        }
36
37
        return $this->getClient()->call(null, sprintf('servers/%s', $serverId), Server::class, false, 'GET');
38
    }
39
40
    /**
41
     * @return Server[]
42
     *
43
     * @throws \Http\Client\Exception
44
     */
45
    public function all(): array
46
    {
47
        return $this->getClient()->call(null, 'servers', Server::class, true, 'GET');
48
    }
49
50
    /**
51
     * @return array
52
     *
53
     * @throws \Http\Client\Exception
54
     */
55
    public function statistics(): array
56
    {
57
        // Result is different - denormalize by hand
58
        return $this->getClient()->call(null, sprintf(self::ENDPOINT, $this->defaultServerId).'/statistics', null, false, 'GET');
59
    }
60
61
    public function cacheFlush(string $domain): CacheFlushResult
62
    {
63
        return $this->getClient()->call(null, sprintf(self::ENDPOINT.'/cache/flush', $this->defaultServerId), CacheFlushResult::class, false, 'PUT', ['domain' => $domain]);
64
    }
65
66
    /**
67
     * @return Config[]
68
     *
69
     * @throws \Http\Client\Exception
70
     */
71
    public function config(): array
72
    {
73
        $uri = sprintf(self::ENDPOINT, $this->defaultServerId).'/config';
74
75
        return $this->getClient()->call(null, $uri, Config::class, true, 'GET');
76
    }
77
}
78