Failed Conditions
Push — master ( 746c21...bb3715 )
by Kentaro
35:35
created

CacheController::index()   B

Complexity

Conditions 6
Paths 2

Size

Total Lines 40
Code Lines 21

Duplication

Lines 5
Ratio 12.5 %

Code Coverage

Tests 6
CRAP Score 7.3329

Importance

Changes 0
Metric Value
dl 5
loc 40
ccs 6
cts 9
cp 0.6667
rs 8.439
c 0
b 0
f 0
cc 6
eloc 21
nc 2
nop 2
crap 7.3329
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
25
namespace Eccube\Controller\Admin\Content;
26
27
use Eccube\Application;
28
use Eccube\Controller\AbstractController;
29
use Symfony\Component\Filesystem\Filesystem;
30
use Symfony\Component\Finder\Finder;
31
use Symfony\Component\HttpFoundation\Request;
32
33
class CacheController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
34
{
35 2
36
    public function index(Application $app, Request $request)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
37
    {
38
39
        $builder = $app['form.factory']->createBuilder('admin_cache');
40
41
        $form = $builder->getForm();
42
43
        $form->handleRequest($request);
44
45
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
46 1
47 1
            $data = $form->get('cache')->getData();
48
49
            $cacheDir = $app['config']['root_dir'].'/app/cache';
50
51 1
            $filesystem = new Filesystem();
52
53
            foreach ($data as $dir) {
54 View Code Duplication
                if (is_dir($cacheDir.'/'.$dir)) {
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
                    // 指定されたキャッシュディレクトリを削除
56
                    $finder = Finder::create()->in($cacheDir.'/'.$dir);
57
                    $filesystem->remove($finder);
58 2
                }
59 2
                if ($dir == 'doctrine') {
60
                    // doctrineが指定された場合は, cache driver経由で削除.
61 2
                    $config =  $app['orm.em']->getConfiguration();
62
                    $this->deleteDoctrineCache($config->getMetadataCacheImpl());
63
                    $this->deleteDoctrineCache($config->getQueryCacheImpl());
64
                    $this->deleteDoctrineCache($config->getResultCacheImpl());
65
                    $this->deleteDoctrineCache($config->getHydrationCacheImpl());
66
                }
67
            }
68
69
            $app->addSuccess('admin.content.cache.save.complete', 'admin');
70
        }
71
72
        return $app->render('Content/cache.twig', array(
73
            'form' => $form->createView(),
74
        ));
75
    }
76
77
    protected function deleteDoctrineCache(\Doctrine\Common\Cache\Cache $cacheDriver)
78
    {
79
        $cacheDriver->deleteAll();
0 ignored issues
show
Bug introduced by
The method deleteAll() does not exist on Doctrine\Common\Cache\Cache. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
80
        $cacheDriver->flushAll();
81
    }
82
}
83