StoreCommand::executeInner()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 18
ccs 12
cts 12
cp 1
crap 1
rs 9.9
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