StoreCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 31
ccs 17
cts 17
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A executeInner() 0 18 1
A configure() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Interfaces\Console;
6
7
use App\Domain\Model\ObjectEntry;
8
use DateTime;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13
class StoreCommand extends AbstractObjectStoreCommand
14
{
15
    protected static $defaultName = 'app:object-store:store';
16
17 2
    protected function configure(): void
18
    {
19
        $this
20 2
            ->setDescription('Stores a value in the ObjectStore')
21 2
            ->addArgument('key', InputArgument::REQUIRED, 'Object key')
22 2
            ->addArgument('value', InputArgument::REQUIRED, 'JSON-encoded value to store')
23
        ;
24 2
    }
25
26 2
    public function executeInner(SymfonyStyle $io, InputInterface $input): int
27
    {
28 2
        $entry = new ObjectEntry(
29 2
            $input->getArgument('key'),
30 2
            json_decode($input->getArgument('value'))
31
        );
32 2
        $time = new DateTime();
33
34 2
        $this->objectStore->store($entry, $time);
35
36 2
        $io->horizontalTable(['Key', 'Value', 'Timestamp'], [[
37 2
            $entry->getKey(),
38 2
            json_encode($entry->getValue()),
39 2
            $time->getTimestamp(),
40
        ]]);
41 2
        $io->success('Value stored successfully');
42
43 2
        return 0;
44
    }
45
}
46