Test Failed
Pull Request — master (#4)
by Ashoka
09:01 queued 03:06
created

Plugin::getPhpCsMappingFile()   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 0
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
    /** @var InstallerInterface[] */
21
    private $installers;
22
23
    /**
24
     * Constructor.
25
     *
26
     * @param InstallerInterface[] ...$installers
27
     */
28
    public function __construct(InstallerInterface ...$installers)
29
    {
30
        $this->installers = $installers;
31
    }
32
33
    /**
34
     * Apply plugin modifications to Composer.
35
     *
36
     * @param Composer    $composer
37
     * @param IOInterface $io
38
     *
39
     * @return void
40
     */
41
    public function activate(Composer $composer, IOInterface $io)
42
    {
43
        $typeResolver    = new ProjectTypeResolver($composer);
44
        $mappingResolver = new MappingResolver($typeResolver);
45
        $fileInstaller   = new FileInstaller(
46
            new UnixFileMappingReader('', '')
47
        );
48
49
        $this->installers[] = new FilesInstaller($mappingResolver, $fileInstaller, $io);
50
        $this->installers[] = new GrumPhpInstaller($io);
51
        $this->installers[] = new ArchiveExcludeInstaller($mappingResolver, $io);
52
        $this->installers[] = new PackagesInstaller($composer, $typeResolver, $io);
53
        $this->installers[] = new PipelinesInstaller($fileInstaller, $io);
54
    }
55
56
    /**
57
     * Run the installers.
58
     *
59
     * @return void
60
     */
61
    public function install()
62
    {
63
        foreach ($this->installers as $installer) {
64
            $installer->install();
65
        }
66
    }
67
68
    /**
69
     * Subscribe to post update and post install command.
70
     *
71
     * @return array
72
     */
73
    public static function getSubscribedEvents(): array
74
    {
75
        return [
76
            'post-install-cmd' => [
77
                'install'
78
            ],
79 1
            'post-update-cmd' => [
80
                'install'
81 1
            ]
82 1
        ];
83 1
    }
84
}
85