Completed
Push — master ( 4de594...21f32b )
by ignace nyamagana
04:46
created

Port::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * League.Uri (http://uri.thephpleague.com)
4
 *
5
 * @package   League.uri
6
 * @author    Ignace Nyamagana Butera <[email protected]>
7
 * @copyright 2013-2015 Ignace Nyamagana Butera
8
 * @license   https://github.com/thephpleague/uri/blob/master/LICENSE (MIT License)
9
 * @version   4.2.0
10
 * @link      https://github.com/thephpleague/uri/
11
 */
12
namespace League\Uri\Components;
13
14
use InvalidArgumentException;
15
use League\Uri\Interfaces\Port as PortInterface;
16
17
/**
18
 * Value object representing a URI port component.
19
 *
20
 * @package League.uri
21
 * @author  Ignace Nyamagana Butera <[email protected]>
22
 * @since   1.0.0
23
 */
24
class Port extends AbstractComponent implements PortInterface
25
{
26
    /**
27
     * @inheritdoc
28
     */
29 784
    protected function validate($data)
30
    {
31 784
        if ('' === $data) {
32 3
            throw new InvalidArgumentException('Expected port to be a int or null; received an empty string');
33
        }
34
35 781
        return $this->validatePort($data);
36
    }
37
38
    /**
39
     * Returns the component literal value.
40
     *
41
     * @return int|null
42
     */
43 742
    public function getContent()
44
    {
45 742
        return $this->data;
46
    }
47
48
    /**
49
     * Return an integer representation of the Port component
50
     *
51
     * @return int|null
52
     */
53 728
    public function toInt()
54
    {
55 728
        return $this->getContent();
56
    }
57
58
    /**
59
     * Returns the instance string representation
60
     * with its optional URI delimiters
61
     *
62
     * @return string
63
     */
64 161
    public function getUriComponent()
65
    {
66 161
        $component = $this->__toString();
67 161
        if ('' !== $component) {
68 158
            return PortInterface::DELIMITER.$component;
69
        }
70
71 3
        return $component;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77 2
    public function __debugInfo()
78
    {
79 2
        return ['port' => $this->getContent()];
80
    }
81
}
82