Test Setup Failed
Push — main ( abdcb9...2e5f68 )
by Slawomir
04:37
created

PostHeaderDto::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

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