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

Docker   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 28
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCode() 0 4 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
}