Express   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
dl 0
loc 106
ccs 49
cts 49
cp 1
rs 10
c 1
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureHooks() 0 11 1
A setupPHPCodesnifferHook() 0 14 2
A setupPHPUnitHook() 0 13 2
A setupMessageHook() 0 11 2
A setupPHPLintingHook() 0 10 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
namespace CaptainHook\App\Runner\Config\Setup;
13
14
use CaptainHook\App\Config;
15
use CaptainHook\App\Console\IOUtil;
16
use CaptainHook\App\Hooks;
17
use CaptainHook\App\Runner\Config\Setup;
18
19
/**
20
 * Class Express
21
 *
22
 * @package CaptainHook
23
 * @author  Sebastian Feldmann <[email protected]>
24
 * @link    https://github.com/captainhook-git/captainhook
25
 * @since   Class available since Release 2.2.0
26
 */
27
class Express extends Guided implements Setup
28
{
29
    /**
30
     * Setup hooks by asking some basic questions
31
     *
32
     * @param  \CaptainHook\App\Config $config
33
     * @throws \Exception
34
     */
35 3
    public function configureHooks(Config $config): void
36
    {
37 3
        $msgHook = $config->getHookConfig(Hooks::COMMIT_MSG);
38 3
        $preHook = $config->getHookConfig(Hooks::PRE_COMMIT);
39 3
        $msgHook->setEnabled(true);
40 3
        $preHook->setEnabled(true);
41
42 3
        $this->setupMessageHook($msgHook);
43 3
        $this->setupPHPLintingHook($preHook);
44 3
        $this->setupPHPUnitHook($preHook);
45 3
        $this->setupPHPCodesnifferHook($preHook);
46
    }
47
48
    /**
49
     * Set up the commit message hook
50
     *
51
     * @param  \CaptainHook\App\Config\Hook $config
52
     * @return void
53
     * @throws \Exception
54
     */
55 3
    private function setupMessageHook(Config\Hook $config): void
56
    {
57 3
        $answer = $this->io->ask(
58 3
            '  <info>Do you want to validate your commit messages?</info> <comment>[y,n]</comment> ',
59 3
            'n'
60 3
        );
61
62 3
        if (IOUtil::answerToBool($answer)) {
63 1
            $call    = '\\CaptainHook' . '\\App' . '\\Hook\\Message\\Action\\Beams';
64 1
            $options = ['subjectLength' => 50, 'bodyLineLength' => 72];
65 1
            $config->addAction(new Config\Action($call, $options));
66
        }
67
    }
68
69
    /**
70
     * Set up the linting hook
71
     *
72
     * @param  \CaptainHook\App\Config\Hook $config
73
     * @return void
74
     * @throws \Exception
75
     */
76 3
    private function setupPHPLintingHook(Config\Hook $config): void
77
    {
78 3
        $answer = $this->io->ask(
79 3
            '  <info>Do you want to check your files for syntax errors?</info> <comment>[y,n]</comment> ',
80 3
            'n'
81 3
        );
82
83 3
        if (IOUtil::answerToBool($answer)) {
84 1
            $call    = '\\CaptainHook' . '\\App' . '\\Hook\\PHP\\Action\\Linting';
85 1
            $config->addAction(new Config\Action($call));
86
        }
87
    }
88
89
    /**
90
     * Setup the phpunit hook
91
     *
92
     * @param  \CaptainHook\App\Config\Hook $config
93
     * @return void
94
     * @throws \Exception
95
     */
96 3
    private function setupPHPUnitHook(Config\Hook $config): void
97
    {
98 3
        $answer = $this->io->ask(
99 3
            '  <info>Do you want to run phpunit before committing?</info> <comment>[y,n]</comment> ',
100 3
            'n'
101 3
        );
102
103 3
        if (IOUtil::answerToBool($answer)) {
104 1
            $call = $this->io->ask(
105 1
                '  <info>Enter the phpunit command you want to execute.</info> <comment>[phpunit]</comment> ',
106 1
                'phpunit'
107 1
            );
108 1
            $config->addAction(new Config\Action($call));
109
        }
110
    }
111
112
    /**
113
     * Setup the code sniffer hook
114
     *
115
     * @param  \CaptainHook\App\Config\Hook $config
116
     * @return void
117
     * @throws \Exception
118
     */
119 3
    private function setupPHPCodesnifferHook(Config\Hook $config): void
120
    {
121 3
        $answer = $this->io->ask(
122 3
            '  <info>Do you want to run phpcs before committing?</info> <comment>[y,n]</comment> ',
123 3
            'n'
124 3
        );
125
126 3
        if (IOUtil::answerToBool($answer)) {
127 1
            $call    = $this->io->ask(
128 1
                '  <info>Enter the phpcs command you want to execute.</info> '
129 1
                . '<comment>[phpcs --standard=psr2 src]</comment> ',
130 1
                'phpcs --standard=psr2 src'
131 1
            );
132 1
            $config->addAction(new Config\Action($call));
133
        }
134
    }
135
}
136