Passed
Push — master ( cb2d88...e8a992 )
by Petr
08:25
created

Factory::getClass()   C

Complexity

Conditions 12
Paths 8

Size

Total Lines 43
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 12
eloc 28
nc 8
nop 1
dl 0
loc 43
ccs 29
cts 29
cp 1
crap 12
rs 6.9666
c 1
b 0
f 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace kalanis\kw_files\Access;
4
5
6
use kalanis\kw_files\FilesException;
7
use kalanis\kw_files\Interfaces;
8
use kalanis\kw_files\Processing;
9
use kalanis\kw_files\Traits\TLang;
10
use kalanis\kw_paths\PathsException;
11
use kalanis\kw_storage\Interfaces\IStorage;
12
13
14
/**
15
 * Class Factory
16
 * @package kalanis\kw_files\Access
17
 * Create Composite access to storage
18
 */
19
class Factory
20
{
21
    use TLang;
22
23 22
    public function __construct(?Interfaces\IFLTranslations $lang = null)
24
    {
25 22
        $this->setLang($lang);
26 22
    }
27
28
    /**
29
     * @param string|array<string|int, string|int|float|bool|object>|object $param
30
     * @throws PathsException
31
     * @throws FilesException
32
     * @return CompositeAdapter
33
     */
34 22
    public function getClass($param): CompositeAdapter
35
    {
36 22
        if (is_string($param)) {
37 2
            return new CompositeAdapter(
38 2
                new Processing\Volume\ProcessNode($param, $this->lang),
39 2
                new Processing\Volume\ProcessDir($param, $this->lang),
40 2
                new Processing\Volume\ProcessFile($param, $this->lang)
41
            );
42
43 20
        } elseif (is_array($param)) {
44 10
            if (isset($param['path']) && is_string($param['path'])) {
45 1
                return new CompositeAdapter(
46 1
                    new Processing\Volume\ProcessNode($param['path'], $this->lang),
47 1
                    new Processing\Volume\ProcessDir($param['path'], $this->lang),
48 1
                    new Processing\Volume\ProcessFile($param['path'], $this->lang)
49
                );
50
51 9
            } elseif (isset($param['source']) && is_string($param['source'])) {
52 1
                return new CompositeAdapter(
53 1
                    new Processing\Volume\ProcessNode($param['source'], $this->lang),
54 1
                    new Processing\Volume\ProcessDir($param['source'], $this->lang),
55 1
                    new Processing\Volume\ProcessFile($param['source'], $this->lang)
56
                );
57
58 8
            } elseif (isset($param['source']) && is_object($param['source']) && ($param['source'] instanceof IStorage)) {
59 1
                return new CompositeAdapter(
60 1
                    new Processing\Storage\ProcessNode($param['source'], $this->lang),
61 1
                    new Processing\Storage\ProcessDir($param['source'], $this->lang),
62 8
                    new Processing\Storage\ProcessFile($param['source'], $this->lang)
63
                );
64
            }
65
66 10
        } elseif (is_object($param)) {
67 7
            if ($param instanceof IStorage) {
68 6
                return new CompositeAdapter(
69 6
                    new Processing\Storage\ProcessNode($param, $this->lang),
70 6
                    new Processing\Storage\ProcessDir($param, $this->lang),
71 6
                    new Processing\Storage\ProcessFile($param, $this->lang)
72
                );
73
            }
74
        }
75
76 11
        throw new FilesException($this->getLang()->flNoAvailableClasses());
77
    }
78
}
79