RegistryFactory::getPool()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Asset Packagist.
4
 *
5
 * @link      https://github.com/hiqdev/asset-packagist
6
 * @package   asset-packagist
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\assetpackagist\registry;
12
13
use Composer\Config as ComposerConfig;
14
use Composer\DependencyResolver\Pool;
15
use Composer\Factory;
16
use Composer\Installer\InstallationManager;
17
use Composer\IO\IOInterface;
18
use Composer\Package\RootPackage;
19
use Composer\Repository\CompositeRepository;
20
use Composer\Repository\RepositoryFactory;
21
use Composer\Repository\RepositoryManager;
22
use Fxp\Composer\AssetPlugin\Config\Config as AssetConfig;
23
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager;
24
use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter;
25
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;
26
use hiqdev\assetpackagist\log\YiiLogIO;
27
use yii\base\Object;
28
use yii\di\Instance;
29
30
class RegistryFactory extends Object
0 ignored issues
show
Deprecated Code introduced by
The class yii\base\Object has been deprecated with message: since 2.0.13, the class name `Object` is invalid since PHP 7.2, use [[BaseObject]] instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
31
{
32
    /**
33
     * The composer output.
34
     * @var string|IOInterface
35
     */
36
    public $io = [
37
        'class' => YiiLogIO::class,
38
    ];
39
40
    /**
41
     * @var ComposerConfig
42
     */
43
    public $composerConfig;
44
45
    /**
46
     * @var RepositoryManager
47
     */
48
    public $repositoryManager;
49
50
    /**
51
     * @var AssetConfig
52
     */
53
    public $assetConfig;
54
55
    /**
56
     * @var RootPackage
57
     */
58
    public $rootPackage;
59
60
    /**
61
     * @var InstallationManager
62
     */
63
    public $installationManager;
64
65
    /**
66
     * @var VcsPackageFilter
67
     */
68
    public $packageFilter;
69
70
    /**
71
     * @var AssetRepositoryManager
72
     */
73
    public $assetRepositoryManager;
74
75
    public function init()
76
    {
77
        parent::init();
78
79
        $this->io = Instance::ensure($this->io, IOInterface::class);
80
81
        /**
82
         * Factory::createConfig load the composer configuration in COMPOSER_HOME
83
         * First read COMPOSER_HOME/config.json and COMPOSER_HOME/auth.json.
84
         */
85
        $this->composerConfig = Factory::createConfig($this->io);
86
87
        /**
88
         * Required to read authentication tokens (Ex. GitHub API)
89
         * See https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens.
90
         */
91
        $this->io->loadConfiguration($this->composerConfig);
92
93
        /**
94
         * Create RepositoryManager with defaults repositories classes.
95
         */
96
        $this->repositoryManager = RepositoryFactory::manager($this->io, $this->composerConfig);
97
98
        /**
99
         * Read fxp/composer-asset-plugin config
100
         * See https://github.com/fxpio/composer-asset-plugin/blob/master/Resources/doc/index.md
101
         * Note: The "COMPOSER_HOME/config.json" file is already the "config" key.
102
         */
103
        $arrayConfig = [];
104
        if ($this->composerConfig->has('fxp-asset')) {
105
            $arrayConfig = $this->composerConfig->get('fxp-asset');
106
        }
107
108
        /**
109
         * Enabling the fxp/composer-asset-plugin plugin
110
         * See activate method in https://github.com/fxpio/composer-asset-plugin/blob/master/FxpAssetPlugin.php.
111
         */
112
        $this->assetConfig = new AssetConfig($arrayConfig);
113
114
        //Dummy Package
115
        $this->rootPackage = new RootPackage('asset-packagist', '0.0.0.0', '0.0.0');
116
        $this->installationManager = new InstallationManager();
117
        $this->packageFilter = new VcsPackageFilter($this->assetConfig, $this->rootPackage, $this->installationManager);
118
        $this->assetRepositoryManager = new AssetRepositoryManager($this->io, $this->repositoryManager, $this->assetConfig, $this->packageFilter);
119
120
        /**
121
         * Define default repositories for Bower and NPM.
122
         */
123
        AssetPlugin::addRegistryRepositories($this->assetRepositoryManager, $this->packageFilter, $this->assetConfig);
124
        AssetPlugin::setVcsTypeRepositories($this->repositoryManager);
125
    }
126
127
    public function getRepository()
128
    {
129
        return new CompositeRepository($this->repositoryManager->getRepositories());
130
    }
131
132
    public function getPool($minimumStability = 'dev')
133
    {
134
        $pool = new Pool($minimumStability);
135
        $pool->addRepository($this->getRepository());
136
        return $pool;
137
    }
138
}
139