RunCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 2
1
<?php
2
3
namespace MS\Sentry\Monitor\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Style\SymfonyStyle;
10
use Symfony\Component\Process\ProcessBuilder;
11
12
class RunCommand extends Command
13
{
14
    /**
15
     * @inheritdoc
16
     */
17
    protected function configure()
18
    {
19
        $this
20
            ->setName('run')
21
            ->setDescription('run sentry monitor server')
22
            ->addArgument('address', InputArgument::OPTIONAL, 'Address:port', 'localhost:8006')
23
        ;
24
    }
25
26
    /**
27
     * @param InputInterface  $input
28
     * @param OutputInterface $output
29
     *
30
     * @return void
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $io = new SymfonyStyle($input, $output);
35
        $io->title('Start and run sentry monitor');
36
37
        $address = $input->getArgument('address');
38
        $webPath = __DIR__ . '/../../web';
39
40
        $processBuilder = new ProcessBuilder([PHP_BINARY, '-S', $address, $webPath . '/index.php']);
41
        $processBuilder
42
            ->setWorkingDirectory($webPath . '/scripts')
43
            ->setTimeout(null);
44
45
        $io->success(sprintf('Server running on "%s"', $address));
46
        $io->comment('Quit the server with CONTROL-C.');
47
48
        $process = $processBuilder->getProcess();
49
        $process->run();
50
    }
51
}
52