Failed Conditions
Push — experimental/3.1 ( ea436b...26b8cd )
by chihiro
244:59 queued 239:01
created

CacheUtil   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 63
Duplicated Lines 34.92 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 22
loc 63
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
D clear() 22 48 11

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Eccube\Application;
27
use Symfony\Component\Filesystem\Filesystem;
28
use Symfony\Component\Finder\Finder;
29
30
/**
31
 * キャッシュ関連のユーティリティクラス.
32
 */
33
class CacheUtil
34
{
35
36
    /**
37
     * キャッシュを削除する.
38
     *
39
     * doctrine, profiler, twig によって生成されたキャッシュディレクトリを削除する.
40
     * キャッシュは $app['config']['root_dir'].'/app/cache' に生成されます.
41
     *
42
     * @param Application $app
43
     * @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...
44
     * @param boolean $isTwig Twigキャッシュファイルのみ削除する場合 true
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
45
     * @return boolean 削除に成功した場合 true
46
     */
47
    public static function clear($app, $isAll, $isTwig = false)
48
    {
49
        $cacheDir = $app['config']['root_dir'].'/app/cache';
50
51
        $filesystem = new Filesystem();
52
        $finder = Finder::create()->notName('.gitkeep')->files();
53
        if ($isAll) {
54
            $finder = $finder->in($cacheDir);
55
            $filesystem->remove($finder);
56 View Code Duplication
        } elseif ($isTwig) {
57
            if (is_dir($cacheDir.'/twig')) {
58
                $finder = $finder->in($cacheDir.'/twig');
59
                $filesystem->remove($finder);
60
            }
61
        } else {
62 View Code Duplication
            if (is_dir($cacheDir.'/doctrine')) {
63
                $finder = $finder->in($cacheDir.'/doctrine');
64
                $filesystem->remove($finder);
65
            }
66 View Code Duplication
            if (is_dir($cacheDir.'/profiler')) {
67
                $finder = $finder->in($cacheDir.'/profiler');
68
                $filesystem->remove($finder);
69
            }
70 View Code Duplication
            if (is_dir($cacheDir.'/twig')) {
71
                $finder = $finder->in($cacheDir.'/twig');
72
                $filesystem->remove($finder);
73
            }
74 View Code Duplication
            if (is_dir($cacheDir.'/translator')) {
75
                $finder = $finder->in($cacheDir.'/translator');
76
                $filesystem->remove($finder);
77
            }
78
        }
79
80
        if (function_exists('opcache_reset')) {
81
            opcache_reset();
82
        }
83
84
        if (function_exists('apc_clear_cache')) {
85
            apc_clear_cache('user');
86
            apc_clear_cache();
87
        }
88
89
        if (function_exists('wincache_ucache_clear')) {
90
            wincache_ucache_clear();
91
        }
92
93
        return true;
94
    }
95
}
96