Passed
Pull Request — master (#9)
by Pavel
11:27
created

RouterCacheWarmer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 50%

Importance

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

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 Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
7
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
8
9
final class RouterCacheWarmer implements CacheWarmerInterface
10
{
11
    const CACHE_DIR = 'rpc';
12
13
    /**
14
     * @var MethodMatcher
15
     */
16
    private $router;
17
18
    /**
19
     * Constructor.
20
     *
21
     * @param MethodMatcher $router A Router instance
22
     */
23 1
    public function __construct(MethodMatcher $router)
24
    {
25 1
        $this->router = $router;
26 1
    }
27
28
    /**
29
     * Warms up the cache.
30
     *
31
     * @param string $cacheDir The cache directory
32
     */
33
    public function warmUp($cacheDir)
34
    {
35
        if ($this->router instanceof WarmableInterface) {
36
            $this->router->warmUp($cacheDir);
37
        }
38
    }
39
40
    /**
41
     * Checks whether this warmer is optional or not.
42
     *
43
     * @return bool always true
44
     */
45 1
    public function isOptional()
46
    {
47 1
        return true;
48
    }
49
}
50