Passed
Push — master ( 1eca82...577019 )
by Sebastian
03:18 queued 45s
created

Local::getPharHookLines()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 21
rs 9.6333
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 1
crap 2
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\Hook\Template;
17
use SebastianFeldmann\Camino\Path;
18
use SebastianFeldmann\Camino\Path\Directory;
19
use SebastianFeldmann\Camino\Path\File;
20
21
abstract class Local implements Template
22
{
23
    /**
24
     * Path to the captainhook configuration
25
     *
26
     * @var string
27
     */
28
    protected $configPath;
29
30
    /**
31
     * Original bootstrap option
32
     *
33
     * @var string
34
     */
35
    protected $bootstrap;
36
37
    /**
38
     * Path to the captainhook executable
39
     *
40
     * @var string
41
     */
42
    protected $executablePath;
43
44
    /**
45
     * Is the executable a phar file
46
     *
47
     * @var bool
48
     */
49
    protected $isPhar;
50 5
51
    /**
52 5
     * Local constructor
53 5
     *
54 5
     * @param \SebastianFeldmann\Camino\Path\Directory $repo
55
     * @param \SebastianFeldmann\Camino\Path\File      $config
56
     * @param \SebastianFeldmann\Camino\Path\File      $captainHook
57
     * @param string                                   $bootstrap
58
     * @param bool                                     $isPhar
59
     */
60
    public function __construct(Directory $repo, File $config, File $captainHook, string $bootstrap, bool $isPhar)
61
    {
62 5
        $this->bootstrap      = $bootstrap;
63
        $this->configPath     = $this->getPathForHookTo($repo, $config);
64 5
        $this->executablePath = $this->getPathForHookTo($repo, $captainHook);
65 5
        $this->isPhar         = $isPhar;
66 5
    }
67 5
68 5
    /**
69 5
     * Return the code for the git hook scripts
70 5
     *
71 5
     * @param  string $hook Name of the hook to generate the sourcecode for
72 5
     * @return string
73 5
     */
74 5
    public function getCode(string $hook): string
75 5
    {
76 5
        return implode(PHP_EOL, $this->getHookLines($hook)) . PHP_EOL;
77 5
    }
78
79
    /**
80
     * Return the path to the target path from inside the .git/hooks directory f.e. __DIR__ ../../vendor
81
     *
82
     * @param  \SebastianFeldmann\Camino\Path\Directory $repo
83
     * @param  \SebastianFeldmann\Camino\Path           $target
84
     * @return string
85
     */
86
    abstract protected function getPathForHookTo(Directory $repo, Path $target): string;
87
88
    /**
89
     * Return the code for the git hook scripts
90
     *
91
     * @param  string $hook Name of the hook to generate the sourcecode for
92
     * @return array<string>
93
     */
94
    abstract protected function getHookLines(string $hook): array;
95
}
96