Passed
Push — main ( dc275a...8e4fcf )
by Slawomir
04:22
created

PostForBaselineDto::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

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