Completed
Push — master ( aa9657...bb9832 )
by Sebastian
05:21
created

Install::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 8
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 SebastianFeldmann\CaptainHook\Console\Command;
11
12
use SebastianFeldmann\CaptainHook\Runner\Installer;
13
use SebastianFeldmann\Git\Repository;
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 Install
21
 *
22
 * @package CaptainHook
23
 * @author  Sebastian Feldmann <[email protected]>
24
 * @link    https://github.com/sebastianfeldmann/captainhook
25
 * @since   Class available since Release 0.9.0
26
 */
27
class Install extends Base
28
{
29
    /**
30
     * Configure the command.
31
     */
32 5
    protected function configure()
33
    {
34 5
        $this->setName('install')
35 5
             ->setDescription('Install git hooks')
36 5
             ->setHelp('This command will install the git hooks to your .git directory')
37 5
             ->addArgument('hook', InputArgument::OPTIONAL, 'Hook you want to install')
38 5
             ->addOption(
39 5
                 'configuration',
40 5
                 'c',
41 5
                 InputOption::VALUE_OPTIONAL,
42 5
                 'Path to your json configuration',
43 5
                 getcwd() . DIRECTORY_SEPARATOR . 'captainhook.json'
44 5
             )->addOption('force', 'f', InputOption::VALUE_NONE, 'Force to overwrite existing hooks')
45 5
             ->addOption(
46 5
                 'git-directory',
47 5
                 'g',
48 5
                 InputOption::VALUE_OPTIONAL,
49 5
                 'Path to your .git directory',
50 5
                 getcwd() . DIRECTORY_SEPARATOR . '.git'
51
             );
52 5
    }
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 void
60
     */
61 4
    protected function execute(InputInterface $input, OutputInterface $output)
62
    {
63
64 4
        $io     = $this->getIO($input, $output);
65 4
        $config = $this->getConfig($input->getOption('configuration'), true);
66 3
        $repo   = new Repository(dirname($input->getOption('git-directory')));
67
68 2
        $installer = new Installer($io, $config, $repo);
69 2
        $installer->setForce($input->getOption('force'))
70 2
                  ->setHook((string) $input->getArgument('hook'));
71
72 2
        $installer->run();
73 2
    }
74
}
75