ConfigInstaller::install()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * Copyright MediaCT. All rights reserved.
5
 * https://www.mediact.nl
6
 */
7
8
namespace Mediact\TestingSuite\Composer\Installer;
9
10
use Composer\Factory;
11
use Composer\IO\IOInterface;
12
use Composer\Json\JsonFile;
13
use Mediact\TestingSuite\Composer\ConfigResolver;
14
15
/**
16
 * @SuppressWarnings(PHPMD.ShortVariable)
17
 * @SuppressWarnings(PHPMD.StaticAccess)
18
 */
19
class ConfigInstaller implements InstallerInterface
20
{
21
    /** @var JsonFile */
22
    private $file;
23
24
    /** @var ConfigResolver */
25
    private $resolver;
26
27
    /** @var IOInterface */
28
    private $io;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param ConfigResolver $resolver
34
     * @param IOInterface    $io
35
     * @param JsonFile|null  $file
36
     */
37 1
    public function __construct(
38
        ConfigResolver $resolver,
39
        IOInterface $io,
40
        JsonFile $file = null
41
    ) {
42 1
        $this->resolver = $resolver;
43 1
        $this->io       = $io;
44 1
        $this->file     = $file ?? new JsonFile(Factory::getComposerFile());
45 1
    }
46
47
    /**
48
     * Install.
49
     *
50
     * @return void
51
     */
52 1
    public function install()
53
    {
54 1
        $definition = $this->file->read();
55 1
        $config     = $definition['config'] ?? [];
56
57 1
        $config = array_replace_recursive(
58 1
            $this->resolver->resolve(),
59 1
            $config
60
        );
61
62 1
        $definition['config'] = $config;
63 1
        $this->file->write($definition);
64 1
    }
65
}
66