Completed
Pull Request — master (#32)
by
unknown
09:15
created

Docker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
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
    public function __construct(string $repoPath, string $vendorPath, string $containerName)
21
    {
22
        $this->binaryPath = HookUtil::getBinaryPath($repoPath, $vendorPath, 'captainhook-run');
23
        $this->containerName = $containerName;
24
    }
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
    public function getCode(string $hook): string
34
    {
35
        return '#!/usr/bin/env bash' . PHP_EOL .
36
            'docker exec ' . $this->containerName . ' ./' . $this->binaryPath . ' ' . $hook . ' "$@"';
37
    }
38
}