AbstractConsoleConfigFactory::invokeDir()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of PhpUnitGen.
5
 *
6
 * (c) 2017-2018 Paul Thébaud <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpUnitGen\Configuration;
13
14
use PhpUnitGen\Configuration\ConfigurationInterface\ConsoleConfigInterface;
15
use PhpUnitGen\Exception\InvalidConfigException;
16
17
/**
18
 * Class AbstractConsoleConfigFactory.
19
 *
20
 * @author     Paul Thébaud <[email protected]>.
21
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
22
 * @license    https://opensource.org/licenses/MIT The MIT license.
23
 * @link       https://github.com/paul-thebaud/phpunit-generator
24
 * @since      Class available since Release 2.0.0.
25
 */
26
abstract class AbstractConsoleConfigFactory
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function invoke(string $configPath): ConsoleConfigInterface
32
    {
33
        return new ConsoleConfig($this->decode($configPath));
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function invokeDir(string $configPath, string $sourceDir, string $targetDir): ConsoleConfigInterface
40
    {
41
        $configArray          = $this->decode($configPath);
42
        $configArray['dirs']  = [
43
            $sourceDir => $targetDir
44
        ];
45
        $configArray['files'] = [];
46
47
        return new ConsoleConfig($configArray);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function invokeFile(string $configPath, string $sourceFile, string $targetFile): ConsoleConfigInterface
54
    {
55
        $configArray          = $this->decode($configPath);
56
        $configArray['dirs']  = [];
57
        $configArray['files'] = [
58
            $sourceFile => $targetFile
59
        ];
60
61
        return new ConsoleConfig($configArray);
62
    }
63
64
    /**
65
     * Decode a configuration file to get a configuration array.
66
     *
67
     * @param string $configPath The configuration file path.
68
     *
69
     * @return array The decoded configuration array.
70
     *
71
     * @throws InvalidConfigException If the configuration is invalid.
72
     */
73
    abstract protected function decode(string $configPath): array;
74
}
75