SerializerCacheWarmer::isOptional()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Serializer bundle package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\SerializerBundle\CacheWarmer;
13
14
use Ivory\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
15
use Ivory\Serializer\Mapping\Loader\ClassMetadataLoaderInterface;
16
use Ivory\Serializer\Mapping\Loader\MappedClassMetadataLoaderInterface;
17
use Psr\Cache\CacheItemPoolInterface;
18
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
19
20
/**
21
 * @author GeLo <[email protected]>
22
 */
23
class SerializerCacheWarmer implements CacheWarmerInterface
24
{
25
    /**
26
     * @var ClassMetadataFactoryInterface
27
     */
28
    private $factory;
29
30
    /**
31
     * @var ClassMetadataLoaderInterface
32
     */
33
    private $loader;
34
35
    /**
36
     * @var CacheItemPoolInterface
37
     */
38
    private $pool;
39
40
    /**
41
     * @param ClassMetadataFactoryInterface $factory
42
     * @param ClassMetadataLoaderInterface  $loader
43
     * @param CacheItemPoolInterface        $pool
44
     */
45 36
    public function __construct(
46
        ClassMetadataFactoryInterface $factory,
47
        ClassMetadataLoaderInterface $loader,
48
        CacheItemPoolInterface $pool
49
    ) {
50 36
        $this->factory = $factory;
51 36
        $this->loader = $loader;
52 36
        $this->pool = $pool;
53 36
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 18
    public function warmUp($cacheDir)
59
    {
60 18
        if (!$this->loader instanceof MappedClassMetadataLoaderInterface) {
61 9
            return;
62
        }
63
64 9
        foreach ($this->loader->getMappedClasses() as $class) {
65 9
            $this->factory->getClassMetadata($class);
66 7
        }
67
68 9
        $this->pool->commit();
69 9
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 9
    public function isOptional()
75
    {
76 9
        return true;
77
    }
78
}
79