Completed
Push — master ( 93f504...996b1b )
by ignace nyamagana
03:50
created

Scheme   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 43
ccs 15
cts 15
cp 1
rs 10
wmc 6
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUriComponent() 0 9 2
A validate() 0 13 3
A __debugInfo() 0 4 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\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
     * @inheritdoc
28
     */
29 823
    protected function validate($scheme)
30
    {
31 823
        if (null === $scheme) {
32 324
            return $scheme;
33
        }
34
35 736
        $scheme = $this->validateString($scheme);
36 724
        if (!preg_match(',^[a-z]([-a-z0-9+.]+)?$,i', $scheme)) {
37 9
            throw new InvalidArgumentException(sprintf("Invalid Submitted scheme: '%s'", $scheme));
38
        }
39
40 715
        return strtolower($scheme);
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 2
    public function __debugInfo()
47
    {
48 2
        return ['scheme' => $this->getContent()];
49
    }
50
51
    /**
52
     * Returns the instance string representation
53
     * with its optional URI delimiters
54
     *
55
     * @return string
56
     */
57 515
    public function getUriComponent()
58
    {
59 515
        $component = $this->__toString();
60 515
        if ('' !== $component) {
61 332
            $component .= SchemeInterface::DELIMITER;
62 221
        }
63
64 515
        return $component;
65
    }
66
}
67