Passed
Push — master ( dd3b28...5b41a6 )
by Gerhard
10:03
created

RequestContext::getResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Enhavo\Bundle\MultiTenancyBundle\Request;
4
5
use Enhavo\Bundle\MultiTenancyBundle\Resolver\ResolverInterface;
6
7
/**
8
 * We want to use the tenant in static routes condition. Unlike in cmf routing, the static routes getting compiled to php
9
 * for faster execution. So it is hard to inject further variables to the condition language expression. Thus, we abuse
10
 * the request context to inject our resolver to make it available in any static routing condition expression.
11
 */
12
class RequestContext extends \Symfony\Component\Routing\RequestContext
13
{
14
    private ?ResolverInterface $resolver;
15
16
    public function getTenant(): ?string
17
    {
18
        return $this->resolver->getTenant()?->getKey();
0 ignored issues
show
Bug introduced by
The method getTenant() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        return $this->resolver->/** @scrutinizer ignore-call */ getTenant()?->getKey();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
    }
20
21
    public function getResolver(): ?ResolverInterface
22
    {
23
        return $this->resolver;
24
    }
25
26
    public function setResolver(?ResolverInterface $resolver): void
27
    {
28
        $this->resolver = $resolver;
29
    }
30
}
31