Data::setData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 20
ccs 10
cts 10
cp 1
crap 1
rs 9.9666

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace kalanis\UploadPerPartes\Uploader;
4
5
6
/**
7
 * Class Data
8
 * @package kalanis\UploadPerPartes\Uploader
9
 * Driver metadata about processed file
10
 */
11
final class Data
12
{
13
    public string $tempDir = '';
14
    public string $tempName = '';
15
    public string $targetDir = '';
16
    public string $targetName = '';
17
    /** @var int<0, max> */
18
    public int $fileSize = 0;
19
    /** @var int<0, max> */
20
    public int $partsCount = 0;
21
    /** @var int<0, max> */
22
    public int $bytesPerPart = 0;
23
    /** @var int<0, max> */
24
    public int $lastKnownPart = 0;
25
26
    /**
27
     * @param string $tempDir
28
     * @param string $tempName
29
     * @param string $targetDir
30
     * @param string $targetName
31
     * @param int<0, max> $fileSize
32
     * @param int<0, max> $partsCount
33
     * @param int<0, max> $bytesPerPart
34
     * @param int<0, max> $lastKnownPart
35
     * @return $this
36
     */
37 26
    public function setData(
38
        string $tempDir,
39
        string $tempName,
40
        string $targetDir,
41
        string $targetName,
42
        int $fileSize,
43
        int $partsCount = 0,
44
        int $bytesPerPart = 0,
45
        int $lastKnownPart = 0
46
    ): self
47
    {
48 26
        $this->tempDir = $tempDir; // where it is during upload
49 26
        $this->tempName = $tempName; // what it is during upload
50 26
        $this->targetDir = $targetDir; // where it will be stored
51 26
        $this->targetName = $targetName; // what name it will have after upload
52 26
        $this->fileSize = max(0, $fileSize); // final size
53 26
        $this->partsCount = max(0, $partsCount); // is on parts...
54 26
        $this->bytesPerPart = max(0, $bytesPerPart); // how long is single part
55 26
        $this->lastKnownPart = max(0, $lastKnownPart); // how many parts has been obtained
56 26
        return $this;
57
    }
58
59 19
    public function clear(): self
60
    {
61 19
        $this->fileSize = max(0, $this->fileSize);
62 19
        $this->partsCount = max(0, $this->partsCount);
63 19
        $this->bytesPerPart = max(0, $this->bytesPerPart);
64 19
        $this->lastKnownPart = max(0, $this->lastKnownPart);
65 19
        return $this;
66
    }
67
}
68