MigrationStep::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 20
c 0
b 0
f 0
rs 9.9666
cc 1
nc 1
nop 9

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
namespace Triadev\EsMigration\Models;
3
4
class MigrationStep
5
{
6
    /** @var int */
7
    private $id;
8
    
9
    /** @var string */
10
    private $type;
11
    
12
    /** @var int */
13
    private $status;
14
    
15
    /** @var string */
16
    private $error;
17
    
18
    /** @var array */
19
    private $params;
20
    
21
    /** @var int */
22
    private $priority;
23
    
24
    /** @var bool */
25
    private $stopOnFailure;
26
    
27
    /** @var \DateTime */
28
    private $createdAt;
29
    
30
    /** @var \DateTime */
31
    private $updatedAt;
32
    
33
    /**
34
     * MigrationStep constructor.
35
     * @param int $id
36
     * @param string $type
37
     * @param int $status
38
     * @param null|string $error
39
     * @param array $params
40
     * @param int $priority
41
     * @param bool $stopOnFailure
42
     * @param \DateTime $createdAt
43
     * @param \DateTime $updatedAt
44
     */
45
    public function __construct(
46
        int $id,
47
        string $type,
48
        int $status,
49
        ?string $error,
50
        array $params,
51
        int $priority,
52
        bool $stopOnFailure,
53
        \DateTime $createdAt,
54
        \DateTime $updatedAt
55
    ) {
56
        $this->id = $id;
57
        $this->type = $type;
58
        $this->status = $status;
59
        $this->error = $error;
60
        $this->params = $params;
61
        $this->priority = $priority;
62
        $this->stopOnFailure = $stopOnFailure;
63
        $this->createdAt = $createdAt;
64
        $this->updatedAt = $updatedAt;
65
    }
66
    
67
    /**
68
     * @return int
69
     */
70
    public function getId(): int
71
    {
72
        return $this->id;
73
    }
74
    
75
    /**
76
     * @return string
77
     */
78
    public function getType(): string
79
    {
80
        return $this->type;
81
    }
82
    
83
    /**
84
     * @return int
85
     */
86
    public function getStatus(): int
87
    {
88
        return $this->status;
89
    }
90
    
91
    /**
92
     * @return string
93
     */
94
    public function getError(): string
95
    {
96
        return $this->error;
97
    }
98
    
99
    /**
100
     * @return array
101
     */
102
    public function getParams(): array
103
    {
104
        return $this->params;
105
    }
106
    
107
    /**
108
     * @return \DateTime
109
     */
110
    public function getCreatedAt(): \DateTime
111
    {
112
        return $this->createdAt;
113
    }
114
    
115
    /**
116
     * @return \DateTime
117
     */
118
    public function getUpdatedAt(): \DateTime
119
    {
120
        return $this->updatedAt;
121
    }
122
    
123
    /**
124
     * @return int
125
     */
126
    public function getPriority(): int
127
    {
128
        return $this->priority;
129
    }
130
    
131
    /**
132
     * @return bool
133
     */
134
    public function isStopOnFailure(): bool
135
    {
136
        return $this->stopOnFailure;
137
    }
138
}
139