Passed
Pull Request — master (#14)
by Klaas
05:22
created

ConfigResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 36
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A resolve() 0 9 2
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Mediact\TestingSuite\Composer;
8
9
class ConfigResolver
10
{
11
    /** @var ProjectTypeResolver */
12
    private $typeResolver;
13
14
    /** @var string */
15
    private $template = __DIR__  . '/../templates/config/%s.json';
16
17
    /**
18
     * Constructor.
19
     *
20
     * @param ProjectTypeResolver $typeResolver
21
     * @param string              $template
22
     */
23 1
    public function __construct(
24
        ProjectTypeResolver $typeResolver,
25
        string $template = null
26
    ) {
27 1
        $this->typeResolver = $typeResolver;
28 1
        $this->template     = $template ?? $this->template;
29 1
    }
30
31
    /**
32
     * Resolve config.
33
     *
34
     * @return string[]
35
     */
36 1
    public function resolve(): array
37
    {
38 1
        $file = sprintf($this->template, $this->typeResolver->resolve());
39
40 1
        if (!file_exists($file)) {
41 1
            $file = sprintf($this->template, 'default');
42
        }
43
44 1
        return json_decode(file_get_contents($file), true);
45
    }
46
}
47