Passed
Push — master ( b34030...56c38f )
by Sebastian
03:50
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\Git\Repository;
13
use sebastianfeldmann\CaptainHook\Runner\Installer;
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 4
    protected function configure()
33
    {
34 4
        $this->setName('install')
35 4
             ->setDescription('Install git hooks.')
36 4
             ->setHelp('This command will install the git hooks to your .git directory.')
37 4
             ->addArgument('hook', InputArgument::OPTIONAL, 'Hook you want to install.')
38 4
             ->addOption(
39 4
                 'configuration',
40 4
                 'c',
41 4
                 InputOption::VALUE_OPTIONAL,
42 4
                 'Path to your json configuration',
43 4
                 getcwd() . DIRECTORY_SEPARATOR . 'captainhook.json'
44 4
             )->addOption('force', 'f', InputOption::VALUE_NONE, 'Force to overwrite existing hooks')
45 4
             ->addOption(
46 4
                 'git-directory',
47 4
                 'g',
48 4
                 InputOption::VALUE_OPTIONAL,
49 4
                 'Path to your .git directory',
50 4
                 getcwd() . DIRECTORY_SEPARATOR . '.git'
51
             );
52 4
    }
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 3
    protected function execute(InputInterface $input, OutputInterface $output)
62
    {
63
64 3
        $io     = $this->getIO($input, $output);
65 3
        $config = $this->getConfig($input->getOption('configuration'), true);
66 2
        $repo   = new Repository(dirname($input->getOption('git-directory')));
67
68 1
        $installer = new Installer($io, $config, $repo);
69 1
        $installer->setForce($input->getOption('force'))
70 1
                  ->setHook($input->getArgument('hook'));
71
72 1
        $installer->run();
73 1
    }
74
}
75