Passed
Push — devel-3.0 ( 6664a5...af8b21 )
by Rubén
03:03
created

SessionTimeout::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\DataModel\ItemPreset;
26
27
use SP\Http\Address;
28
29
/**
30
 * Class SessionTimeout
31
 *
32
 * @package SP\DataModel\ItemPreset
33
 */
34
class SessionTimeout
35
{
36
    /**
37
     * @var string
38
     */
39
    private $address;
40
    /**
41
     * @var string
42
     */
43
    private $mask;
44
    /**
45
     * @var int
46
     */
47
    private $timeout;
48
49
    /**
50
     * SessionTimeout constructor.
51
     *
52
     * @param string $address IP address and/or mask
53
     * @param int    $timeout Timeout in seconds
54
     *
55
     * @throws \SP\Core\Exceptions\InvalidArgumentException
56
     */
57
    public function __construct(string $address, int $timeout)
58
    {
59
        $parse = Address::parse4($address);
60
61
        $this->address = $parse['address'];
62
        $this->timeout = $timeout;
63
64
        $this->setMask($parse);
65
    }
66
67
    /**
68
     * @param array $parse
69
     */
70
    private function setMask(array $parse)
71
    {
72
        if (isset($parse['cidr'])) {
73
            $this->mask = Address::cidrToDec($parse['cidr']);
74
        } elseif (isset($parse['mask'])) {
75
            $this->mask = $parse['mask'];
76
        } else {
77
            $this->mask = '255.255.255.255';
78
        }
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getAddress(): string
85
    {
86
        return $this->address;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getMask(): string
93
    {
94
        return $this->mask;
95
    }
96
97
    /**
98
     * @return int
99
     */
100
    public function getTimeout(): int
101
    {
102
        return $this->timeout;
103
    }
104
}