Factory::select()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 11
ccs 5
cts 5
cp 1
crap 4
rs 9.9666
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