Passed
Pull Request — master (#9)
by Jakub
03:57
created

ComposerInstallCommand::targetDir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Zalas\Toolbox\Tool\Command;
4
5
use Zalas\Toolbox\Tool\Command;
6
7
final class ComposerInstallCommand implements Command
8
{
9
    private $repository;
10
    private $targetDir;
11
    private $version;
12
13 9
    public function __construct(string $repository, string $targetDir, ?string $version = null)
14
    {
15 9
        $this->repository = $repository;
16 9
        $this->targetDir = $targetDir;
17 9
        $this->version = $version;
18
    }
19
20 5
    public function __toString(): string
21
    {
22 5
        return \sprintf(
23 5
            'git clone %s %s && cd %s && git checkout %s && composer install --no-dev --no-suggest --prefer-dist -n',
24 5
            $this->repository,
25 5
            $this->targetDir,
26 5
            $this->targetDir,
27 5
            $this->version ?? '$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null)'
28
        );
29
    }
30
}
31