Factory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLoader() 0 8 2
A select() 0 11 4
1
<?php
2
3
namespace kalanis\kw_input\Parsers;
4
5
6
use kalanis\kw_input\Interfaces\IEntry;
7
8
9
/**
10
 * Class Factory
11
 * @package kalanis\kw_input\Loaders
12
 * Loading factory
13
 */
14
class Factory
15
{
16
    /** @var AParser[] */
17
    protected static array $loaders;
18
19 4
    public function getLoader(string $source): AParser
20
    {
21 4
        if (isset(static::$loaders[$source])) {
22 3
            return static::$loaders[$source];
23
        }
24 3
        $loader = $this->select($source);
25 3
        static::$loaders[$source] = $loader;
26 3
        return $loader;
27
    }
28
29 1
    protected function select(string $source): AParser
30
    {
31
        switch ($source) {
32
            case IEntry::SOURCE_CLI:
33 1
                return new Cli();
34
            case IEntry::SOURCE_JSON:
35 1
                return new Json();
36
            case IEntry::SOURCE_FILES:
37 1
                return new Files();
38
            default:
39 1
                return new Basic();
40
        }
41
    }
42
}
43