CreateItemRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
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 9
dl 0
loc 19
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 App\Request;
4
5
use Ramsey\Uuid\UuidInterface;
6
use Ramsey\Uuid\Uuid;
7
use Symfony\Component\Validator\Constraints as Assert;
8
use JMS\Serializer\Annotation\Type;
9
10
class CreateItemRequest
11
{
12
    /**
13
     * @var string
14
     * @Type("string")
15
     * @Assert\NotBlank()
16
     * @Assert\Length(max=255)
17
     */
18
    private $name;
19
    /**
20
     * @var string
21
     * @Type("string")
22
     * @Assert\NotBlank()
23
     * @Assert\Uuid()
24
     */
25
    private $categoryId;
26
    /**
27
     * @var int
28
     * @Type("int")
29
     * @Assert\Length(max=255)
30
     */
31
    private $year;
32
    /**
33
     * @var string
34
     * @Type("string")
35
     * @Assert\Length(max=255)
36
     */
37
    private $format;
38
    /**
39
     * @var string
40
     * @Type("string")
41
     * @Assert\Length(max=255)
42
     */
43
    private $author;
44
    /**
45
     * @var string
46
     * @Type("string")
47
     * @Assert\Length(max=255)
48
     */
49
    private $publisher;
50
    /**
51
     * @var string
52
     * @Type("string")
53
     * @Assert\Length(max=255)
54
     */
55
    private $description;
56
    /**
57
     * @var string
58
     * @Type("string")
59
     * @Assert\Length(max=255)
60
     */
61
    private $store;
62
    /**
63
     * @var string
64
     * @Type("string")
65
     * @Assert\Length(max=255)
66
     */
67
    private $url;
68
69
    /**
70
     * CreateItemRequest constructor.
71
     * @param string $name
72
     * @param string $categoryId
73
     * @param int $year
74
     * @param string $format
75
     * @param string $author
76
     * @param string $publisher
77
     * @param string $description
78
     * @param string $store
79
     * @param string $url
80
     */
81 1
    public function __construct(string $name,
82
                                string $categoryId,
83
                                int $year,
84
                                string $format,
85
                                string $author,
86
                                string $publisher,
87
                                string $description,
88
                                string $store,
89
                                string $url)
90
    {
91 1
        $this->name = $name;
92 1
        $this->categoryId = $categoryId;
93 1
        $this->year = $year;
94 1
        $this->format = $format;
95 1
        $this->author = $author;
96 1
        $this->publisher = $publisher;
97 1
        $this->description = $description;
98 1
        $this->store = $store;
99 1
        $this->url = $url;
100 1
    }
101
102
    /**
103
     * @return string
104
     */
105 1
    public function getName(): string
106
    {
107 1
        return $this->name;
108
    }
109
110
    /**
111
     * @return UuidInterface
112
     */
113 1
    public function getCategoryId(): UuidInterface
114
    {
115 1
        return Uuid::fromString($this->categoryId);
116
    }
117
118
    /**
119
     * @return ?int
120
     */
121 1
    public function getYear(): ?int
122
    {
123 1
        return $this->year;
124
    }
125
126
    /**
127
     * @return ?string
128
     */
129 1
    public function getFormat(): ?string
130
    {
131 1
        return $this->format;
132
    }
133
134
    /**
135
     * @return ?string
136
     */
137 1
    public function getAuthor(): ?string
138
    {
139 1
        return $this->author;
140
    }
141
142
    /**
143
     * @return ?string
144
     */
145 1
    public function getPublisher(): ?string
146
    {
147 1
        return $this->publisher;
148
    }
149
150
    /**
151
     * @return ?string
152
     */
153 1
    public function getDescription(): ?string
154
    {
155 1
        return $this->description;
156
    }
157
158
    /**
159
     * @return ?string
160
     */
161 1
    public function getStore(): ?string
162
    {
163 1
        return $this->store;
164
    }
165
166
    /**
167
     * @return ?string
168
     */
169 1
    public function getUrl(): ?string
170
    {
171 1
        return $this->url;
172
    }
173
}
174