Completed
Push — master ( d7cb5b...31c113 )
by Nikita
11:15
created

RebuildInternalCacheSubscriber   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 33
loc 33
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 8 8 1
A rebuildInternalCache() 15 15 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Taisiya\CoreBundle\Event;
4
5
use Symfony\Component\Console\Input\ArrayInput;
6
use Symfony\Component\Console\Output\ConsoleOutput;
7
use Taisiya\CoreBundle\Console\Command\Cache\RebuildInternalCacheCommand;
8
use Taisiya\CoreBundle\Event\Composer\CommandEvent;
9
10 View Code Duplication
class RebuildInternalCacheSubscriber implements EventSubscriberInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public static function getSubscribedEvents()
16
    {
17
        return [
18
            CommandEvent::NAME => [
19
                ['rebuildInternalCache', -1000],
20
            ],
21
        ];
22
    }
23
24
    /**
25
     * @param CommandEvent $event
26
     */
27
    public function rebuildInternalCache(CommandEvent $event): void
28
    {
29
        /** @var ConsoleOutput $output */
30
        $output = $event->getApp()->getContainer()['console.output'];
31
32
        if ($output->isVerbose()) {
33
            $str = 'Run '.RebuildInternalCacheCommand::NAME.' command';
34
            $output->writeln('');
35
            $output->writeln($str);
36
            $output->writeln(str_repeat('-', strlen($str)));
37
        }
38
39
        $input = new ArrayInput([RebuildInternalCacheCommand::NAME]);
40
        $event->getApp()->getConsole()->doRun($input, $output);
41
    }
42
}
43