Test Failed
Push — master ( e493d7...b1ea68 )
by Petr
11:01
created

Factory::getStorage()   B

Complexity

Conditions 10
Paths 11

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 21
c 1
b 0
f 0
nc 11
nop 1
dl 0
loc 32
rs 7.6666

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\UploadPerPartes\Target\Local\DrivingFile\Storage;
4
5
6
use kalanis\kw_files\Access\CompositeAdapter;
7
use kalanis\kw_paths\ArrayPath;
8
use kalanis\kw_paths\PathsException;
9
use kalanis\kw_storage\Interfaces\IStorage;
10
use kalanis\UploadPerPartes\Interfaces\IDrivingFile;
11
use kalanis\UploadPerPartes\Traits\TLangInit;
12
use kalanis\UploadPerPartes\Uploader\Config;
13
use kalanis\UploadPerPartes\UploadException;
14
15
16
/**
17
 * Class Factory
18
 * @package kalanis\UploadPerPartes\Target\Local\DrivingFile\Storage
19
 * Key data storage - Factory to get where to store info data
20
 */
21
class Factory
22
{
23
    use TLangInit;
24
25
    public const FORMAT_VOLUME = 1;
26
    public const FORMAT_STORAGE = 2;
27
    public const FORMAT_FILES = 3;
28
    public const FORMAT_REDIS = 4;
29
    public const FORMAT_PREDIS = 5;
30
    public const FORMAT_CLIENT = 6;
31
32
    /**
33
     * @param Config $config
34
     * @throws UploadException
35
     * @return IDrivingFile
36
     */
37
    public function getStorage(Config $config): IDrivingFile
38
    {
39
        if ($config->drivingFileStorage instanceof IDrivingFile) {
40
            return $config->drivingFileStorage;
41
        }
42
        if ($config->drivingFileStorage instanceof IStorage) {
43
            return new Storage($config->drivingFileStorage, $config->tempDir, $this->getUppLang());
44
        }
45
        if ($config->drivingFileStorage instanceof CompositeAdapter) {
46
            try {
47
                $ap = new ArrayPath();
48
                return new Files($config->drivingFileStorage, $ap->setString($config->tempDir)->getArray(), $ap, $this->getUppLang());
49
                // @codeCoverageIgnoreStart
50
            } catch (PathsException $ex) {
51
                throw new UploadException($ex->getMessage(), $ex->getCode(), $ex);
52
            }
53
            // @codeCoverageIgnoreEnd
54
        }
55
56
        switch ($config->drivingFileStorage) {
57
            case 'volume':
58
            case self::FORMAT_VOLUME:
59
                return new Volume($config->tempDir, $this->getUppLang());
60
            case 'client':
61
            case self::FORMAT_CLIENT:
62
                return new Client($this->getUppLang());
63
            default:
64
                if (is_string($config->drivingFileStorage)) {
65
                    return new Volume($config->drivingFileStorage, $this->getUppLang());
66
                }
67
68
                throw new UploadException($this->getUppLang()->uppDriveFileStorageNotSet());
69
        }
70
    }
71
}
72