Passed
Branch master (7b18cd)
by Jakub
03:40
created

ComposerInstallCommand::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 1
rs 10
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 10
    public function __construct(string $repository, string $targetDir, ?string $version = null)
14
    {
15 10
        $this->repository = $repository;
16 10
        $this->targetDir = $targetDir;
17 10
        $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