Completed
Push — master ( be4b54...4b1069 )
by ignace nyamagana
04:15
created

UriBuilderTrait::normalizeUriHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 13
ccs 11
cts 11
cp 1
rs 9.4285
cc 1
eloc 11
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\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 692
    protected static function normalizeUriHash(array $components)
33
    {
34 692
        return array_replace([
35 692
            'scheme' => null,
36 461
            'user' => null,
37 461
            'pass' => null,
38 461
            'host' => null,
39 461
            'port' => null,
40 461
            'path' => '',
41 461
            'query' => null,
42 461
            'fragment' => null,
43 461
        ], $components);
44
    }
45
46
    /**
47
     * Format the user info
48
     *
49
     * @param string $user
50
     * @param string $pass
51
     *
52
     * @return string
53
     */
54 57
    protected static function buildUserInfo($user, $pass)
55
    {
56 57
        $userinfo = $user;
57 57
        if (null === $userinfo) {
58 12
            return '';
59
        }
60
61 45
        if (null !== $pass) {
62 45
            $userinfo .= ':'.$pass;
63 30
        }
64
65 45
        return $userinfo.'@';
66
    }
67
}
68