Passed
Push — master ( 7bee4d...457c92 )
by Sebastian
01:54
created

Add::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

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