Completed
Push — master ( 93fa4e...dc02e9 )
by WEBEWEB
04:24
created

IntegerPortTrait::setPort()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
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 integer
28
     */
29
    protected $port;
30
31
    /**
32
     * Get the port.
33
     *
34
     * @return integer Returns the port.
35
     */
36
    public function getPort() {
37
        return $this->port;
38
    }
39
40
    /**
41
     * Set the port.
42
     *
43
     * @param integer $port The port.
44
     * @throws InvalidArgumentException Throws an invalid argument exception if the port is not between 1 and 65536.
45
     */
46
    public function setPort($port) {
47
        if ($port < 0 || 65536 < $port) {
48
            throw new InvalidArgumentException("The port must be between 1 and 65536");
49
        }
50
        $this->port = $port;
51
        return $this;
52
    }
53
}
54