FlushCache   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A define() 0 4 1
A doExecute() 0 7 2
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Console\Commands\Assets;
6
7
use AbterPhp\Framework\Assets\CacheManager\ICacheManager;
8
use Opulence\Console\Commands\Command;
9
use Opulence\Console\Responses\IResponse;
10
11
class FlushCache extends Command
12
{
13
    public const NAME = 'assets:flushcache';
14
15
    protected ICacheManager $cacheManager;
16
17
    /**
18
     * FlushCacheCommand constructor.
19
     *
20
     * @param ICacheManager $cacheManager
21
     */
22
    public function __construct(ICacheManager $cacheManager)
23
    {
24
        $this->cacheManager = $cacheManager;
25
26
        parent::__construct();
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    protected function define(): void
33
    {
34
        $this->setName(static::NAME)
35
            ->setDescription('Flushes assets cache')
36
        ;
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    protected function doExecute(IResponse $response): void
43
    {
44
        try {
45
            $this->cacheManager->flush();
46
            $response->writeln('<info>Assets are flushed</info>');
47
        } catch (\Exception $e) {
48
            $response->writeln(sprintf('<fatal>%s</fatal>', $e->getMessage()));
49
        }
50
    }
51
}
52