RequestUrlResolver::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
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