Passed
Push — master ( 69774c...de7969 )
by Sebastian
02:46
created

Configuration::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.9666
cc 1
nc 1
nop 2
crap 1
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\Console\Command;
13
14
use CaptainHook\App\Console\IOUtil;
15
use CaptainHook\App\Console\Runtime\Resolver;
16
use CaptainHook\App\Runner\Config\Creator;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Class Config
23
 *
24
 * @package CaptainHook
25
 * @author  Sebastian Feldmann <[email protected]>
26
 * @link    https://github.com/captainhookphp/captainhook
27
 * @since   Class available since Release 0.9.0
28
 */
29
class Configuration extends ConfigAware
30
{
31
    /**
32
     * Configure the command
33
     *
34 5
     * @return void
35
     */
36 5
    protected function configure(): void
37 5
    {
38 5
        parent::configure();
39 5
        $this->setName('configure')
40 5
             ->setDescription('Configure your hooks')
41 5
             ->setHelp('This command creates or updates your captainhook configuration')
42 5
             ->addOption('extend', 'e', InputOption::VALUE_NONE, 'Extend existing configuration file')
43 5
             ->addOption('force', 'f', InputOption::VALUE_NONE, 'Overwrite existing configuration file')
44 5
             ->addOption('advanced', 'a', InputOption::VALUE_NONE, 'More options, but more to type')
45 5
             ->addOption(
46 5
                 'bootstrap',
47 5
                 null,
48
                 InputOption::VALUE_OPTIONAL,
49 5
                 'Path to composers vendor/autoload.php'
50 5
             );
51 5
    }
52 5
53 5
    /**
54
     * Execute the command
55 5
     *
56
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
57
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
58
     * @return int|null
59
     * @throws \Exception
60
     */
61
    protected function execute(InputInterface $input, OutputInterface $output)
62
    {
63
        $io       = $this->getIO($input, $output);
64
        $config   = $this->createConfig($input, false, ['bootstrap']);
65 2
66
        $configurator = new Creator($io, $config);
67 2
        $configurator->force(IOUtil::argToBool($input->getOption('force')))
68 2
                     ->extend(IOUtil::argToBool($input->getOption('extend')))
69 2
                     ->advanced(IOUtil::argToBool($input->getOption('advanced')))
70
                     ->setExecutable($this->resolver->getExecutable())
71 2
                     ->run();
72 2
        return 0;
73 2
    }
74
}
75