DumpServerCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 2
Metric Value
eloc 23
c 5
b 0
f 2
dl 0
loc 66
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 25 3
1
<?php
2
3
namespace BeyondCode\DumpServer;
4
5
use Illuminate\Console\Command;
6
use InvalidArgumentException;
7
use Symfony\Component\VarDumper\Cloner\Data;
8
use Symfony\Component\Console\Style\SymfonyStyle;
9
use Symfony\Component\VarDumper\Dumper\CliDumper;
10
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
11
use Symfony\Component\VarDumper\Server\DumpServer;
12
use Symfony\Component\VarDumper\Command\Descriptor\CliDescriptor;
13
use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor;
14
15
class DumpServerCommand extends Command
16
{
17
    /**
18
     * The console command name.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'dump-server {--format=cli : The output format (cli,html).}';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Start the dump server to collect dump information.';
30
31
    /**
32
     * The Dump server.
33
     *
34
     * @var \Symfony\Component\VarDumper\Server\DumpServer
35
     */
36
    protected $server;
37
38
    /**
39
     * DumpServerCommand constructor.
40
     *
41
     * @param  \Symfony\Component\VarDumper\Server\DumpServer  $server
42
     * @return void
43
     */
44
    public function __construct(DumpServer $server)
45
    {
46
        $this->server = $server;
47
48
        parent::__construct();
49
    }
50
51
    /**
52
     * Handle the command.
53
     *
54
     * @return void
55
     */
56
    public function handle()
57
    {
58
        switch ($format = $this->option('format')) {
59
            case 'cli':
60
                $descriptor = new CliDescriptor(new CliDumper);
61
                break;
62
            case 'html':
63
                $descriptor = new HtmlDescriptor(new HtmlDumper);
64
                break;
65
            default:
66
                throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $format));
67
        }
68
69
        $io = new SymfonyStyle($this->input, $this->output);
70
71
        $errorIo = $io->getErrorStyle();
72
        $errorIo->title('Laravel Var Dump Server');
73
74
        $this->server->start();
75
76
        $errorIo->success(sprintf('Server listening on %s', $this->server->getHost()));
77
        $errorIo->comment('Quit the server with CONTROL-C.');
78
79
        $this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) {
80
            $descriptor->describe($io, $data, $context, $clientId);
81
        });
82
    }
83
}
84