BoxBuildCommand::targetDir()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

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