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

Plugin::getFilePaths()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
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
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
44
     */
45
    public function activate(Composer $composer, IOInterface $io)
46
    {
47
        $typeResolver    = new ProjectTypeResolver($composer);
48
        $mappingResolver = new MappingResolver($typeResolver);
49
        $fileInstaller   = new FileInstaller(
50
            new UnixFileMappingReader('', '')
51
        );
52
53
        $this->installers[] = new FilesInstaller($mappingResolver, $fileInstaller, $io);
54
        $this->installers[] = new GrumPhpInstaller($io);
55
        $this->installers[] = new ArchiveExcludeInstaller($mappingResolver, $io);
56
        $this->installers[] = new PackagesInstaller($composer, $typeResolver, $io);
57
        $this->installers[] = new PipelinesInstaller($fileInstaller, $io);
58
    }
59
60
    /**
61
     * Run the installers.
62
     *
63
     * @return void
64
     */
65
    public function install()
66
    {
67
        foreach ($this->installers as $installer) {
68
            $installer->install();
69
        }
70
    }
71
72
    /**
73
     * Subscribe to post update and post install command.
74
     *
75
     * @return array
76
     */
77
    public static function getSubscribedEvents(): array
78
    {
79 1
        return [
80
            'post-install-cmd' => [
81 1
                'install'
82 1
            ],
83 1
            'post-update-cmd' => [
84 1
                'install'
85 1
            ]
86 1
        ];
87 1
    }
88
}
89