Passed
Push — main ( f5d7d4...b3268f )
by
unknown
05:10 queued 02:13
created

GetClusterNodesCommand::handle()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Padosoft\SuperCache\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\Log;
7
use Padosoft\SuperCache\RedisConnector;
8
use Padosoft\SuperCache\Service\GetClusterNodesService;
9
10
class GetClusterNodesCommand extends Command
11
{
12
    protected $signature = 'supercache:get-cluster-nodes
13
                                {--connection_name= : (opzionale) nome della connessione redis }
14
                                ';
15
    protected $description = 'Comando per ottenere i nodi del cluster sulla connessione specificata';
16
    protected RedisConnector $redis;
17
    protected GetClusterNodesService $service;
18
19
    public function __construct(RedisConnector $redis, GetClusterNodesService $service)
20
    {
21
        parent::__construct();
22
        $this->redis = $redis;
23
        $this->service = $service;
24
    }
25
26
    /**
27
     * @throws \JsonException
28
     */
29
    public function handle(): void
30
    {
31
        try {
32
            $array_nodi = $this->service->getClusterNodes($this->option('connection_name'));
33
            $this->output->writeln(json_encode($array_nodi, JSON_THROW_ON_ERROR));
34
        } catch (\Throwable $e) {
35
            Log::error('Errore durante il recupero dei nodi del cluster ' . $e->getMessage());
36
            $this->output->writeln(json_encode([], JSON_THROW_ON_ERROR));
37
        }
38
    }
39
}
40