Configuration   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 26
c 0
b 0
f 0
dl 0
loc 50
ccs 27
cts 27
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 18 2
A configure() 0 14 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 Exception;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * Class Config
24
 *
25
 * @package CaptainHook
26
 * @author  Sebastian Feldmann <[email protected]>
27
 * @link    https://github.com/captainhook-git/captainhook
28
 * @since   Class available since Release 0.9.0
29
 */
30
class Configuration extends ConfigAware
31
{
32
    /**
33
     * Configure the command
34
     *
35
     * @return void
36
     */
37 4
    protected function configure(): void
38
    {
39 4
        parent::configure();
40 4
        $this->setName('configure')
41 4
             ->setDescription('Create or update a captainhook.json configuration')
42 4
             ->setHelp('Create or update a captainhook.json configuration')
43 4
             ->addOption('extend', 'e', InputOption::VALUE_NONE, 'Extend existing configuration file')
44 4
             ->addOption('force', 'f', InputOption::VALUE_NONE, 'Overwrite existing configuration file')
45 4
             ->addOption('advanced', 'a', InputOption::VALUE_NONE, 'More options, but more to type')
46 4
             ->addOption(
47 4
                 'bootstrap',
48 4
                 null,
49 4
                 InputOption::VALUE_OPTIONAL,
50 4
                 'Path to composers vendor/autoload.php'
51 4
             );
52
    }
53
54
    /**
55
     * Execute the command
56
     *
57
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
58
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
59
     * @return int
60
     * @throws \Exception
61
     */
62 2
    protected function execute(InputInterface $input, OutputInterface $output): int
63
    {
64
        try {
65 2
            $io     = $this->getIO($input, $output);
66 2
            $config = $this->createConfig($input, false, ['bootstrap']);
67
68 2
            $this->determineVerbosity($output, $config);
69
70 2
            $configurator = new Creator($io, $config);
71 2
            $configurator->force(IOUtil::argToBool($input->getOption('force')))
72 2
                         ->extend(IOUtil::argToBool($input->getOption('extend')))
73 2
                         ->advanced(IOUtil::argToBool($input->getOption('advanced')))
74 2
                         ->setExecutable($this->resolver->getExecutable())
75 2
                         ->run();
76
77 1
            return 0;
78 1
        } catch (Exception $e) {
79 1
            return $this->crash($output, $e);
80
        }
81
    }
82
}
83