UriFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 17 2
1
<?php
2
namespace Kambo\Http\Message\Factories\Environment\Superglobal;
3
4
// \Spl
5
use InvalidArgumentException;
6
7
// \Http\Message
8
use Kambo\Http\Message\Uri;
9
use Kambo\Http\Message\Environment\Environment;
10
use Kambo\Http\Message\Factories\Environment\Interfaces\FactoryInterface;
11
12
/**
13
 * Create instance of Uri object from instance of Environment object
14
 *
15
 * @package Kambo\Http\Message\Factories\Environment\Superglobal
16
 * @author  Bohuslav Simek <[email protected]>
17
 * @license MIT
18
 */
19
class UriFactory implements FactoryInterface
20
{
21
    /**
22
     * Create instances of Uri object from instance of Environment object
23
     *
24
     * @param Environment $environment environment data
25
     *
26
     * @return Uri Instance of Uri object created from environment
27
     */
28 5
    public function create(Environment $environment)
29
    {
30 5
        $scheme = $environment->getRequestScheme();
31 5
        $host   = $environment->getHost();
32 5
        $port   = $environment->getPort();
33 5
        $query  = $environment->getQueryString();
34 5
        $user   = $environment->getAuthUser();
35 5
        $pass   = $environment->getAuthPassword();
36
37
        // parse_url() requires a full URL - but only URL path is need it here.
38 5
        $path = parse_url('http://example.com' . $environment->getRequestUri(), PHP_URL_PATH);
39 5
        if ($path === false) {
40 1
            throw new InvalidArgumentException('Uri path must be a string');
41
        }
42
43 4
        return new Uri($scheme, $host, $port, $path, $query, '', $user, $pass);
44
    }
45
}
46