Config   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 59
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConverter() 0 3 1
A getConverterClasses() 0 3 1
A registerConverter() 0 6 1
A unregisterConverter() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Murtukov\PHPCodeGenerator;
6
7
/**
8
 * Static config to be used by all generator components.
9
 */
10
class Config
11
{
12
    public static string $indent = '    ';
13
    public static bool $shortenQualifiers = true;
14
    public static bool $manageUseStatements = true;
15
    public static string $suppressSymbol = '@';
16
17
    /**
18
     * @var ConverterInterface[]
19
     */
20
    private static array $customStringifiers = [
21
        // e.g.: 'App\Stringifiers\ExpressionStringifier' => object,
22
    ];
23
24
    /**
25
     * A map of FCQNs and their types registered as custom stringifiers.
26
     */
27
    private static array $customStringifiersTypeMap = [
28
        // e.g.: 'string' => [App\Stringifiers\ExpressionStringifier, App\Stringifiers\AnotherStringifier],
29
    ];
30
31
    /**
32
     * Registers user defined stringifiers.
33
     */
34 1
    public static function registerConverter(ConverterInterface $converter, string $type)
35
    {
36 1
        $fqcn = get_class($converter);
37
38 1
        self::$customStringifiers[$fqcn] = $converter;
39 1
        self::$customStringifiersTypeMap[$type][] = $fqcn;
40 1
    }
41
42
    /**
43
     * Unregister a previously registered custom stringifier.
44
     *
45
     * @param string $fqcn - Fully qualified class name
46
     */
47 1
    public static function unregisterConverter(string $fqcn)
48
    {
49
        // Remove instance
50 1
        unset(self::$customStringifiers[$fqcn]);
51
        // Remove map entry
52 1
        $type = array_search($fqcn, self::$customStringifiersTypeMap);
53 1
        unset(self::$customStringifiersTypeMap[$type]);
54 1
    }
55
56
    /**
57
     * Returns an instance of registered custom stringifier.
58
     *
59
     * @return ConverterInterface|null
60
     */
61 1
    public static function getConverter(string $fqcn): ?object
62
    {
63 1
        return self::$customStringifiers[$fqcn] ?? null;
64
    }
65
66 1
    public static function getConverterClasses(string $type): ?array
67
    {
68 1
        return self::$customStringifiersTypeMap[$type] ?? [];
69
    }
70
}
71