Completed
Pull Request — master (#15)
by Stefano
02:47
created

CacheClearallCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

1 Method

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