Passed
Pull Request — master (#9)
by Pavel
12:36
created

RouterCacheWarmer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
dl 0
loc 41
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1
ccs 5
cts 10
cp 0.5
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A warmUp() 0 6 2
A isOptional() 0 4 1
1
<?php
2
3
namespace Bankiru\Api\Rpc\Cache;
4
5
use Bankiru\Api\Rpc\Routing\MethodMatcher;
6
use Bankiru\Api\Rpc\Routing\Router;
7
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
8
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
9
10
final class RouterCacheWarmer implements CacheWarmerInterface
11
{
12
    const CACHE_DIR = 'rpc';
13
14
    /**
15
     * @var Router
16
     */
17
    private $router;
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param MethodMatcher $router A Router instance
23
     */
24 1
    public function __construct(MethodMatcher $router)
25
    {
26 1
        $this->router = $router;
0 ignored issues
show
Documentation Bug introduced by
$router is of type object<Bankiru\Api\Rpc\Routing\MethodMatcher>, but the property $router was declared to be of type object<Bankiru\Api\Rpc\Routing\Router>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
27 1
    }
28
29
    /**
30
     * Warms up the cache.
31
     *
32
     * @param string $cacheDir The cache directory
33
     */
34
    public function warmUp($cacheDir)
35
    {
36
        if ($this->router instanceof WarmableInterface) {
37
            $this->router->warmUp($cacheDir);
38
        }
39
    }
40
41
    /**
42
     * Checks whether this warmer is optional or not.
43
     *
44
     * @return bool always true
45
     */
46 1
    public function isOptional()
47
    {
48 1
        return true;
49
    }
50
}
51