Factory::getLoader()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 2
rs 10
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