ConfigFactory   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 1
eloc 11
c 3
b 0
f 0
dl 0
loc 22
ccs 4
cts 4
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 5 1
1
<?php
2
/**
3
 * Composer plugin for config assembling
4
 *
5
 * @link      https://github.com/hiqdev/composer-config-plugin
6
 * @package   composer-config-plugin
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\composer\config\configs;
12
13
use hiqdev\composer\config\Builder;
14
15
/**
16
 * Config factory creates Config object of proper class
17
 * according to config name (and mayby other options later).
18
 *
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class ConfigFactory
22
{
23
    private static $knownTypes = [
24
        '__rebuild'     => Rebuild::class,
25
        '__files'       => System::class,
26
        'aliases'       => System::class,
27
        'packages'      => System::class,
28
        'dotenv'        => DotEnv::class,
29
        'params'        => Params::class,
30
        'defines'       => Defines::class,
31
    ];
32
33
    /**
34
     * @param Builder $builder
35
     * @param string $name
36
     * @return Config
37 1
     */
38
    public static function create(Builder $builder, string $name): Config
39 1
    {
40 1
        $class = static::$knownTypes[$name] ?? Config::class;
0 ignored issues
show
Bug introduced by
Since $knownTypes is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $knownTypes to at least protected.
Loading history...
41 1
42
        return new $class($builder, $name);
43 1
    }
44
}
45