Passed
Push — master ( b74a1f...762e12 )
by MoshiMoshi
03:10
created

CacheCleanup   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 4
c 3
b 1
f 1
lcom 1
cbo 2
dl 0
loc 41
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A warmUp() 0 4 1
A isOptional() 0 4 1
A cleanUp() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the ConfigCacheBundle package.
5
 *
6
 * Copyright (c) 2015-2016 Yahoo Japan Corporation
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace YahooJapan\ConfigCacheBundle\CacheWarmer;
13
14
use Symfony\Component\Filesystem\Filesystem;
15
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
16
use YahooJapan\ConfigCacheBundle\ConfigCache\SaveAreaBuilder;
17
18
/**
19
 * The CacheCleanup is to clear the temporary directory.
20
 */
21
class CacheCleanup implements CacheWarmerInterface
22
{
23
    protected $builder;
24
    protected $filesystem;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param SaveAreaBuilder $builder
30
     * @param Filesystem      $filesystem
31
     */
32 12
    public function __construct(SaveAreaBuilder $builder, Filesystem $filesystem)
33
    {
34 12
        $this->builder    = $builder;
35 12
        $this->filesystem = $filesystem;
36 12
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 1
    public function warmUp($cacheDir)
42
    {
43 1
        $this->cleanUp();
44 1
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 11
    public function isOptional()
50
    {
51 11
        return true;
52
    }
53
54
    /**
55
     * Cleans up to clear the temporary directory after warming up.
56
     */
57 2
    public function cleanUp()
58
    {
59 2
        $this->filesystem->remove($this->builder->buildPrefix());
60 2
    }
61
}
62