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

RouterCacheWarmer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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