Passed
Push — master ( 055b76...bacc0b )
by Patrick
01:33 queued 12s
created

MessageDto::__construct()   A

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 1
Metric Value
cc 1
eloc 0
c 1
b 0
f 1
nc 1
nop 8
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
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace ForecastAutomation\QueueClient\Shared\Dto;
13
14
use ForecastAutomation\Kernel\Shared\Dto\AbstractDto;
15
16
// https://github.com/cloudevents/spec/blob/v1.0.1/json-format.md#32-examples
17
// https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/
18
class MessageDto extends AbstractDto
19
{
20 1
    public function __construct(
21
        public array $data = [],
22
        public string $queueName = 'queueName',
23
        public string $type = 'eventName',
24
        public string $specversion = '1.0',
25
        public string $datacontenttype = 'application/json',
26
        public string $id = '',
27
        public int $time = 0,
28
        public array $adapterMetaResponse = [],
29
    ) {
30 1
    }
31
32
    public function setData(array $data): self
33
    {
34
        $this->data = $data;
35
36
        return $this;
37
    }
38
39
    public function setQueueName(string $queueName): self
40
    {
41
        $this->queueName = $queueName;
42
43
        return $this;
44
    }
45
46
    public function setType(string $type): self
47
    {
48
        $this->type = $type;
49
50
        return $this;
51
    }
52
53
    public function setSpecversion(string $specversion): self
54
    {
55
        $this->specversion = $specversion;
56
57
        return $this;
58
    }
59
60
    public function setDatacontenttype(string $datacontenttype): self
61
    {
62
        $this->datacontenttype = $datacontenttype;
63
64
        return $this;
65
    }
66
67
    public function setId(string $id): self
68
    {
69
        $this->id = $id;
70
71
        return $this;
72
    }
73
74
    public function setTime(int $time): self
75
    {
76
        $this->time = $time;
77
78
        return $this;
79
    }
80
81
    public function setAdapterMetaResponse(array $adapterMetaResponse): self
82
    {
83
        $this->adapterMetaResponse = $adapterMetaResponse;
84
85
        return $this;
86
    }
87
}
88