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

Add::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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 Add extends Base
28
{
29
    /**
30
     * Configure the command
31
     *
32
     * @return void
33
     */
34 3
    protected function configure() : void
35
    {
36 3
        $this->setName('add')
37 3
             ->setDescription('Add an action to a hook configuration')
38 3
             ->setHelp('This command will add an action configuration to a given hook configuration')
39 3
             ->addArgument('hook', InputArgument::REQUIRED, 'Hook you want to add the action to')
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('AddAction');
65
66 1
        $editor->run();
67 1
    }
68
}
69