Passed
Push — master ( 8a455a...42a228 )
by Craig
07:01
created

CacheHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 44
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A clearCaches() 0 14 2
A __construct() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula Foundation - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\Bundle\CoreInstallerBundle\Helper;
15
16
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
17
use Zikula\Bundle\CoreBundle\CacheClearer;
18
19
class CacheHelper
20
{
21
    /**
22
     * @var CacheClearer
23
     */
24
    private $zikulaCacheClearer;
25
26
    /**
27
     * @var CacheClearerInterface
28
     */
29
    private $symfonyCacheClearer;
30
31
    /**
32
     * @var string
33
     */
34
    private $env;
35
36
    /**
37
     * CacheHelper constructor.
38
     */
39
    public function __construct(
40
        CacheClearer $zikulaCacheClearer,
41
        CacheClearerInterface $symfonyCacheClearer,
42
        string $env
43
    ) {
44
        $this->zikulaCacheClearer = $zikulaCacheClearer;
45
        $this->symfonyCacheClearer = $symfonyCacheClearer;
46
        $this->env = $env;
47
    }
48
49
    public function clearCaches(): bool
50
    {
51
        // clear cache with zikula's method
52
        $this->zikulaCacheClearer->clear('symfony');
53
        // use full symfony cache_clearer not zikula's to clear entire cache and set for warmup
54
        // console commands always run in `dev` mode but site should be `prod` mode. clear both for good measure.
55
        $this->symfonyCacheClearer->clear('dev');
56
        $this->symfonyCacheClearer->clear('prod');
57
        if (!in_array($this->env, ['dev', 'prod'])) {
58
            // this is just in case anyone ever creates a mode that isn't dev|prod
59
            $this->symfonyCacheClearer->clear($this->env);
60
        }
61
62
        return true;
63
    }
64
}
65