Completed
Push — master ( b4abb9...a8f089 )
by ignace nyamagana
14:58
created

UriBuilderTrait::filterUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 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.0
10
 * @link      https://github.com/thephpleague/uri/
11
 */
12
namespace League\Uri\Schemes\Generic;
13
14
/**
15
 * A trait to format URI components
16
 *
17
 * @package League.uri
18
 * @author  Ignace Nyamagana Butera <[email protected]>
19
 * @since   4.1.0
20
 * @internal
21
 */
22
trait UriBuilderTrait
23
{
24
    /**
25
     * Normalize URI components hash
26
     *
27
     * @param array $components a hash representation of the URI components
28
     *                          similar to PHP parse_url function result
29
     *
30
     * @return array
31
     */
32
    protected static function normalizeUriHash(array $components)
33
    {
34
        return array_replace([
35
            'scheme' => null,
36
            'user' => null,
37
            'pass' => null,
38
            'host' => null,
39
            'port' => null,
40
            'path' => null,
41
            'query' => null,
42
            'fragment' => null,
43
        ], $components);
44
    }
45
46
    /**
47
     * Format the Path in a URI string
48
     *
49
     * @param string $path
50
     * @param string $authority the Authority part
51
     *
52
     * @return string
53
     */
54
    protected function formatPath($path, $authority)
55
    {
56
        if ('' == $authority) {
57
            return preg_replace(',^/+,', '/', $path);
58
        }
59
60
        if ('' !== $path && '/' != $path[0]) {
61
            return '/'.$path;
62
        }
63
64
        return $path;
65
    }
66
67
    /**
68
     * Format the user info
69
     *
70
     * @param string $user
71
     * @param string $pass
72
     *
73
     * @return string
74
     */
75
    protected static function buildUserInfo($user, $pass)
76
    {
77
        $userinfo = $user;
78
        if (null === $userinfo) {
79
            return '';
80
        }
81
82
        if (null !== $pass) {
83
            $userinfo .= ':'.$pass;
84
        }
85
86
        return $userinfo.'@';
87
    }
88
}
89