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

BoxBuildCommand::import()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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