Completed
Pull Request — master (#98)
by Hiraku
02:37
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 2
    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
        // @codeCoverageIgnoreEnd
48
49
        // load all classes
50 2
        foreach (self::$pluginClasses as $class) {
51 2
            class_exists(__NAMESPACE__ . '\\' . $class);
52 2
        }
53
54 2
        $this->io = $io;
55 2
        $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 2
    }
57
58 1
    public static function getSubscribedEvents()
59
    {
60
        return array(
61 1
            Installer\InstallerEvents::POST_DEPENDENCIES_SOLVING => array(
62 1
                array('onPostDependenciesSolving', PHP_INT_MAX),
63 1
            ),
64 1
        );
65
    }
66
67
    /**
68
     * pre-fetch parallel by curl_multi
69
     */
70 1
    public function onPostDependenciesSolving(Installer\InstallerEvent $ev)
71
    {
72 1
        if ($this->disabled) {
73 1
            return;
74
        }
75 1
        $prefetcher = new Prefetcher;
76 1
        $prefetcher->fetchAllFromOperations(
77 1
            $this->io,
78 1
            $this->config,
79 1
            $ev->getOperations()
80 1
        );
81 1
    }
82
83 1
    public function disable()
84
    {
85 1
        $this->disabled = true;
86 1
    }
87
88 1
    public function isDisabled()
89
    {
90 1
        return $this->disabled;
91
    }
92
}
93