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) |
|
|
|
|
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) |
|
|
|
|
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
|
|
|
|
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.