GetCommand::executeInner()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 23
ccs 14
cts 14
cp 1
crap 3
rs 9.8333
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