ComposerHelper::install()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 4
b 0
f 0
nc 3
nop 1
dl 0
loc 24
rs 9.8333
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: joshgulledge
5
 * Date: 9/3/18
6
 * Time: 3:39 PM
7
 */
8
9
10
namespace LCI\MODX\Orchestrator;
11
12
use Composer\Composer;
13
use Composer\Script\Event;
14
use Composer\Installer\PackageEvent;
15
use Composer\Package\Package;
16
17
class ComposerHelper
18
{
19
    /**
20
     * @param Event $event
0 ignored issues
show
Bug introduced by
The type Composer\Script\Event was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
     * @throws \LCI\Blend\Exception\MigratorException
22
     */
23
    public static function install(Event $event)
24
    {
25
        $args = $event->getArguments();
26
27
        /** @var Composer $composer */
28
        $composer = $event->getComposer();
29
30
        $vendorDir = $composer->getConfig()->get('vendor-dir');
31
        require $vendorDir . '/autoload.php';
32
33
        Orchestrator::installComposerPackage('lci/blend');
34
        Orchestrator::install();
35
36
        /** @var Package $package */
37
        $package = $composer->getPackage();
38
        $extra = $package->getExtra();
39
40
        /** @deprecated in favor of deploy commands */
41
        if (isset($extra['auto-install']) && is_array($extra['auto-install'])) {
42
            foreach ($extra['auto-install'] as $orchestrator_package) {
43
                Orchestrator::installComposerPackage($orchestrator_package);
44
            }
45
        } else {
46
            Orchestrator::updateAllOrchestratorComposerPackages();
47
        }
48
    }
49
50
    /**
51
     * @param Event $event
52
     * @throws \LCI\Blend\Exception\MigratorException
53
     */
54
    public static function update(Event $event)
55
    {
56
        $args = $event->getArguments();
57
        /** @var Composer $composer */
58
        $composer = $event->getComposer();
59
        $vendorDir = $composer->getConfig()->get('vendor-dir');
60
        require $vendorDir . '/autoload.php';
61
62
        Orchestrator::install();
63
        Orchestrator::updateComposerPackage('lci/blend');
64
65
        /** @var Package $package */
66
        $package = $composer->getPackage();
67
        $extra = $package->getExtra();
68
69
        /** @deprecated in favor of deploy commands */
70
        if (isset($extra['auto-install']) && is_array($extra['auto-install'])) {
71
            foreach ($extra['auto-install'] as $orchestrator_package) {
72
                Orchestrator::updateComposerPackage($orchestrator_package);
73
            }
74
        } else {
75
            Orchestrator::updateAllOrchestratorComposerPackages();
76
        }
77
    }
78
79
    /**
80
     * @param PackageEvent $event
0 ignored issues
show
Bug introduced by
The type Composer\Installer\PackageEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
81
     * @throws \LCI\Blend\Exception\MigratorException
82
     */
83
    public static function uninstall(PackageEvent $event)
84
    {
85
        $args = $event->getArguments();
86
87
        /** @var \Composer\Package\BasePackage $package ~ current package */
88
        $currentPackage = $event->getOperation()->getPackage();
89
90
        /** @var Composer $composer */
91
        $composer = $event->getComposer();
92
93
        /** @var Package $package */
94
        $localPackage = $composer->getPackage();
95
96
        // this is the root composer.json data
97
        $vendorDir = $composer->getConfig()->get('vendor-dir');
98
99
        if (file_exists($vendorDir . '/autoload.php')) {
100
            require $vendorDir . '/autoload.php';
101
        }
102
103
        if ($currentPackage->getName() == 'lci\orchestrator') {
104
            Orchestrator::uninstall();
105
            // --leave-blend
106
            if (!isset($args['leave-blend'])) {
107
                Orchestrator::uninstallComposerPackage('lci/blend');
108
            }
109
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
110
        } elseif (self::isValidAutoInstall($currentPackage->getName(), $localPackage->getExtra())) {
0 ignored issues
show
Deprecated Code introduced by
The function LCI\MODX\Orchestrator\Co...r::isValidAutoInstall() has been deprecated: in favor of deploy commands ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

110
        } elseif (/** @scrutinizer ignore-deprecated */ self::isValidAutoInstall($currentPackage->getName(), $localPackage->getExtra())) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
111
            Orchestrator::uninstallComposerPackage($currentPackage->getName());
112
        }
113
    }
114
115
    /**
116
     * @deprecated in favor of deploy commands
117
     *
118
     * @param $package_name
119
     * @param $extra
120
     * @return bool
121
     */
122
    protected static function isValidAutoInstall($package_name, $extra)
123
    {
124
        if (isset($extra['auto-install']) && is_array($extra['auto-install']) && in_array($package_name, $extra['auto-install'])) {
125
            return true;
126
        }
127
128
        return false;
129
    }
130
131
}
132