Completed
Push — v2 ( 418ab2...1227a6 )
by Daniel
05:04 queued 01:11
created

FormCachePurgeCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 39
ccs 0
cts 15
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A configure() 0 5 1
A execute() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\Command;
6
7
use Silverback\ApiComponentBundle\ApiComponentBundleEvents;
8
use Silverback\ApiComponentBundle\Event\CommandLogEvent;
9
use Silverback\ApiComponentBundle\Form\Cache\FormCachePurger;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Exception\InvalidArgumentException;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15
16
class FormCachePurgeCommand extends Command
17
{
18
    private FormCachePurger $formCachePurger;
19
    private EventDispatcherInterface $dispatcher;
20
21
    public function __construct(
22
        FormCachePurger $formCachePurger,
23
        EventDispatcherInterface $dispatcher,
24
        ?string $name = null
25
    ) {
26
        $this->formCachePurger = $formCachePurger;
27
        $this->dispatcher = $dispatcher;
28
        parent::__construct($name);
29
    }
30
31
    /**
32
     * @throws InvalidArgumentException
33
     */
34
    protected function configure(): void
35
    {
36
        $this
37
            ->setName('silverback:api-component:form-cache-purge')
38
            ->setDescription('Purges the varnish cache for forms. Sets the `modified` timestamp to the file last modified date');
39
    }
40
41
    /**
42
     * @param InputInterface $input
43
     * @param OutputInterface $output
44
     * @return int|null|void
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        $this->dispatcher->addListener(
49
            ApiComponentBundleEvents::COMMAND_LOG,
50
            static function (CommandLogEvent $event) use ($output) {
51
                $output->writeln($event->getSubject());
52
            }
53
        );
54
        $this->formCachePurger->clear();
55
    }
56
}
57