Completed
Push — master ( f85b73...7f85ed )
by Bohuslav
02:46
created

UriFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
crap 1
1
<?php
2
namespace Kambo\HttpMessage\Factories\Environment\Superglobal;
3
4
// \HttpMessage
5
use Kambo\HttpMessage\Uri;
6
use Kambo\HttpMessage\Environment\Environment;
7
use Kambo\HttpMessage\Factories\Environment\Interfaces\Factory;
8
9
/**
10
 * Create instance of Uri object from instance of Environment object
11
 *
12
 * @package Kambo\HttpMessage\Factories\Environment\Superglobal
13
 * @author  Bohuslav Simek <[email protected]>
14
 * @license MIT
15
 */
16
class UriFactory implements Factory
17
{
18
    /**
19
     * Create instances of Uri object from instance of Environment object
20
     *
21
     * @param Environment $environment environment data
22
     *
23
     * @return Uri Instance of Uri object created from environment
24
     */
25 2
    public function create(Environment $environment)
26
    {
27 2
        $scheme = $environment->getRequestScheme();
28 2
        $host   = $environment->getHost();
29 2
        $port   = $environment->getPort();
30
31 2
        $path  = parse_url('http://example.com' . $environment->getRequestUri(), PHP_URL_PATH);
32 2
        $query = $environment->getQueryString();
33 2
        $user  = $environment->getAuthUser();
34 2
        $pass  = $environment->getAuthPassword();
35
36 2
        return new Uri($scheme, $host, $port, $path, $query, '', $user, $pass);
0 ignored issues
show
Security Bug introduced by
It seems like $path defined by parse_url('http://exampl...estUri(), PHP_URL_PATH) on line 31 can also be of type false; however, Kambo\HttpMessage\Uri::__construct() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
37
    }
38
}
39