Test Failed
Pull Request — master (#45)
by Chubarov
02:24
created

ServerRun::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt\Commands;
6
7
use FondBot\Toolbelt\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Process\PhpExecutableFinder;
10
use Symfony\Component\Process\ProcessUtils;
11
12
class ServerRun extends Command
13
{
14
    protected function configure(): void
15
    {
16
        $this
17
            ->setName('serve')
18
            ->setDescription('Run server')
19
            ->addOption('host', null, InputArgument::OPTIONAL, 'The host address to serve the application on.', '127.0.0.1')
20
            ->addOption('port', null, InputArgument::OPTIONAL, 'The port to serve the application on.', '8000');
21
    }
22
23
    /**
24
     * Get the port for the command.
25
     *
26
     * @return string
27
     */
28
    protected function port()
29
    {
30
        return $this->input->getOption('port');
31
    }
32
33
    /**
34
     * Get the host for the command.
35
     *
36
     * @return string
37
     */
38
    protected function host()
39
    {
40
        return $this->input->getOption('host');
41
    }
42
43
    /**
44
     * Get the full server command.
45
     *
46
     * @return string
47
     */
48
    protected function serverCommand() : string
49
    {
50
        return sprintf('%s -S %s:%s %s/public/index.php',
51
            ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)),
0 ignored issues
show
Security Bug introduced by
It seems like (new \Symfony\Component\...eFinder())->find(false) targeting Symfony\Component\Proces...xecutableFinder::find() can also be of type false; however, Symfony\Component\Proces...Utils::escapeArgument() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
Deprecated Code introduced by
The method Symfony\Component\Proces...Utils::escapeArgument() has been deprecated with message: since version 3.3, to be removed in 4.0. Use a command line array or give env vars to the `Process::start/run()` method instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
52
            $this->host(),
53
            $this->port(),
54
            ProcessUtils::escapeArgument(path())
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Proces...Utils::escapeArgument() has been deprecated with message: since version 3.3, to be removed in 4.0. Use a command line array or give env vars to the `Process::start/run()` method instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
55
        );
56
    }
57
58
    public function handle(): void
59
    {
60
        chdir(path());
61
        $this->line("<info>Fondbot development server started:</info> <http://{$this->host()}:{$this->port()}>");
62
        passthru($this->serverCommand());
63
    }
64
65
}
66