Passed
Push — feature/uploadable ( 7c6d25...a7ed20 )
by Daniel
11:07
created

FormCachePurgeCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 37
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 9 1
A __construct() 0 8 1
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\Form\Cache\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
    public function __construct(
33
        FormCachePurger $formCachePurger,
34
        EventDispatcherInterface $dispatcher,
35
        ?string $name = null
36
    ) {
37
        $this->formCachePurger = $formCachePurger;
38
        $this->dispatcher = $dispatcher;
39
        parent::__construct($name);
40
    }
41
42
    /**
43
     * @throws InvalidArgumentException
44
     */
45
    protected function configure(): void
46
    {
47
        $this
48
            ->setName('silverback:api-components:form-cache-purge')
49
            ->setDescription('Purges the varnish cache for forms. Sets the `modified` timestamp to the file last modified date');
50
    }
51
52
    /**
53
     * @return int|void|null
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $this->dispatcher->addListener(
58
            CommandLogEvent::class,
59
            static function (CommandLogEvent $event) use ($output) {
60
                $output->writeln($event->getSubject());
61
            }
62
        );
63
        $this->formCachePurger->clear();
64
    }
65
}
66