PhiveInstallCommand::__toString()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
ccs 11
cts 11
cp 1
crap 2
rs 9.9332
1
<?php declare(strict_types=1);
2
3
namespace Zalas\Toolbox\Tool\Command;
4
5
use Zalas\Toolbox\Tool\Command;
6
7
final class PhiveInstallCommand implements Command
8
{
9
    private string $alias;
10
    private string $bin;
11
    private ?string $sig;
12
13 7
    public function __construct(string $alias, string $bin, ?string $sig = null)
14
    {
15 7
        $this->alias = $alias;
16 7
        $this->bin = $bin;
17 7
        $this->sig = $sig;
18
    }
19
20 5
    public function __toString(): string
21
    {
22 5
        $home = \sprintf('%s/.phive', \dirname($this->bin));
23 5
        $tmp = \sprintf('%s/tmp/%s', $home, \md5($this->alias));
24
25 5
        return \sprintf(
26 5
            'phive --no-progress --home %s install %s %s -t %s && mv %s/* %s',
27 5
            $home,
28 5
            $this->sig ? '--trust-gpg-keys '.$this->sig : '--force-accept-unsigned',
29 5
            $this->alias,
30 5
            $tmp,
31 5
            $tmp,
32 5
            $this->bin
33 5
        );
34
    }
35
}
36