Completed
Pull Request — master (#46)
by ignace nyamagana
03:43
created

Scheme::__debugInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
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.1.1
10
 * @link      https://github.com/thephpleague/uri/
11
 */
12
namespace League\Uri\Components;
13
14
use InvalidArgumentException;
15
use League\Uri\Interfaces\Scheme as SchemeInterface;
16
17
/**
18
 * Value object representing a URI scheme component.
19
 *
20
 * @package League.uri
21
 * @author  Ignace Nyamagana Butera <[email protected]>
22
 * @since   1.0.0
23
 */
24
class Scheme extends AbstractComponent implements SchemeInterface
25
{
26
    /**
27
     * Validate and format the submitted string scheme
28
     *
29
     * @param  string                   $scheme
30
     * @throws InvalidArgumentException if the scheme is invalid
31
     *
32
     * @return string
33
     */
34 607
    protected function validate($scheme)
35
    {
36 607
        if (!preg_match(',^[a-z]([-a-z0-9+.]+)?$,i', $scheme)) {
37 9
            throw new InvalidArgumentException(sprintf("Invalid Submitted scheme: '%s'", $scheme));
38
        }
39
40 598
        return strtolower($scheme);
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 2
    public function __debugInfo()
47
    {
48 2
        return ['scheme' => $this->__toString()];
49
    }
50
51
    /**
52
     * Returns the instance string representation
53
     * with its optional URI delimiters
54
     *
55
     * @return string
56
     */
57 308
    public function getUriComponent()
58
    {
59 308
        $component = $this->__toString();
60 308
        if ('' !== $component) {
61 272
            $component .= SchemeInterface::DELIMITER;
62 181
        }
63
64 308
        return $component;
65
    }
66
}
67