RequestUrlResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 12 2
1
<?php
2
3
namespace SfCod\Filesystem\Resolvable\Resolver;
4
5
use SfCod\Filesystem\Resolvable\ResolverInterface;
6
use Symfony\Component\HttpFoundation\RequestStack;
7
8
/**
9
 * Class RequestUrlResolver
10
 *
11
 * @author Virchenko Maksim <[email protected]>
12
 *
13
 * @package SfCod\Filesystem\Resolvable\Resolver
14
 */
15
class RequestUrlResolver implements ResolverInterface
16
{
17
    /**
18
     * @var RequestStack
19
     */
20
    private $requestStack;
21
22
    /**
23
     * RequestUrlResolver constructor.
24
     *
25
     * @param string $prefix
0 ignored issues
show
Bug introduced by
There is no parameter named $prefix. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
26
     */
27
    public function __construct(RequestStack $requestStack)
28
    {
29
        $this->requestStack = $requestStack;
30
    }
31
32
    /**
33
     * Resolves an object path to an URI.
34
     *
35
     * @param string $path Object path
36
     *
37
     * @return string
38
     */
39
    public function resolve(string $path): string
40
    {
41
        if ($this->requestStack->getCurrentRequest()) {
42
            $request = $this->requestStack->getCurrentRequest();
43
44
            $baseUrl = rtrim($request->getSchemeAndHttpHost() . $request->getBaseUrl(), '/');
45
        } else {
46
            $baseUrl = '';
47
        }
48
49
        return $baseUrl . '/' . ltrim($path, '/');
50
    }
51
}
52