GetCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 36
ccs 19
cts 19
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A executeInner() 0 23 3
A configure() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Interfaces\Console;
6
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Style\SymfonyStyle;
11
12
class GetCommand extends AbstractObjectStoreCommand
13
{
14
    protected static $defaultName = 'app:object-store:get';
15
16 3
    protected function configure(): void
17
    {
18
        $this
19 3
            ->setDescription('Gets a value from the ObjectStore')
20 3
            ->addArgument('key', InputArgument::REQUIRED, 'Object key')
21 3
            ->addOption('timestamp', 't', InputOption::VALUE_REQUIRED, 'Timestamp to get the value')
22
        ;
23 3
    }
24
25 3
    public function executeInner(SymfonyStyle $io, InputInterface $input): int
26
    {
27 3
        $key = $input->getArgument('key');
28 3
        $timestamp = $input->getOption('timestamp');
29 3
        $time = \DateTime::createFromFormat('U', (string) $timestamp) ?: new \DateTime();
30
31 3
        $entry = $this->objectStore->get($key, $time);
32
33 3
        $io->title('Object store');
34
35 3
        if (!$entry) {
36 2
            $io->error('Object not found!');
37
38 2
            return  1;
39
        }
40
41 2
        $io->horizontalTable(['Key', 'Value', 'Timestamp'], [[
42 2
            $entry->getKey(),
43 2
            json_encode($entry->getValue()),
44 2
            $time->getTimestamp(),
45
        ]]);
46
47 2
        return 0;
48
    }
49
}
50