Completed
Pull Request — master (#98)
by Hiraku
09:07
created

Plugin::filterPackages()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 9.2
cc 4
eloc 11
nc 4
nop 1
crap 4
1
<?php
2
/*
3
 * hirak/prestissimo
4
 * @author Hiraku NAKANO
5
 * @license MIT https://github.com/hirak/prestissimo
6
 */
7
namespace Hirak\Prestissimo;
8
9
use Composer\Composer;
10
use Composer\IO;
11
use Composer\Plugin as CPlugin;
12
use Composer\EventDispatcher;
13
use Composer\Package;
14
use Composer\Installer;
15
use Composer\DependencyResolver;
16
17
class Plugin implements
18
    CPlugin\PluginInterface,
19
    EventDispatcher\EventSubscriberInterface
20
{
21
    /** @var IO\IOInterface */
22
    private $io;
23
24
    /** @var Composer\Config */
25
    private $config;
26
27
    /** @var boolean */
28
    private $disabled = false;
29
30
    private static $pluginClasses = array(
31
        'CopyRequest',
32
        'CurlMulti',
33
        'ConfigFacade',
34
        'FetchException',
35
        'FileDownloaderDummy',
36
        'Plugin',
37
        'Prefetcher',
38
    );
39
40
    public function activate(Composer $composer, IO\IOInterface $io)
41
    {
42
        // @codeCoverageIgnoreStart
43
        // guard for self-update problem
44
        if (__CLASS__ !== 'Hirak\Prestissimo\Plugin') {
45
            return $this->disable();
46
        }
47 2
        // @codeCoverageIgnoreEnd
48
49
        // load all classes
50
        foreach (self::$pluginClasses as $class) {
51
            class_exists(__NAMESPACE__ . '\\' . $class);
52
        }
53
54
        $this->io = $io;
55
        $this->config = $composer->getConfig();
0 ignored issues
show
Documentation Bug introduced by
It seems like $composer->getConfig() of type object<Composer\Config> is incompatible with the declared type object<Composer\Composer\Config> of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
    }
57 2
58 2
    public static function getSubscribedEvents()
59 2
    {
60
        return array(
61 2
            Installer\InstallerEvents::POST_DEPENDENCIES_SOLVING => array(
62 2
                array('onPostDependenciesSolving', PHP_INT_MAX),
63 2
            ),
64 2
        );
65
    }
66 1
67
    /**
68
     * pre-fetch parallel by curl_multi
69 1
     */
70 1
    public function onPostDependenciesSolving(Installer\InstallerEvent $ev)
71 1
    {
72 1
        if ($this->disabled) {
73
            return;
74
        }
75
        $prefetcher = new Prefetcher;
76
        $prefetcher->fetchAllFromOperations(
77
            $this->io,
78 1
            $this->config,
79
            $ev->getOperations()
80 1
        );
81 1
    }
82
83 1
    public function disable()
84 1
    {
85 1
        $this->disabled = true;
86
    }
87 1
88 1
    public function isDisabled()
89 1
    {
90 1
        return $this->disabled;
91 1
    }
92
}
93