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

ComposerInstallCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 10
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 $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