ConfigResolver::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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