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

Cmd   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 38.46 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 20
loc 52
c 0
b 0
f 0
ccs 23
cts 23
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 11 11 1
A install() 9 9 1
A createApplication() 0 8 1

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\Composer;
11
12
use Composer\Script\Event;
13
use SebastianFeldmann\CaptainHook\Console\Command\Configuration;
14
use SebastianFeldmann\CaptainHook\Console\Command\Install;
15
use Symfony\Component\Console\Input\ArrayInput;
16
17
/**
18
 * Class Cmd
19
 *
20
 * @package CaptainHook
21
 * @author  Sebastian Feldmann <[email protected]>
22
 * @link    https://github.com/sebastianfeldmann/captainhook
23
 * @since   Class available since Release 0.9.0
24
 */
25
abstract class Cmd
26
{
27
    /**
28
     * Gets called by composer after a successful package installation.
29
     *
30
     * @param \Composer\Script\Event $event
31
     * @param string                 $config
32
     */
33 1 View Code Duplication
    public static function configure(Event $event, $config = '')
34
    {
35 1
        $app           = self::createApplication($event, $config);
36 1
        $configuration = new Configuration();
37 1
        $configuration->setIO($app->getIO());
38 1
        $input         = new ArrayInput(
39 1
            ['command' => 'configure', '--configuration' => $config, '-f' => '-f', '-e' => '-e']
40
        );
41 1
        $app->add($configuration);
42 1
        $app->run($input);
43 1
    }
44
45
    /**
46
     * Installs the hooks to your local repository.
47
     *
48
     * @param \Composer\Script\Event $event
49
     * @param string                 $config
50
     */
51 1 View Code Duplication
    public static function install(Event $event, string $config = '')
52
    {
53 1
        $app     = self::createApplication($event, $config);
54 1
        $install = new Install();
55 1
        $install->setIO($app->getIO());
56 1
        $input   = new ArrayInput(['command' => 'install', '--configuration' => $config, '-f' => '-f']);
57 1
        $app->add($install);
58 1
        $app->run($input);
59 1
    }
60
61
    /**
62
     * Create a CaptainHook Composer application.
63
     *
64
     * @param  \Composer\Script\Event $event
65
     * @param  string                 $config
66
     * @return \SebastianFeldmann\CaptainHook\Composer\Application
67
     */
68 2
    private static function createApplication(Event $event, string $config = '') : Application
69
    {
70 2
        $app = new Application();
71 2
        $app->setAutoExit(false);
72 2
        $app->setConfigFile($config);
73 2
        $app->setProxyIO($event->getIO());
74 2
        return $app;
75
    }
76
}
77