Passed
Push — main ( 388f81...59708d )
by Sebastian
03:37
created

Local::getBootstrapCmdOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of captainhook.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace CaptainHook\App\Hook\Template;
15
16
use CaptainHook\App\Config;
17
use CaptainHook\App\Hook\Template;
18
use CaptainHook\App\Runner\Bootstrap\Util;
19
20
abstract class Local implements Template
21
{
22
    /**
23
     * All template related path information
24
     *
25
     * @var \CaptainHook\App\Hook\Template\PathInfo
26
     */
27
    protected PathInfo $pathInfo;
28
29
    /**
30
     * CaptainHook configuration
31
     *
32
     * @var \CaptainHook\App\Config
33
     */
34
    protected Config $config;
35
36
    /**
37
     * Local constructor
38
     *
39
     * @param \CaptainHook\App\Hook\Template\PathInfo $pathInfo
40
     * @param \CaptainHook\App\Config                 $config
41
     */
42 34
    public function __construct(PathInfo $pathInfo, Config $config)
43
    {
44 34
        $this->pathInfo = $pathInfo;
45 34
        $this->config   = $config;
46
    }
47
48
    /**
49
     * Return the code for the git hook scripts
50
     *
51
     * @param  string $hook Name of the hook to generate the sourcecode for
52
     * @return string
53
     */
54 31
    public function getCode(string $hook): string
55
    {
56 31
        return implode(PHP_EOL, $this->getHookLines($hook)) . PHP_EOL;
57
    }
58
59
    /**
60
     * Returns the bootstrap option depending on the current runtime (can be empty)
61
     *
62
     * @return string
63
     */
64 27
    public function getBootstrapCmdOption(): string
65
    {
66 27
        return Util::bootstrapCmdOption($this->pathInfo->isPhar(), $this->config);
67
    }
68
69
    /**
70
     * Return the code for the git hook scripts
71
     *
72
     * @param  string $hook Name of the hook to generate the sourcecode for
73
     * @return array<string>
74
     */
75
    abstract protected function getHookLines(string $hook): array;
76
}
77