Test Failed
Branch feature__set_up_scrutinizer (ea6624)
by Robin
06:04 queued 02:46
created

CliCommandFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace App\Support\Console\DockerCompose;
4
5
use App\Models\Site;
6
use App\Support\Contracts\Cli;
7
8
class CliCommandFactory
9
{
10
    /**
11
     * @var Cli
12
     */
13
    protected $cli;
14
15 50
    public function __construct(Cli $cli)
16
    {
17 50
        $this->cli = $cli;
18 50
    }
19
20
    /**
21
     * Create a Docker CLI command.
22
     *
23
     * @param string $command
24
     * @return CliCommand
25
     */
26 10
    public function command($command)
27
    {
28 10
        return new CliCommand($this->cli, $command);
29
    }
30
31
    /**
32
     * Construct a docker-compose exec {$container} command
33
     *
34
     * @param string|null $container
35
     * @return CliCommand
36
     */
37
    public function execContainer($container = null)
38
    {
39
        return new CliCommand($this->cli, "exec {$container}");
40
    }
41
42
    /**
43
     * Construct a docker-compose run {$container} command
44
     *
45
     * @param string|null $container
46
     * @return CliCommand
47
     */
48
    public function runContainer($container = null)
49
    {
50
        $site = Site::resolveFromPathOrCurrentWorkingDirectory();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $site is correct as App\Models\Site::resolve...rrentWorkingDirectory() targeting App\Models\Site::resolve...rrentWorkingDirectory() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
51
        $workingDir = $site ? '-w /srv/app/' . $site->name : '';
0 ignored issues
show
introduced by
$site is of type null, thus it always evaluated to false.
Loading history...
52
53
        return new CliCommand($this->cli, "run {$workingDir} --rm {$container}");
54
    }
55
}
56