Completed
Pull Request — master (#4)
by Jakub
03:36
created

ComposerInstallCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 7 1
A __construct() 0 4 1
A targetDir() 0 5 2
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 $version;
11
12 9
    public function __construct(string $repository, ?string $version = null)
13
    {
14 9
        $this->repository = $repository;
15 9
        $this->version = $version;
16
    }
17
18 5
    public function __toString(): string
19
    {
20 5
        return \sprintf(
21 5
            'cd /tools && git clone %s && cd /tools/%s && git checkout %s && composer install --no-dev --no-suggest --prefer-dist -n',
22 5
            $this->repository,
23 5
            $this->targetDir(),
24 5
            $this->version ?? '$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null)'
25
        );
26
    }
27
28 5
    private function targetDir(): string
29
    {
30 5
        $targetDir = \preg_replace('#^.*/(.*?)(.git)?$#', '$1', $this->repository);
31
32 5
        return  $targetDir !== $this->repository ? $targetDir : 'tmp';
33
    }
34
}
35