Factory::getSource()   B
last analyzed

Complexity

Conditions 9
Paths 8

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 14
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 21
ccs 15
cts 15
cp 1
crap 9
rs 8.0555
1
<?php
2
3
namespace kalanis\kw_menu\EntriesSource;
4
5
6
use kalanis\kw_files\Access\CompositeAdapter;
7
use kalanis\kw_files\FilesException;
8
use kalanis\kw_menu\Interfaces\IEntriesSource;
9
use kalanis\kw_menu\Interfaces\IMNTranslations;
10
use kalanis\kw_menu\MenuException;
11
use kalanis\kw_menu\Traits\TLang;
12
use kalanis\kw_paths\PathsException;
13
use kalanis\kw_storage\Interfaces\IStorage;
14
use kalanis\kw_tree\Interfaces\ITree;
15
16
17
/**
18
 * Class Factory
19
 * @package kalanis\kw_menu\EntriesSource
20
 * Entries source is in parsed via class
21
 */
22
class Factory
23
{
24
    use TLang;
25
26 10
    public function __construct(?IMNTranslations $lang = null)
27
    {
28 10
        $this->setMnLang($lang);
29 10
    }
30
31
    /**
32
     * @param mixed $params
33
     * @throws FilesException
34
     * @throws MenuException
35
     * @throws PathsException
36
     * @return IEntriesSource
37
     */
38 10
    public function getSource($params): IEntriesSource
39
    {
40 10
        if (is_object($params)) {
41 6
            if ($params instanceof IEntriesSource) {
42 1
                return $params;
43
            }
44 5
            if ($params instanceof ITree) {
45 1
                return new Tree($params);
46
            }
47 4
            if ($params instanceof CompositeAdapter) {
48 1
                return new Files($params);
49
            }
50 3
            if ($params instanceof IStorage) {
51 3
                return new Storage($params);
52
            }
53 6
        } elseif (is_array($params) && isset($params['source'])) {
54 3
            return $this->getSource($params['source']);
55 4
        } elseif (is_string($params)) {
56 4
            return new Volume($params);
57
        }
58 1
        throw new MenuException($this->getMnLang()->mnNoAvailableEntrySource());
59
    }
60
}
61