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

Config   A

Complexity

Total Complexity 40

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 86
c 1
b 0
f 0
dl 0
loc 142
rs 9.2
wmc 40

1 Method

Rating   Name   Duplication   Size   Complexity  
F __construct() 0 105 40

How to fix   Complexity   

Complex Class

Complex classes like Config often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Config, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace kalanis\UploadPerPartes\Uploader;
4
5
6
use kalanis\UploadPerPartes\Interfaces;
7
use kalanis\UploadPerPartes\Target\Local;
8
use kalanis\UploadPerPartes\Target\Local\DrivingFile;
9
10
11
/**
12
 * Class Config
13
 * @package kalanis\UploadPerPartes\Uploader
14
 * Configuration of the whole uploader
15
 */
16
final class Config
17
{
18
    /** @var int<0, max> */
19
    public int $bytesPerPart = 0;
20
    public bool $canContinue = true;
21
    public string $tempDir = '';
22
    public string $targetDir = '';
23
    /** @var string|Interfaces\IUppTranslations|null */
24
    public $lang = null;
25
    /** @var string|Interfaces\IOperations|null */
26
    public $target = null;
27
    /** @var string|DrivingFile\DataEncoders\AEncoder|null */
28
    public $dataEncoder = null;
29
    /** @var string|DrivingFile\DataModifiers\AModifier|null */
30
    public $dataModifier = null;
31
    /** @var string|DrivingFile\KeyEncoders\AEncoder|null */
32
    public $keyEncoder = null;
33
    /** @var string|DrivingFile\KeyModifiers\AModifier|null */
34
    public $keyModifier = null;
35
    /** @var int|string|object|null */
36
    public $drivingFileStorage = null;
37
    /** @var int|string|object|null */
38
    public $temporaryStorage = null;
39
    /** @var string|Local\TemporaryStorage\KeyEncoders\AEncoder|null */
40
    public $temporaryEncoder = null;
41
    /** @var int|string|object|null */
42
    public $finalStorage = null;
43
    /** @var string|Local\FinalStorage\KeyEncoders\AEncoder|null */
44
    public $finalEncoder = null;
45
    /** @var string|null */
46
    public ?string $checksum = null;
47
    /** @var string|null */
48
    public ?string $decoder = null;
49
50
    /**
51
     * @param array<string, string|int|bool|object|array<string|int|bool|object>|null> $params
52
     */
53
    public function __construct(array $params)
54
    {
55
        if (isset($params['calc_size'])) {
56
            $this->bytesPerPart = max(1, intval($params['calc_size']));
57
        }
58
        if (isset($params['temp_location'])) {
59
            $this->tempDir = strval($params['temp_location']);
60
        }
61
        if (isset($params['target_location'])) {
62
            $this->targetDir = strval($params['target_location']);
63
        }
64
        if (isset($params['lang'])) {
65
            if (is_object($params['lang'])) {
66
                if ($params['lang'] instanceof Interfaces\IUppTranslations) {
67
                    $this->lang = $params['lang'];
68
                }
69
            } else {
70
                $this->lang = strval($params['lang']);
71
            }
72
        }
73
        if (isset($params['target'])) {
74
            if (is_object($params['target'])) {
75
                if ($params['target'] instanceof Interfaces\IOperations) {
76
                    $this->target = $params['target'];
77
                }
78
            } else {
79
                $this->target = strval($params['target']);
80
            }
81
        }
82
        if (isset($params['data_encoder'])) {
83
            if (is_object($params['data_encoder'])) {
84
                if ($params['data_encoder'] instanceof DrivingFile\DataEncoders\AEncoder) {
85
                    $this->dataEncoder = $params['data_encoder'];
86
                }
87
            } else {
88
                $this->dataEncoder = strval($params['data_encoder']);
89
            }
90
        }
91
        if (isset($params['data_modifier'])) {
92
            if (is_object($params['data_modifier'])) {
93
                if ($params['data_modifier'] instanceof DrivingFile\DataModifiers\AModifier) {
94
                    $this->dataModifier = $params['data_modifier'];
95
                }
96
            } else {
97
                $this->dataModifier = strval($params['data_modifier']);
98
            }
99
        }
100
        if (isset($params['key_encoder'])) {
101
            if (is_object($params['key_encoder'])) {
102
                if ($params['key_encoder'] instanceof DrivingFile\KeyEncoders\AEncoder) {
103
                    $this->keyEncoder = $params['key_encoder'];
104
                }
105
            } else {
106
                $this->keyEncoder = strval($params['key_encoder']);
107
            }
108
        }
109
        if (isset($params['key_modifier'])) {
110
            if (is_object($params['key_modifier'])) {
111
                if ($params['key_modifier'] instanceof DrivingFile\KeyModifiers\AModifier) {
112
                    $this->keyModifier = $params['key_modifier'];
113
                }
114
            } else {
115
                $this->keyModifier = strval($params['key_modifier']);
116
            }
117
        }
118
        if (isset($params['driving_file'])) {
119
            if (!is_array($params['driving_file']) && !is_bool($params['driving_file'])) {
120
                $this->drivingFileStorage = $params['driving_file'];
121
            }
122
        }
123
        if (isset($params['temp_storage'])) {
124
            if (!is_array($params['temp_storage']) && !is_bool($params['temp_storage'])) {
125
                $this->temporaryStorage = $params['temp_storage'];
126
            }
127
        }
128
        if (isset($params['temp_encoder'])) {
129
            if (is_object($params['temp_encoder'])) {
130
                if ($params['temp_encoder'] instanceof Local\TemporaryStorage\KeyEncoders\AEncoder) {
131
                    $this->temporaryEncoder = $params['temp_encoder'];
132
                }
133
            } else {
134
                $this->temporaryEncoder = strval($params['temp_encoder']);
135
            }
136
        }
137
        if (isset($params['final_storage'])) {
138
            if (!is_array($params['final_storage']) && !is_bool($params['final_storage'])) {
139
                $this->finalStorage = $params['final_storage'];
140
            }
141
        }
142
        if (isset($params['final_encoder'])) {
143
            if (is_object($params['final_encoder'])) {
144
                if ($params['final_encoder'] instanceof Local\FinalStorage\KeyEncoders\AEncoder) {
145
                    $this->finalEncoder = $params['final_encoder'];
146
                }
147
            } else {
148
                $this->finalEncoder = strval($params['final_encoder']);
149
            }
150
        }
151
        if (isset($params['checksum'])) {
152
            $this->checksum = strval($params['checksum']);
153
        }
154
        if (isset($params['decoder'])) {
155
            $this->decoder = strval($params['decoder']);
156
        }
157
        $this->canContinue = isset($params['can_continue']) ? boolval(intval(strval($params['can_continue']))) : true;
158
    }
159
}
160