File::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

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

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 BackblazeB2;
4
5
class File implements \JsonSerializable
6
{
7
    protected $id;
8
    protected $name;
9
    protected $hash;
10
    protected $size;
11
    protected $type;
12
    protected $info;
13
    protected $bucketId;
14
    protected $action;
15
    protected $uploadTimestamp;
16
17
    /**
18
     * File constructor.
19
     *
20
     * @param $id
21
     * @param $name
22
     * @param $hash
23
     * @param $size
24
     * @param $type
25
     * @param $info
26
     * @param $bucketId
27
     * @param $action
28
     * @param $uploadTimestamp
29
     */
30 8
    public function __construct($id, $name, $hash = null, $size = null, $type = null, $info = null, $bucketId = null, $action = null, $uploadTimestamp = null)
31
    {
32 8
        $this->id = $id;
33 8
        $this->name = $name;
34 8
        $this->hash = $hash;
35 8
        $this->size = $size;
36 8
        $this->type = $type;
37 8
        $this->info = $info;
38 8
        $this->bucketId = $bucketId;
39 8
        $this->action = $action;
40 8
        $this->uploadTimestamp = $uploadTimestamp;
41 8
    }
42
43
    /**
44
     * @return array
45
     * */
46
    public function jsonSerialize(): mixed
47
    {
48
        return [
49
            'id'              => $this->getId(),
50
            'name'            => $this->getName(),
51
            'hash'            => $this->getHash(),
52
            'size'            => $this->getSize(),
53
            'type'            => $this->getType(),
54
            'info'            => $this->getInfo(),
55
            'bucketId'        => $this->getBucketId(),
56
            'action'          => $this->getAction(),
57
            'uploadTimestamp' => $this->getUploadTimestamp(),
58
        ];
59
    }
60
61
    /**
62
     * @return string
63
     */
64 1
    public function getId()
65
    {
66 1
        return $this->id;
67
    }
68
69
    /**
70
     * @return string
71
     */
72 2
    public function getName()
73
    {
74 2
        return $this->name;
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getHash()
81
    {
82
        return $this->hash;
83
    }
84
85
    /**
86
     * @return int
87
     */
88
    public function getSize()
89
    {
90
        return $this->size;
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public function getType()
97
    {
98
        return $this->type;
99
    }
100
101
    /**
102
     * @return array
103
     */
104
    public function getInfo()
105
    {
106
        return $this->info;
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public function getBucketId()
113
    {
114
        return $this->bucketId;
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getAction()
121
    {
122
        return $this->action;
123
    }
124
125
    /**
126
     * @return string
127
     */
128
    public function getUploadTimestamp()
129
    {
130
        return $this->uploadTimestamp;
131
    }
132
}
133