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

GrumPhpInstaller   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 59
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B install() 0 25 3
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Mediact\TestingSuite\Composer\Installer;
8
9
use Composer\Factory;
10
use Composer\IO\IOInterface;
11
use Composer\Json\JsonFile;
12
13
class GrumPhpInstaller implements InstallerInterface
14
{
15
    /** @var JsonFile */
16
    private $file;
17
18
    /** @var IOInterface */
19
    private $io;
20
21
    /** @var string */
22
    private $destination;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param IOInterface|null $io
28
     * @param JsonFile         $file
29
     * @param string|null      $destination
30
     */
31
    public function __construct(
32
        IOInterface $io,
33
        JsonFile $file = null,
34
        string $destination = null
35
    ) {
36
        $this->file        = $file;
37
        $this->io          = $io;
38
        $this->file        = $file ?? new JsonFile(Factory::getComposerFile());
39
        $this->destination = $destination ?? getcwd();
40
    }
41
42
    /**
43
     * Install.
44
     *
45
     * @return void
46
     */
47
    public function install()
48
    {
49
        $grumPhpFile = $this->destination . '/grumphp.yml';
50
51
        if (file_exists($grumPhpFile)) {
52
            unlink($grumPhpFile);
53
            $this->io->write(
54
                sprintf(
55
                    '<comment>Removed:</comment> existing GrumPHP config file %s',
56
                    $grumPhpFile
57
                )
58
            );
59
        }
60
61
        $definition = $this->file->read();
62
        if (!empty($definition['extra']['grumphp']['config-default-path'])) {
63
            return;
64
        }
65
66
        $definition['extra']['grumphp']['config-default-path'] =
67
            'vendor/mediact/testing-suite/config/default/grumphp.yml';
68
69
        $this->file->write($definition);
70
        $this->io->write(
71
            '<info>Added:</info> GrumPHP config to composer.json'
72
        );
73
    }
74
}
75