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

BoxBuildCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 34
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 11 1
A __construct() 0 6 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 BoxBuildCommand implements Command
8
{
9
    private $repository;
10
    private $phar;
11
    private $bin;
12
    private $version;
13
    
14 10
    public function __construct(string $repository, string $phar, string $bin, ?string $version = null)
15
    {
16 10
        $this->repository = $repository;
17 10
        $this->phar = $phar;
18 10
        $this->bin = $bin;
19 10
        $this->version = $version;
20
    }
21
22 5
    public function __toString(): string
23
    {
24 5
        return \sprintf(
25 5
            'cd /tools && git clone %s && cd /tools/%s && git checkout %s && composer install --no-dev --no-suggest --prefer-dist -n && box build && mv %s %s && chmod +x %s && cd && rm -rf /tools/%s',
26 5
            $this->repository,
27 5
            $this->targetDir(),
28 5
            $this->version ?? '$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null)',
29 5
            $this->phar,
30 5
            $this->bin,
31 5
            $this->bin,
32 5
            $this->targetDir()
33
        );
34
    }
35
36 5
    private function targetDir(): string
37
    {
38 5
        $targetDir = \preg_replace('#^.*/(.*?)(.git)?$#', '$1', $this->repository);
39
40 5
        return  $targetDir !== $this->repository ? $targetDir : 'tmp';
41
    }
42
}
43