AbstractPurgeCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 38
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A passStoreViewIfSet() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * File: AbstractPurgeCommand.php
7
 *
8
 * @author Maciej Sławik <[email protected]>
9
 * @copyright Copyright (C) 2019 Lizard Media (http://lizardmedia.pl)
10
 */
11
12
namespace LizardMedia\VarnishWarmer\Console\Command;
13
14
use LizardMedia\VarnishWarmer\Api\VarnishActionManagerInterface;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
18
/**
19
 * Class AbstractPurgeCommand
20
 * @package LizardMedia\VarnishWarmer\Console\Command
21
 */
22
class AbstractPurgeCommand extends Command
23
{
24
    /**
25
     * @var string
26
     */
27
    protected const STORE_VIEW_ID = 'store';
28
29
    /**
30
     * @var VarnishActionManagerInterface
31
     */
32
    protected $varnishActionManager;
33
34
    /**
35
     * AbstractPurgeCommand constructor.
36
     * @param VarnishActionManagerInterface $varnishActionManager
37
     * @param null $name
38
     */
39
    public function __construct(
40
        VarnishActionManagerInterface $varnishActionManager,
41
        $name = null
42
    ) {
43
        parent::__construct($name);
44
        $this->varnishActionManager = $varnishActionManager;
45
    }
46
47
    /**
48
     * @param InputInterface $input
49
     * @return void
50
     */
51
    protected function passStoreViewIfSet(InputInterface $input): void
52
    {
53
        $storeViewId = $input->getOption(self::STORE_VIEW_ID);
54
55
        if (!empty($storeViewId)) {
56
            $this->varnishActionManager->setStoreViewId((int) $storeViewId);
57
        }
58
    }
59
}
60