UserPostHeaderDto::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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

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\Modules\Security\Domain\Dto;
4
5
use Symfony\Component\Uid\Ulid;
6
7
class UserPostHeaderDto
8
{
9
    /**
10
     * @param Ulid $id
11
     * @param string $title
12
     * @param string $summary
13
     * @param array $tags
14
     * @param Ulid $createdById
15
     * @param string $createdByName
16
     * @param \DateTime $createdAt
17
     * @param int $version
18
     * @param int $commentsCount
19
     */
20 4
    public function __construct(private Ulid      $id,
21
                                private string    $title,
22
                                private string    $summary,
23
                                private array     $tags,
24
                                private Ulid      $createdById,
25
                                private string    $createdByName,
26
                                private \DateTime $createdAt,
27
                                private int       $version,
28
                                private int       $commentsCount)
29
    {
30 4
    }
31
32
    /**
33
     * @return Ulid
34
     */
35 4
    public function getId(): Ulid
36
    {
37 4
        return $this->id;
38
    }
39
40
41
    /**
42
     * @return string
43
     */
44 4
    public function getTitle(): string
45
    {
46 4
        return $this->title;
47
    }
48
49
    /**
50
     * @return string
51
     */
52 4
    public function getSummary(): string
53
    {
54 4
        return $this->summary;
55
    }
56
57
    /**
58
     * @return array
59
     */
60 4
    public function getTags(): array
61
    {
62 4
        return $this->tags;
63
    }
64
65
66
    /**
67
     * @return \DateTime
68
     */
69 4
    public function getCreatedAt(): \DateTime
70
    {
71 4
        return $this->createdAt;
72
    }
73
74
75
    /**
76
     * @return int
77
     */
78 4
    public function getVersion(): int
79
    {
80 4
        return $this->version;
81
    }
82
83
84
    /**
85
     * @return int
86
     */
87 2
    public function getCommentsCount(): int
88
    {
89 2
        return $this->commentsCount;
90
    }
91
92
    /**
93
     * @return Ulid
94
     */
95 4
    public function getCreatedById(): Ulid
96
    {
97 4
        return $this->createdById;
98
    }
99
100
    /**
101
     * @return string
102
     */
103 4
    public function getCreatedByName(): string
104
    {
105 4
        return $this->createdByName;
106
    }
107
108
109
}