Passed
Push — master ( b34030...56c38f )
by Sebastian
03:50
created

Run   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 34.88 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 15
loc 43
c 0
b 0
f 0
ccs 24
cts 24
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 15 15 1
A execute() 0 14 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\CommitMessage;
13
use sebastianfeldmann\CaptainHook\Git\Repository;
14
use sebastianfeldmann\CaptainHook\Runner;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Class Run
22
 *
23
 * @package CaptainHook
24
 * @author  Sebastian Feldmann <[email protected]>
25
 * @link    https://github.com/sebastianfeldmann/captainhook
26
 * @since   Class available since Release 0.9.0
27
 */
28
class Run extends Base
29
{
30
    /**
31
     * Configure the command.
32
     */
33 2 View Code Duplication
    protected function configure()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
34
    {
35 2
        $this->setName('run')
36 2
             ->setDescription('Run git hook.')
37 2
             ->setHelp("This command executes a configured git hook.")
38 2
             ->addArgument('hook', InputArgument::REQUIRED, 'Hook you want to execute.')
39 2
             ->addOption('message', 'm', InputOption::VALUE_OPTIONAL, 'File containing the commit message.')
40 2
             ->addOption(
41 2
                 'configuration',
42 2
                 'c',
43 2
                 InputOption::VALUE_OPTIONAL,
44 2
                 'Path to your json configuration',
45 2
                 getcwd() . DIRECTORY_SEPARATOR . 'captainhook.json'
46
             );
47 2
    }
48
49
    /**
50
     * Execute the command.
51
     *
52
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
53
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
54
     * @return void
55
     */
56 2
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58 2
        $io      = $this->getIO($input, $output);
59 2
        $config  = $this->getConfig($input->getOption('configuration'), true);
60 2
        $repo    = new Repository();
61 2
        $msgFile = $input->getOption('message');
62 2
        if (!empty($msgFile)) {
63 1
            $repo->setCommitMsg(CommitMessage::createFromFile($msgFile));
64
        }
65
66 2
        $hook = new Runner\Hook($io, $config, $repo);
67 2
        $hook->setHook($input->getArgument('hook'));
68 2
        $hook->run();
69 2
    }
70
}
71