Passed
Push — main ( 79e4f1...ed1bb6 )
by Slawomir
04:28
created

CommentWithPostDto::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
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 8
dl 0
loc 11
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\Comments\Domain\Dto;
4
5
use Symfony\Component\Uid\Ulid;
6
7
class CommentWithPostDto
8
{
9
10
    /**
11
     * @param Ulid $id
12
     * @param string $author
13
     * @param string $body
14
     * @param Ulid|null $parentId
15
     * @param \DateTime $createdAt
16
     * @param Ulid $postId
17
     * @param string $postTitle
18
     * @param array $postTags
19
     */
20
    public function __construct(
21
        private Ulid      $id,
22 2
        private string    $author,
23
        private string    $body,
24
        private ?Ulid     $parentId,
25
        private \DateTime $createdAt,
26
        private Ulid      $postId,
27
        private string    $postTitle,
28
        private array     $postTags
29
    )
30
    {
31
    }
32
33
    /**
34
     * @return Ulid
35 2
     */
36
    public function getId(): Ulid
37
    {
38
        return $this->id;
39
    }
40 2
41
    /**
42 2
     * @return string
43
     */
44
    public function getAuthor(): string
45
    {
46
        return $this->author;
47
    }
48 2
49
    /**
50 2
     * @return string
51
     */
52
    public function getBody(): string
53
    {
54
        return $this->body;
55
    }
56 2
57
    /**
58 2
     * @return Ulid|null
59
     */
60
    public function getParentId(): ?Ulid
61
    {
62
        return $this->parentId;
63
    }
64 2
65
    /**
66 2
     * @return \DateTime
67
     */
68
    public function getCreatedAt(): \DateTime
69
    {
70
        return $this->createdAt;
71
    }
72 2
73
    /**
74 2
     * @return Ulid
75
     */
76
    public function getPostId(): Ulid
77
    {
78
        return $this->postId;
79
    }
80 2
81
    /**
82 2
     * @return string
83
     */
84
    public function getPostTitle(): string
85
    {
86
        return $this->postTitle;
87
    }
88 2
89
    /**
90 2
     * @return array<string>
91
     */
92
    public function getPostTags(): array
93
    {
94
        return $this->postTags;
95
    }
96 2
97
98
}