Passed
Push — master ( ac5429...699403 )
by Ross
02:06
created

IpType::setType()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 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\Data;
24
25
use Symfony\Component\Console\Exception\LogicException;
26
27
/**
28
 * Class IpType
29
 * @package RossMitchell\UpdateCloudFlare\Data
30
 */
31
class IpType
32
{
33
    const IP_V4 = 'A';
34
    const IP_V6 = 'AAAA';
35
36
    /**
37
     * @var string
38
     */
39
    private $type;
40
41
    /**
42
     * @return string
43
     * @throws LogicException
44
     */
45
    public function getType(): string
46
    {
47
        if ($this->type === null) {
48
            throw new LogicException('You must set the type');
49
        }
50
51
        return $this->type;
52
    }
53
54
    /**
55
     * @param string $type
56
     *
57
     * @return IpType
58
     * @throws LogicException
59
     */
60
    public function setType(string $type): IpType
61
    {
62
        switch ($type) {
63
            case self::IP_V4:
64
            case self::IP_V6;
65
                $this->type = $type;
66
                break;
67
            default:
68
                throw new LogicException('IP Type must be either '.self::IP_V4.' or '.self::IP_V6);
69
        }
70
71
        return $this;
72
    }
73
74
}
75