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\Loaders;
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 ALoader[] */
17
    protected array $loaders;
18
19 4
    public function getLoader(string $source): ALoader
20
    {
21 4
        if (isset($this->loaders[$source])) {
22 1
            return $this->loaders[$source];
23
        }
24 4
        $loader = $this->select($source);
25 4
        $this->loaders[$source] = $loader;
26 4
        return $loader;
27
    }
28
29 4
    protected function select(string $source): ALoader
30
    {
31
        switch ($source) {
32
            case IEntry::SOURCE_FILES:
33 2
                return new File();
34
            case IEntry::SOURCE_JSON:
35 1
                return new Json();
36
            case IEntry::SOURCE_CLI:
37 2
                return new CliEntry();
38
            default:
39 4
                return new Entry();
40
        }
41
    }
42
}
43