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

Shell   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPathForHookTo() 0 6 2
A getHookLines() 0 11 1
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\Local;
15
16
use CaptainHook\App\CH;
17
use CaptainHook\App\Hook\Template;
18
use SebastianFeldmann\Camino\Path;
19
use SebastianFeldmann\Camino\Path\Directory;
20
21
/**
22
 * Local class
23
 *
24
 * Generates the sourcecode for the php hook scripts in .git/hooks/*.
25
 *
26
 * @package CaptainHook
27
 * @author  Sebastian Feldmann <[email protected]>
28
 * @link    https://github.com/captainhookphp/captainhook
29
 * @since   Class available since Release 5.0.0
30
 */
31
class Shell extends Template\Local
32
{
33
    /**
34
     * Return the path to the target path from the git repository root f.e. vendor/bin/captainhook
35
     *
36
     * @param  \SebastianFeldmann\Camino\Path\Directory $repo
37
     * @param  \SebastianFeldmann\Camino\Path           $target
38
     * @return string
39
     */
40
    protected function getPathForHookTo(Directory $repo, Path $target): string
41
    {
42
        if (!$target->isChildOf($repo)) {
43
            return $target->getPath();
44
        }
45
        return $target->getRelativePathFrom($repo);
46
    }
47
48
    /**
49
     * Returns lines of code for the local src installation
50
     *
51
     * @param  string $hook
52
     * @return array<string>
53
     */
54
    protected function getHookLines(string $hook): array
55
    {
56
        return [
57
            '#!/usr/bin/sh',
58
            '',
59
            '# installed by CaptainHook ' . CH::VERSION,
60
            '',
61
            $this->executablePath
62
                . ' --configuration=' . $this->configPath
63
                . ' --bootstrap=' . $this->bootstrap
64
                . ' ' . $hook . ' "$@"',
65
        ];
66
    }
67
}
68