Completed
Pull Request — master (#1632)
by Kentaro
32:45
created

Cache::clear()   C

Complexity

Conditions 7
Paths 11

Size

Total Lines 30
Code Lines 21

Duplication

Lines 14
Ratio 46.67 %

Code Coverage

Tests 7
CRAP Score 14.432

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 14
loc 30
ccs 7
cts 15
cp 0.4667
rs 6.7272
cc 7
eloc 21
nc 11
nop 3
crap 14.432
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
namespace Eccube\Util;
25
26
use Symfony\Component\Filesystem\Filesystem;
27
use Symfony\Component\Finder\Finder;
28
29
/**
30
 * キャッシュ関連のユーティリティクラス.
31
 */
32
class Cache
33
{
34
35
    /**
36
     * キャッシュを削除する.
37
     *
38
     * doctrine, profiler, twig によって生成されたキャッシュディレクトリを削除する.
39
     * キャッシュは $app['config']['root_dir'].'/app/cache' に生成されます.
40
     *
41
     * @param Application $app
42
     * @param boolean $isAll .gitkeep を残してすべてのファイル・ディレクトリを削除する場合 true, 各ディレクトリのみを削除する場合 false
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 2 spaces after parameter name; 1 found
Loading history...
43
     * @param boolean $isTwig Twigキャッシュファイルのみ削除する場合 true
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
44
     * @return boolean 削除に成功した場合 true
45
     */
46 4
    public static function clear($app, $isAll, $isTwig = false)
47
    {
48 2
        $cacheDir = $app['config']['root_dir'].'/app/cache';
49
50
        $filesystem = new Filesystem();
51 4
        if ($isAll) {
52
            $finder = Finder::create()->in($cacheDir)->notName('.gitkeep');
53
            $filesystem->remove($finder);
54 3 View Code Duplication
        } elseif ($isTwig) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
            if (is_dir($cacheDir.'/twig')) {
56
                $finder = Finder::create()->in($cacheDir.'/twig');
57
                $filesystem->remove($finder);
58
            }
59
        } else {
60 View Code Duplication
            if (is_dir($cacheDir.'/doctrine')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
                $finder = Finder::create()->in($cacheDir.'/doctrine');
62
                $filesystem->remove($finder);
63
            }
64 View Code Duplication
            if (is_dir($cacheDir.'/profiler')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
                $finder = Finder::create()->in($cacheDir.'/profiler');
66
                $filesystem->remove($finder);
67
            }
68
            if (is_dir($cacheDir.'/twig')) {
69
                $finder = Finder::create()->in($cacheDir.'/twig');
70
                $filesystem->remove($finder);
71
            }
72 1
        }
73
74 4
        return true;
75 4
    }
76
}
77