Passed
Branch master (146bbc)
by Allan
06:55
created

Plugin::deactivate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 0
c 1
b 1
f 1
dl 0
loc 2
rs 10
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerChangelogs;
7
8
use Vaimo\ComposerChangelogs\Managers;
9
use Vaimo\ComposerChangelogs\Analysers;
10
11
class Plugin implements
12
    \Composer\Plugin\PluginInterface,
13
    \Composer\EventDispatcher\EventSubscriberInterface,
14
    \Composer\Plugin\Capable
15
{
16
    /**
17
     * @var \Vaimo\ComposerChangelogs\Managers\ChangelogManager
18
     */
19
    private $changelogManager;
20
21
    /**
22
     * @var \Vaimo\ComposerChangelogs\Analysers\ComposerOperationAnalyser
23
     */
24
    private $operationAnalyser;
25
26
    /**
27
     * @var string[]
28
     */
29
    private $capabilitiesConfig = array();
30
    
31
    /**
32
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
33
     *
34
     * @param \Composer\Composer $composer
35
     * @param \Composer\IO\IOInterface $cliIO
36
     */
37
    public function activate(\Composer\Composer $composer, \Composer\IO\IOInterface $cliIO)
38
    {
39
        $composerCtxFactory = new \Vaimo\ComposerChangelogs\Factories\ComposerContextFactory($composer);
40
        $composerCtx = $composerCtxFactory->create();
41
42
        $pluginBootstrap = new \Vaimo\ComposerChangelogs\Composer\Plugin\Bootstrap($composerCtx);
43
44
        $pluginBootstrap->preloadPluginClasses();
45
        
46
        $this->changelogManager = new Managers\ChangelogManager($composerCtx);
47
        $this->operationAnalyser = new Analysers\ComposerOperationAnalyser();
48
49
        if (!interface_exists('\Composer\Plugin\Capability\CommandProvider')) {
50
            return;
51
        }
52
53
        $this->capabilitiesConfig = array(
54
            'Composer\Plugin\Capability\CommandProvider' => 'Vaimo\ComposerChangelogs\Composer\Plugin\CommandsProvider',
55
        );
56
    }
57
58
    public static function getSubscribedEvents()
59
    {
60
        return array(
61
            \Composer\Script\ScriptEvents::POST_INSTALL_CMD => 'bootstrapImplementation',
62
            \Composer\Script\ScriptEvents::POST_UPDATE_CMD => 'bootstrapImplementation',
63
            \Composer\Installer\PackageEvents::PRE_PACKAGE_UNINSTALL => 'onPackageUninstall'
64
        );
65
    }
66
    
67
    public function getCapabilities()
68
    {
69
        return $this->capabilitiesConfig;
70
    }
71
    
72
    public function bootstrapImplementation()
73
    {
74
        if (!$this->changelogManager) {
75
            return;
76
        }
77
        
78
        $this->changelogManager->bootstrap();
79
    }
80
    
81
    public function onPackageUninstall(\Composer\Installer\PackageEvent $event)
82
    {
83
        if (!$this->operationAnalyser->isPluginUninstallOperation($event->getOperation())) {
84
            return;
85
        }
86
87
        $this->changelogManager = null;
88
    }
89
90
    /**
91
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
92
     */
93
    public function deactivate(\Composer\Composer $composer, \Composer\IO\IOInterface $appIO)
94
    {
95
    }
96
97
    /**
98
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
99
     */
100
    public function uninstall(\Composer\Composer $composer, \Composer\IO\IOInterface $appIO)
101
    {
102
    }
103
}
104