Test Failed
Push — develop ( 88c868...a2aeae )
by Daniel
12:27
created

FormCacheClear::updateFormTimestamp()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 2
nop 1
dl 0
loc 12
ccs 10
cts 10
cp 1
crap 3
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Command;
4
5
use Silverback\ApiComponentBundle\Cache\FormCacheClearer;
6
use Silverback\ApiComponentBundle\Event\CommandNotifyEvent;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11
12
class FormCacheClear extends Command
13
{
14
    private $cacheClearer;
15
    private $dispatcher;
16
17
    public function __construct(
18
        FormCacheClearer $cacheClearer,
19
        EventDispatcherInterface $dispatcher,
20
        ?string $name = null
21
    ) {
22
        $this->cacheClearer = $cacheClearer;
23 1
        $this->dispatcher = $dispatcher;
24
        parent::__construct($name);
25
    }
26
27 1
    /**
28 1
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
29 1
     */
30
    protected function configure(): void
31
    {
32
        $this
33
            ->setName('api_component_bundle:form:clear_cache')
34 1
            ->setDescription('Purges the varnish cache for forms where files have been updated')
35
        ;
36
    }
37 1
38 1
    /**
39
     * @param InputInterface $input
40 1
     * @param OutputInterface $output
41
     * @return int|null|void
42
     * @throws \ReflectionException
43
     */
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        $this->dispatcher->addListener(FormCacheClearer::FORM_CACHE_EVENT_NAME, function (CommandNotifyEvent $event) use ($output) {
47
            $output->writeln($event->getSubject());
48 1
        });
49
        $this->cacheClearer->clear();
50 1
    }
51
}
52