Completed
Push — master ( c5e2b8...ec08fd )
by Alberto
19s queued 12s
created

CacheClearallCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 11 3
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * BEdita, API-first content management framework
6
 * Copyright 2020 ChannelWeb Srl, Chialab Srl
7
 *
8
 * This file is part of BEdita: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published
10
 * by the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
14
 */
15
namespace BEdita\WebTools\Command;
16
17
use Cake\Command\CacheClearallCommand as BaseCommand;
18
use Cake\Console\Arguments;
19
use Cake\Console\ConsoleIo;
20
use Cake\Filesystem\Folder;
21
22
/**
23
 * Extend `CacheClearallCommand` to remove Twig compiled files.
24
 */
25
class CacheClearallCommand extends BaseCommand
26
{
27
    /**
28
     * Add `twig` compiled files removal step.
29
     *
30
     * {@inheritDoc}
31
     */
32
    public function execute(Arguments $args, ConsoleIo $io): ?int
33
    {
34
        $twigCachePath = CACHE . 'twigView';
35
        $folder = new Folder($twigCachePath);
36
        if (file_exists($twigCachePath) && !$folder->delete()) {
37
            $io->error("Error removing Twig cache files in {$twigCachePath}");
38
            $this->abort();
39
        }
40
        $io->out("<success>Cleared twig cache</success>");
41
42
        return parent::execute($args, $io);
43
    }
44
}
45