Passed
Push — master ( af3dcf...3709c1 )
by Petr
02:16
created

Factory::getSource()   B

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