ListZones   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 56
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setResult() 0 13 3
A __construct() 0 7 1
A getResult() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 *
5
 * Copyright (C) 2018  Ross Mitchell
6
 *
7
 * This file is part of RossMitchell/UpdateCloudFlare.
8
 *
9
 * RossMitchell/UpdateCloudFlare is free software: you can redistribute
10
 * it and/or modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
namespace RossMitchell\UpdateCloudFlare\Responses;
24
25
use RossMitchell\UpdateCloudFlare\Abstracts\CloudFlareResponse;
26
use RossMitchell\UpdateCloudFlare\Exceptions\CloudFlareException;
27
use RossMitchell\UpdateCloudFlare\Factories\Responses\ErrorFactory;
28
use RossMitchell\UpdateCloudFlare\Factories\Responses\Results\ListZoneResultsFactory;
29
use RossMitchell\UpdateCloudFlare\Responses\Results\ListZonesResult;
30
use Symfony\Component\Console\Exception\LogicException;
31
32
/**
33
 * Class ListZones
34
 * @package RossMitchell\UpdateCloudFlare\Responses
35
 */
36
class ListZones extends CloudFlareResponse
37
{
38
    /**
39
     * @var ListZonesResult[]
40
     */
41
    private $result;
42
    /**
43
     * @var ListZoneResultsFactory
44
     */
45
    private $zoneResultsFactory;
46
47
    /**
48
     * ListZones constructor.
49
     *
50
     * @param ListZoneResultsFactory $zoneResultsFactory
51
     * @param ErrorFactory           $errorFactory
52
     * @param \stdClass              $rawResult
53
     *
54
     * @throws LogicException
55
     * @throws CloudFlareException
56
     */
57 16
    public function __construct(
58
        ListZoneResultsFactory $zoneResultsFactory,
59
        ErrorFactory $errorFactory,
60
        \stdClass $rawResult
61
    ) {
62 16
        $this->zoneResultsFactory = $zoneResultsFactory;
63 16
        parent::__construct($rawResult, $errorFactory);
64 10
    }
65
66
    /**
67
     * @return ListZonesResult[]
68
     */
69 4
    public function getResult(): array
70
    {
71 4
        return $this->result;
72
    }
73
74
    /**
75
     * @param mixed $result
76
     *
77
     * @throws LogicException
78
     */
79 10
    public function setResult($result): void
80
    {
81 10
        $results = [];
82 10
        if (!\is_array($result)) {
83 1
            $this->result = $results;
84
85 1
            return;
86
        }
87
88 9
        foreach ($result as $data) {
89 9
            $results[] = $this->zoneResultsFactory->create($data);
90
        }
91 9
        $this->result = $results;
92 9
    }
93
}
94