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

GetClusterNodesCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 2
A __construct() 0 5 1
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