SetCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A __construct() 0 4 1
A execute() 0 3 1
A set() 0 5 1
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
10
/**
11
 * Description of SetCommand.
12
 *
13
 * @author dude920228
14
 */
15
class SetCommand extends Command
16
{
17
    private $serviceManager;
18
19
    public function __construct($config, $name = null)
20
    {
21
        parent::__construct($name);
22
        $this->serviceManager = new ServiceManager($config);
23
    }
24
25
    protected function configure()
26
    {
27
        $this->setName('set');
28
        $this->setHelp('This command allows you to create entries in the cache pool');
29
        $this->addArgument('key', InputArgument::REQUIRED, 'The key assigned to the cache entry');
30
        $this->addArgument('value', InputArgument::REQUIRED, 'The value of the cache entry');
31
    }
32
33
    protected function execute($input, $output)
34
    {
35
        $this->set($input);
36
    }
37
38
    private function set($input)
39
    {
40
        /* @var $client CacheClient */
41
        $client = $this->serviceManager->get(CacheClient::class);
42
        $client->set($input->getArgument('key'), $input->getArgument('value'));
43
    }
44
}
45