ClearCacheCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 4
dl 0
loc 52
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A __construct() 0 7 1
A execute() 0 13 1
1
<?php
2
3
namespace BrainExe\Core\Console;
4
5
use BrainExe\Core\DependencyInjection\Rebuild;
6
use BrainExe\Core\EventDispatcher\EventDispatcher;
7
use BrainExe\Core\EventDispatcher\Events\ClearCacheEvent;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use BrainExe\Core\Annotations\Command as CommandAnnotation;
12
13
/**
14
 * @CommandAnnotation
15
 */
16
class ClearCacheCommand extends Command
17
{
18
19
    /**
20
     * @var Rebuild
21
     */
22
    private $rebuild;
23
24
    /**
25
     * @var EventDispatcher
26
     */
27
    private $dispatcher;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 2
    protected function configure()
33
    {
34 2
        $this->setName('cache:clear')
35 2
            ->setDescription('Clears the local cache')
36 2
            ->setAliases(['cc']);
37 2
    }
38
39
    /**
40
     * @param Rebuild $rebuild
41
     * @param EventDispatcher $dispatcher
42
     */
43 2
    public function __construct(Rebuild $rebuild, EventDispatcher $dispatcher)
44
    {
45 2
        parent::__construct();
46
47 2
        $this->rebuild    = $rebuild;
48 2
        $this->dispatcher = $dispatcher;
49 2
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56 1
        $output->write('Rebuild DIC...');
57 1
        $this->rebuild->buildContainer();
58
59 1
        $event = new ClearCacheEvent();
60 1
        $this->dispatcher->dispatchEvent($event);
61
62 1
        @mkdir(ROOT . 'logs', 0744);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
63 1
        @mkdir(ROOT . 'cache', 0744);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
64
65 1
        $output->writeln('<info>done</info>');
66 1
    }
67
}
68