ComposerInstallCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
eloc 13
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 8 1
A __construct() 0 5 1
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 string $repository;
10
    private string $targetDir;
11
    private ?string $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 --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 5
        );
29
    }
30
}
31