Completed
Push — master ( 11a693...420c23 )
by ignace nyamagana
03:57
created

Normalize   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 4
A getDefaultModifiers() 0 13 2
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\Modifiers;
13
14
use League\Uri\Interfaces\Uri;
15
use Psr\Http\Message\UriInterface;
16
17
/**
18
 * A class to normalize URI objects
19
 *
20
 * @package League.uri
21
 * @author  Ignace Nyamagana Butera <[email protected]>
22
 * @since   4.0.0
23
 */
24
class Normalize extends AbstractUriModifier
25
{
26
    /**
27
     * Return a Uri object modified according to the modifier
28
     *
29
     * @param Uri|UriInterface $uri
30
     *
31
     * @return Uri|UriInterface
32
     */
33 42
    public function __invoke($uri)
34
    {
35 42
        $this->assertUriObject($uri);
36 42
        $modifiers = $this->getDefaultModifiers();
37 42
        $path = $uri->getPath();
38 42
        if ('' !== $uri->getScheme().$uri->getAuthority()
39 42
            || (isset($path[0]) && '/' === $path[0])) {
40 39
            return $modifiers->pipe(new RemoveDotSegments())->__invoke($uri);
41
        }
42
43 3
        return $modifiers->__invoke($uri);
44
    }
45
46
    /**
47
     * Return the default modifier to apply on any URI object
48
     *
49
     * @return array
50
     */
51 42
    protected function getDefaultModifiers()
52
    {
53 42
        static $defaults;
54 42
        if (null === $defaults) {
55 3
            $defaults = new Pipeline([
56 3
                new HostToAscii(),
57 3
                new KsortQuery(),
58 3
                new DecodeUnreservedCharacters(),
59 2
            ]);
60 2
        }
61
62 42
        return $defaults;
63
    }
64
}
65