BoxBuildCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 37
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

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