PurgeAsyncTagsCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A execute() 0 11 2
A configure() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace IntegerNet\AsyncVarnish\Console\Command;
5
6
use IntegerNet\AsyncVarnish\Model\PurgeAsyncCache as Purger;
7
use Magento\Framework\App\State;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class PurgeAsyncTagsCommand extends \Symfony\Component\Console\Command\Command
12
{
13
    /**
14
     * @var State
15
     */
16
    private $appState;
17
18
    /**
19
     * @var Purger
20
     */
21
    private $purger;
22
23
    public function __construct(
24
        State $appState,
25
        Purger $purger,
26
        ?string $name = null
27
    ) {
28
        $this->appState = $appState;
29
        $this->purger = $purger;
30
        parent::__construct($name);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function configure()
37
    {
38
        $this->setName('integernet:asyncvarnish:purge')
39
            ->setDescription('Purges Varnish Tags currently stored in database table');
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        try {
48
            $this->appState->setAreaCode('adminhtml');
49
            $successQty = $this->purger->run();
50
51
            $output->setDecorated(true);
52
            $output->writeln('<info>' . sprintf('%s records purged from cache', $successQty) . '</info>');
53
        } catch (\Exception $e) {
54
            $output->setDecorated(true);
55
            $output->writeln('<error>' . $e->getMessage() . '</error>');
56
        }
57
    }
58
}
59