Completed
Push — master ( 6e4f15...3feaf0 )
by Alex
20s queued 11s
created

UrlGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAbsolutePath() 0 7 3
A generateAbsolutePath() 0 5 2
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FeedIo\Parser;
12
13
class UrlGenerator
14
{
15
16
    /**
17
     * @param string $host
18
     * @param string $path
19
     * @return string
20
     */
21 6
    public function getAbsolutePath(string $path, string $host = null): string
22
    {
23 6
        if (! parse_url($path, PHP_URL_HOST) && $host) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $host of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
24 1
            return $this->generateAbsolutePath($host, $path);
25
        }
26 5
        return $path;
27
    }
28
29
    /**
30
     * @param string $host
31
     * @param string $path
32
     * @return string
33
     */
34 2
    public function generateAbsolutePath(string $host, string $path): string
35
    {
36 2
        $path = substr($path, 0, 1) == '/' ? $path:"/{$path}";
37 2
        return $host . $path;
38
    }
39
}
40