DeleteCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpCache\Commands;
4
5
use PhpCache\CacheClient\CacheClient;
6
use PhpCache\ServiceManager\ServiceManager;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Description of PhpCache.
14
 *
15
 * @author dude920228
16
 */
17
class DeleteCommand extends Command
18
{
19
    private $serviceManager;
20
21
    public function __construct($config, $name = null)
22
    {
23
        parent::__construct($name);
24
        $this->serviceManager = new ServiceManager($config);
25
    }
26
27
    protected function configure()
28
    {
29
        $this->setName('delete');
30
        $this->setHelp('This command allows you to delete entries from the cache pool by key');
31
        $this->addArgument('key', InputArgument::REQUIRED, 'Key for the cache entry to be deleted');
32
    }
33
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $this->deleteEntry($input);
37
    }
38
39
    private function deleteEntry(InputInterface $input)
40
    {
41
        $key = $input->getArgument('key');
42
        /* @var $client CacheClient */
43
        $client = $this->serviceManager->get(CacheClient::class);
44
        $client->delete($key);
45
    }
46
}
47