Passed
Push — master ( f8a196...66e67e )
by Evgenii
01:52
created

CliSubcommand::hasUrlOption()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Helick\LocalServer\Subcommands;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
final class CliSubcommand extends Subcommand
9
{
10
    /**
11
     * The process' command string.
12
     *
13
     * @var string
14
     */
15
    const COMMAND = 'docker-compose exec -T -u nobody php vendor/bin/wp %s';
16
17
    /**
18
     * Invoke the subcommand.
19
     *
20
     * @param InputInterface  $input
21
     * @param OutputInterface $output
22
     *
23
     * @return void
24
     */
25
    public function __invoke(InputInterface $input, OutputInterface $output): void
26
    {
27
        $options = $input->getArgument('options');
28
29
        if (!$this->hasUrlOption($options)) {
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type null and string; however, parameter $options of Helick\LocalServer\Subco...command::hasUrlOption() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
        if (!$this->hasUrlOption(/** @scrutinizer ignore-type */ $options)) {
Loading history...
30
            $options[] = sprintf('--url=http://%s.localtest.me/', basename(getcwd()));
31
        }
32
33
        $this->runProcess(sprintf(static::COMMAND, implode(' ', $options)));
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type null and string; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        $this->runProcess(sprintf(static::COMMAND, implode(' ', /** @scrutinizer ignore-type */ $options)));
Loading history...
34
    }
35
36
    /**
37
     * @param array $options
38
     *
39
     * @return bool
40
     */
41
    protected function hasUrlOption(array $options): bool
42
    {
43
        foreach ($options as $option) {
44
            if (strpos($option, '--url=') === 0) {
45
                return true;
46
            }
47
        }
48
49
        return false;
50
    }
51
}
52