Passed
Push — master ( 3a6da4...ca4c8c )
by Sebastian
03:44
created

Enable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 17
dl 0
loc 40
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 10 1
A configure() 0 12 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\App\Console\Command;
11
12
use CaptainHook\App\CH;
13
use CaptainHook\App\Runner\Config\Editor;
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Class Add
21
 *
22
 * @package CaptainHook
23
 * @author  Sebastian Feldmann <[email protected]>
24
 * @link    https://github.com/captainhookphp/captainhook
25
 * @since   Class available since Release 4.1.1
26
 */
27
class Enable extends Base
28
{
29
    /**
30
     * Configure the command
31
     *
32
     * @return void
33
     */
34 3
    protected function configure() : void
35
    {
36 3
        $this->setName('enable')
37 3
             ->setDescription('Enable a hook execution')
38 3
             ->setHelp('This command will enable a hook configuration for a given hook')
39 3
             ->addArgument('hook', InputArgument::REQUIRED, 'Hook you want to enable')
40 3
             ->addOption(
41 3
                 'configuration',
42 3
                 'c',
43 3
                 InputOption::VALUE_OPTIONAL,
44 3
                 'Path to your json configuration',
45 3
                 getcwd() . DIRECTORY_SEPARATOR . CH::CONFIG
46
             );
47 3
    }
48
49
    /**
50
     * Execute the command
51
     *
52
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
53
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
54
     * @return void
55
     * @throws \CaptainHook\App\Exception\InvalidHookName
56
     */
57 2
    protected function execute(InputInterface $input, OutputInterface $output) : void
58
    {
59 2
        $io     = $this->getIO($input, $output);
60 2
        $config = $this->getConfig($input->getOption('configuration'), true);
61
62 1
        $editor = new Editor($io, $config);
63 1
        $editor->setHook((string) $input->getArgument('hook'))
64 1
               ->setChange('EnableHook');
65
66 1
        $editor->run();
67 1
    }
68
}
69