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

Factory   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 31
dl 0
loc 58
ccs 32
cts 32
cp 1
rs 10
c 1
b 0
f 1
wmc 13

2 Methods

Rating   Name   Duplication   Size   Complexity  
C getClass() 0 43 12
A __construct() 0 3 1
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