Passed
Pull Request — master (#32)
by
unknown
02:23
created

Docker::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace CaptainHook\App\Hook\Template;
5
6
use CaptainHook\App\Hook\Template;
7
use CaptainHook\App\Hook\Util as HookUtil;
8
9
class Docker implements Template
10
{
11
    /**
12
     * @var string
13
     */
14
    private $binaryPath;
15
    /**
16
     * @var string
17
     */
18
    private $containerName;
19
20 2
    public function __construct(string $repoPath, string $vendorPath, string $containerName)
21
    {
22 2
        $this->binaryPath = HookUtil::getBinaryPath($repoPath, $vendorPath, 'captainhook-run');
23 2
        $this->containerName = $containerName;
24 2
    }
25
26
    /**
27
     * Return the code for the git hook scripts.
28
     *
29
     * @param string $hook Name of the hook to trigger.
30
     *
31
     * @return string
32
     */
33 2
    public function getCode(string $hook): string
34
    {
35 2
        return '#!/usr/bin/env bash' . PHP_EOL .
36 2
            'docker exec ' . $this->containerName . ' ./' . $this->binaryPath . ' ' . $hook . ' "$@"';
37
    }
38
}