Passed
Push — master ( b649b5...b34030 )
by Sebastian
04:07
created

Template   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 29
c 0
b 0
f 0
ccs 18
cts 18
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCode() 0 20 1
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace CaptainHook\Hook;
11
12
/**
13
 * Template class
14
 *
15
 * @package CaptainHook
16
 * @author  Sebastian Feldmann <[email protected]>
17
 * @link    https://github.com/sebastianfeldmann/captainhook
18
 * @since   Class available since Release 0.9.0
19
 */
20
abstract class Template
21
{
22
    /**
23
     * Return the php code for the git hook scripts.
24
     *
25
     * @param  string $hook
26
     * @return string
27
     */
28 2
    public static function getCode($hook)
29
    {
30 2
        return '#!/usr/bin/env php' . PHP_EOL .
31 2
               '<?php' . PHP_EOL .
32 2
               '$autoLoader = __DIR__ . \'/../../vendor/autoload.php\';' . PHP_EOL . PHP_EOL .
33 2
               'if (!file_exists($autoLoader)) {' . PHP_EOL .
34 2
               '    fwrite(STDERR,' . PHP_EOL .
35 2
               '        \'Composer autoload.php could not be found\' . PHP_EOL .' . PHP_EOL .
36 2
               '        \'Please re-install the hook with:\' . PHP_EOL .' . PHP_EOL .
37 2
               '        \'$ captainhook install --composer-vendor-path=...\' . PHP_EOL' . PHP_EOL .
38 2
               '    );' . PHP_EOL .
39 2
               '    exit(1);' . PHP_EOL .
40 2
               '}' . PHP_EOL .
41 2
               'require $autoLoader;' . PHP_EOL .
42 2
               '$config = realpath(__DIR__ . \'/../../captainhook.json\');' . PHP_EOL .
43 2
               '$app    = new CaptainHook\Console\Application\Hook();' . PHP_EOL .
44 2
               '$app->setHook(\'' . $hook . '\');' . PHP_EOL .
45 2
               '$app->setConfigFile($config);' . PHP_EOL .
46 2
               '$app->run();' . PHP_EOL . PHP_EOL;
47
    }
48
}
49