Passed
Push — master ( def3b9...9746d2 )
by Daniel
06:04
created

FormCachePurgeCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\Command;
15
16
use Silverback\ApiComponentsBundle\Event\CommandLogEvent;
17
use Silverback\ApiComponentsBundle\Helper\Form\FormCachePurger;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Exception\InvalidArgumentException;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
23
24
/**
25
 * @author Daniel West <[email protected]>
26
 */
27
class FormCachePurgeCommand extends Command
28
{
29
    private FormCachePurger $formCachePurger;
30
    private EventDispatcherInterface $dispatcher;
31
32 7
    public function __construct(FormCachePurger $formCachePurger, EventDispatcherInterface $dispatcher, ?string $name = null)
33
    {
34 7
        $this->formCachePurger = $formCachePurger;
35 7
        $this->dispatcher = $dispatcher;
36 7
        parent::__construct($name);
37 7
    }
38
39
    /**
40
     * @throws InvalidArgumentException
41
     */
42 7
    protected function configure(): void
43
    {
44
        $this
45 7
            ->setName('silverback:api-components:form-cache-purge')
46 7
            ->setDescription('Purges the varnish cache for forms. Sets the `modified` timestamp to the file last modified date');
47 7
    }
48
49
    /**
50
     * @return int|void|null
51
     */
52 2
    protected function execute(InputInterface $input, OutputInterface $output): int
53
    {
54
        $this->dispatcher->addListener(CommandLogEvent::class, static function (CommandLogEvent $event) use ($output) {
55 2
            $output->writeln($event->getSubject());
56 2
        });
57 2
        $this->formCachePurger->clear();
58 2
        $output->writeln('Form cache purge complete');
59
60 2
        return 0;
61
    }
62
}
63