Factory::getClass()   C
last analyzed

Complexity

Conditions 14
Paths 10

Size

Total Lines 54
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 43
CRAP Score 14

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 14
eloc 37
nc 10
nop 1
dl 0
loc 54
ccs 43
cts 43
cp 1
crap 14
rs 6.2666
c 1
b 0
f 1

How to fix   Long Method    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 23
    public function __construct(?Interfaces\IFLTranslations $lang = null)
24
    {
25 23
        $this->setFlLang($lang);
26
    }
27
28
    /**
29
     * @param mixed $param
30
     * @throws PathsException
31
     * @throws FilesException
32
     * @return CompositeAdapter
33
     */
34 23
    public function getClass($param): CompositeAdapter
35
    {
36 23
        if (is_string($param)) {
37 2
            return new CompositeAdapter(
38 2
                new Processing\Volume\ProcessNode($param, $this->flLang),
39 2
                new Processing\Volume\ProcessDir($param, $this->flLang),
40 2
                new Processing\Volume\ProcessFile($param, $this->flLang),
41 2
                new Processing\Volume\ProcessFile($param, $this->flLang)
42 2
            );
43
44 21
        } elseif (is_array($param)) {
45 10
            if (isset($param['files'])) {
46 1
                return $this->getClass($param['files']);
47
            }
48 10
            if (isset($param['path']) && is_string($param['path'])) {
49 1
                return new CompositeAdapter(
50 1
                    new Processing\Volume\ProcessNode($param['path'], $this->flLang),
51 1
                    new Processing\Volume\ProcessDir($param['path'], $this->flLang),
52 1
                    new Processing\Volume\ProcessFile($param['path'], $this->flLang),
53 1
                    new Processing\Volume\ProcessFile($param['path'], $this->flLang)
54 1
                );
55
56 9
            } elseif (isset($param['source']) && is_string($param['source'])) {
57 1
                return new CompositeAdapter(
58 1
                    new Processing\Volume\ProcessNode($param['source'], $this->flLang),
59 1
                    new Processing\Volume\ProcessDir($param['source'], $this->flLang),
60 1
                    new Processing\Volume\ProcessFile($param['source'], $this->flLang),
61 1
                    new Processing\Volume\ProcessFile($param['source'], $this->flLang)
62 1
                );
63
64 8
            } elseif (isset($param['source']) && is_object($param['source']) && ($param['source'] instanceof IStorage)) {
65 8
                return new CompositeAdapter(
66 8
                    new Processing\Storage\ProcessNode($param['source'], $this->flLang),
67 8
                    new Processing\Storage\ProcessDir($param['source'], $this->flLang),
68 8
                    new Processing\Storage\ProcessFile($param['source'], $this->flLang),
69 8
                    new Processing\Storage\ProcessFileStream($param['source'], $this->flLang)
70 8
                );
71
            }
72
73 11
        } elseif (is_object($param)) {
74 8
            if ($param instanceof CompositeAdapter) {
75 1
                return $param;
76
77 7
            } elseif ($param instanceof IStorage) {
78 6
                return new CompositeAdapter(
79 6
                    new Processing\Storage\ProcessNode($param, $this->flLang),
80 6
                    new Processing\Storage\ProcessDir($param, $this->flLang),
81 6
                    new Processing\Storage\ProcessFile($param, $this->flLang),
82 6
                    new Processing\Storage\ProcessFileStream($param, $this->flLang)
83 6
                );
84
            }
85
        }
86
87 11
        throw new FilesException($this->getFlLang()->flNoAvailableClasses());
88
    }
89
}
90