Completed
Push — master ( c7b21c...a018ba )
by Sebastian
42:08
created

Cmd::createApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 6
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\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 = null)
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 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, $config = null)
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...
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, $config = null)
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