ComposerAlias   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A activate() 0 8 1
A getCapabilities() 0 6 1
A getCommands() 0 11 2
A getAliases() 0 4 1
1
<?php
2
/*
3
 * This file is part of the slince/composer-alias package.
4
 *
5
 * (c) Slince <[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
11
namespace Slince\ComposerAlias;
12
13
use Composer\Composer;
14
use Composer\IO\IOInterface;
15
use Composer\Json\JsonFile;
16
use Composer\Plugin\Capability\CommandProvider;
17
use Composer\Plugin\Capable;
18
use Composer\Plugin\PluginInterface;
19
use Slince\ComposerAlias\Command\ProxyCommand;
20
21
class ComposerAlias implements PluginInterface, Capable, CommandProvider
22
{
23
    /**
24
     * @var Composer
25
     */
26
    protected $composer;
27
28
    /**
29
     * @var IOInterface
30
     */
31
    protected $io;
32
33
    /**
34
     * @var AliasCollection
35
     */
36
    protected static $aliases;
37
38
    protected static $activated = false;
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function activate(Composer $composer, IOInterface $io)
44
    {
45
        $this->composer = $composer;
46
        $this->io = $io;
47
        $configFile = $this->composer->getConfig()->get('home').'/config.json';
48
        static::$aliases = new AliasCollection(new JsonFile($configFile, null, $this->io));
49
        static::$activated = true;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function getCapabilities()
56
    {
57
        return [
58
            CommandProvider::class => __CLASS__,
59
        ];
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getCommands()
66
    {
67
        $commands = [
68
            new Command\AliasCommand($this),
69
        ];
70
        foreach (array_keys($this->getAliases()->all()) as $alias) {
71
            $commands[] = new ProxyCommand($alias, $this);
72
        }
73
74
        return $commands;
75
    }
76
77
    /**
78
     * @return AliasCollection
79
     */
80
    public function getAliases()
81
    {
82
        return static::$aliases;
83
    }
84
}
85