Passed
Push — main ( ac9fbe...3d521c )
by Daniel
04:51
created

FormCachePurgeCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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\Attribute\AsCommand;
19
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
#[AsCommand(name: 'silverback:api-components:form-cache-purge', description: 'Purges the varnish cache for forms. Sets the `modified` timestamp to the file last modified date')]
28
class FormCachePurgeCommand extends Command
29
{
30
    private FormCachePurger $formCachePurger;
31
    private EventDispatcherInterface $dispatcher;
32
33
    public function __construct(FormCachePurger $formCachePurger, EventDispatcherInterface $dispatcher)
34
    {
35
        parent::__construct();
36
        $this->formCachePurger = $formCachePurger;
37
        $this->dispatcher = $dispatcher;
38
    }
39
40
    /**
41
     * @return int|void|null
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output): int
44
    {
45
        $this->dispatcher->addListener(
46
            CommandLogEvent::class,
47
            static function (CommandLogEvent $event) use ($output) {
48
                $output->writeln($event->getSubject());
49
            }
50
        );
51
        $this->formCachePurger->clear();
52
        $output->writeln('Form cache purge complete');
53
54
        return 0;
55
    }
56
}
57