Completed
Pull Request — master (#28)
by Clayton
01:17
created

DumpServerCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 28 3
A share() 0 4 1
1
<?php
2
3
namespace BeyondCode\DumpServer;
4
5
use Illuminate\Console\Command;
6
7
use InvalidArgumentException;
8
use Symfony\Component\VarDumper\Cloner\Data;
9
use Symfony\Component\Console\Style\SymfonyStyle;
10
use Symfony\Component\VarDumper\Dumper\CliDumper;
11
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
12
use Symfony\Component\VarDumper\Server\DumpServer;
13
use Symfony\Component\VarDumper\Command\Descriptor\CliDescriptor;
14
use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor;
15
16
class DumpServerCommand extends Command
17
{
18
    /**
19
     * The console command name.
20
     *
21
     * @var string
22
     */
23
    protected $signature = 'dump-server {--format=cli : The output format (cli,html).}';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = 'Start the dump server to collect dump information.';
31
32
    /**
33
     * The Dump server.
34
     *
35
     * @var \Symfony\Component\VarDumper\Server\DumpServer
36
     */
37
    private $server;
38
39
    /**
40
     * DumpServerCommand constructor.
41
     *
42
     * @param  \Symfony\Component\VarDumper\Server\DumpServer  $server
43
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
44
     */
45
    public function __construct(DumpServer $server)
46
    {
47
        $this->server = $server;
48
49
        parent::__construct();
50
    }
51
52
    /**
53
     * Handle the command.
54
     *
55
     * @return void
56
     */
57
    public function handle()
58
    {
59
        switch ($format = $this->option('format')) {
60
            case 'cli':
61
                $descriptor = new CliDescriptor(new CliDumper);
62
                break;
63
            case 'html':
64
                $descriptor = new HtmlDescriptor(new HtmlDumper);
65
                break;
66
            default:
67
                throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $format));
68
        }
69
70
        $io = new SymfonyStyle($this->input, $this->output);
71
72
        $errorIo = $io->getErrorStyle();
73
        $errorIo->title('Laravel Var Dump Server');
74
75
        $this->server->start();
76
77
        $errorIo->success(sprintf('Server listening on %s', $this->server->getHost()));
78
        $errorIo->comment('Quit the server with CONTROL-C.');
79
80
        $this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) {
81
            $descriptor->describe($io, $data, $context, $clientId);
82
            $this->share($data, $context, $clientId);
83
        });
84
    }
85
86
    /**
87
     * Share the contents of the dump.
88
     *
89
     * @param  \Symfony\Component\VarDumper\Cloner\Data  $data
90
     * @param  array  $context
91
     * @param  int  $clientId
92
     *
93
     * @return void
94
     */
95
    protected function share(Data $data, array $context, int $clientId)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $clientId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
        //
98
    }
99
}
100