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\Console\Command; |
11
|
|
|
|
12
|
|
|
use CaptainHook\Git\Repository; |
13
|
|
|
use CaptainHook\Runner\Configurator; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Config |
20
|
|
|
* |
21
|
|
|
* @package CaptainHook |
22
|
|
|
* @author Sebastian Feldmann <[email protected]> |
23
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
24
|
|
|
* @since Class available since Release 0.9.0 |
25
|
|
|
*/ |
26
|
|
|
class Configuration extends Base |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Configure the command. |
30
|
|
|
*/ |
31
|
3 |
View Code Duplication |
protected function configure() |
|
|
|
|
32
|
|
|
{ |
33
|
3 |
|
$this->setName('configure') |
34
|
3 |
|
->setDescription('Configure your hooks.') |
35
|
3 |
|
->setHelp('This command creates or updates your captainhook configuration.') |
36
|
3 |
|
->addOption('extend', 'e', InputOption::VALUE_NONE, 'Extend existing configuration file') |
37
|
3 |
|
->addOption('force', 'f', InputOption::VALUE_NONE, 'Overwrite existing configuration file') |
38
|
3 |
|
->addOption( |
39
|
3 |
|
'configuration', |
40
|
3 |
|
'c', |
41
|
3 |
|
InputOption::VALUE_OPTIONAL, |
42
|
3 |
|
'Path to your json configuration', |
43
|
3 |
|
getcwd() . DIRECTORY_SEPARATOR . 'captainhook.json' |
44
|
|
|
); |
45
|
3 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Execute the command. |
49
|
|
|
* |
50
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
51
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
55
|
|
|
{ |
56
|
2 |
|
$io = $this->getIO($input, $output); |
57
|
2 |
|
$config = $this->getConfig($input->getOption('configuration')); |
58
|
2 |
|
$repo = new Repository(); |
59
|
|
|
|
60
|
2 |
|
$configurator = new Configurator($io, $config, $repo); |
61
|
2 |
|
$configurator->force($input->getOption('force')) |
62
|
2 |
|
->extend($input->getOption('extend')) |
63
|
2 |
|
->run(); |
64
|
2 |
|
} |
65
|
|
|
} |
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.