Test Failed
Pull Request — master (#4)
by Ashoka
06:12
created

Plugin::installFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Mediact\TestingSuite\Composer;
4
5
use Composer\Composer;
6
use Composer\EventDispatcher\EventSubscriberInterface;
7
use Composer\IO\IOInterface;
8
use Composer\Plugin\PluginInterface;
9
use Mediact\Composer\FileInstaller;
10
use Mediact\FileMapping\UnixFileMappingReader;
11
use Mediact\TestingSuite\Composer\Installer\ArchiveExcludeInstaller;
12
use Mediact\TestingSuite\Composer\Installer\FilesInstaller;
13
use Mediact\TestingSuite\Composer\Installer\GrumPhpInstaller;
14
use Mediact\TestingSuite\Composer\Installer\InstallerInterface;
15
use Mediact\TestingSuite\Composer\Installer\PackagesInstaller;
16
use Mediact\TestingSuite\Composer\Installer\PipelinesInstaller;
17
18
class Plugin implements PluginInterface, EventSubscriberInterface
19
{
20
    /**
21
     * @var InstallerInterface[]
22
     */
23
    private $installers;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param InstallerInterface[] ...$installers
29
     */
30
    public function __construct(InstallerInterface ...$installers)
31
    {
32
        $this->installers = $installers;
33
    }
34
35
    /**
36
     * Apply plugin modifications to Composer.
37
     *
38
     * @param Composer    $composer
39
     * @param IOInterface $io
40
     *
41
     * @return void
42
     */
43
    public function activate(Composer $composer, IOInterface $io)
44
    {
45
        $typeResolver    = new ProjectTypeResolver($composer);
46
        $mappingResolver = new MappingResolver($typeResolver);
47
        $fileInstaller   = new FileInstaller(
48
            new UnixFileMappingReader('', '')
49
        );
50
51
        $this->installers[] = new FilesInstaller($mappingResolver, $fileInstaller, $io);
52
        $this->installers[] = new GrumPhpInstaller($io);
53
        $this->installers[] = new ArchiveExcludeInstaller($mappingResolver, $io);
54
        $this->installers[] = new PackagesInstaller($composer, $typeResolver, $io);
55
        $this->installers[] = new PipelinesInstaller($fileInstaller, $io);
56
    }
57
58
    /**
59
     * Run the installers.
60
     *
61
     * @return void
62
     */
63
    public function install()
64
    {
65
        foreach ($this->installers as $installer) {
66
            $installer->install();
67
        }
68
    }
69
70
    /**
71
     * Subscribe to post update and post install command.
72
     *
73
     * @return array
74
     */
75
    public static function getSubscribedEvents(): array
76
    {
77
        return [
78
            'post-install-cmd' => [
79 1
                'install'
80
            ],
81 1
            'post-update-cmd' => [
82 1
                'install'
83 1
            ]
84 1
        ];
85 1
    }
86
}
87