IntegerPortTrait::getPort()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2019 WEBEWEB
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
namespace WBW\Library\Core\Model\Attribute;
13
14
use InvalidArgumentException;
15
16
/**
17
 * Integer port trait.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Library\Core\Model\Attribute
21
 */
22
trait IntegerPortTrait {
23
24
    /**
25
     * Port.
26
     *
27
     * @var int|null
28
     */
29
    protected $port;
30
31
    /**
32
     * Get the port.
33
     *
34
     * @return int|null Returns the port.
35
     */
36
    public function getPort(): ?int {
37
        return $this->port;
38
    }
39
40
    /**
41
     * Set the port.
42
     *
43
     * @param int|null $port The port.
44
     * @return self Returns this instance.
45
     * @throws InvalidArgumentException Throws an invalid argument exception if the port is not between 1 and 65536.
46
     */
47
    public function setPort(?int $port): self {
48
        if ($port < 0 || 65536 < $port) {
49
            throw new InvalidArgumentException("The port must be between 1 and 65536");
50
        }
51
        $this->port = $port;
52
        return $this;
53
    }
54
}
55