Log::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 10
cp 0
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 8
crap 2

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 Mediawiki\DataModel;
4
5
use JsonSerializable;
6
7
/**
8
 * @since 0.5
9
 */
10
class Log implements JsonSerializable {
11
12
	/**
13
	 * @var int
14
	 */
15
	private $id;
16
17
	/**
18
	 * @var string
19
	 */
20
	private $type;
21
22
	/**
23
	 * @var string
24
	 */
25
	private $action;
26
27
	/**
28
	 * @var string
29
	 */
30
	private $timestamp;
31
32
	/**
33
	 * @var string
34
	 */
35
	private $user;
36
37
	/**
38
	 * @var string
39
	 */
40
	private $comment;
41
42
	/**
43
	 * @var PageIdentifier
44
	 */
45
	private $pageIdentifier;
46
47
	/**
48
	 * @var array
49
	 */
50
	private $details;
51
52
	/**
53
	 * @param int $id
54
	 * @param string $type
55
	 * @param string $action
56
	 * @param string $timestamp
57
	 * @param string $user
58
	 * @param PageIdentifier $pageIdentifier
59
	 * @param string $comment
60
	 * @param array $details
61
	 */
62
	public function __construct( $id, $type, $action, $timestamp, $user, $pageIdentifier, $comment, $details ) {
63
		$this->id = $id;
64
		$this->type = $type;
65
		$this->action = $action;
66
		$this->timestamp = $timestamp;
67
		$this->user = $user;
68
		$this->pageIdentifier = $pageIdentifier;
69
		$this->comment = $comment;
70
		$this->details = $details;
71
	}
72
73
	/**
74
	 * @since 0.5
75
	 * @return string
76
	 */
77
	public function getUser() {
78
		return $this->user;
79
	}
80
81
	/**
82
	 * @since 0.5
83
	 * @return string
84
	 */
85
	public function getAction() {
86
		return $this->action;
87
	}
88
89
	/**
90
	 * @since 0.5
91
	 * @return string
92
	 */
93
	public function getComment() {
94
		return $this->comment;
95
	}
96
97
	/**
98
	 * @since 0.5
99
	 * @return int
100
	 */
101
	public function getId() {
102
		return $this->id;
103
	}
104
105
	/**
106
	 * @since 0.6
107
	 * @return PageIdentifier
108
	 */
109
	public function getPageIdentifier() {
110
		return $this->pageIdentifier;
111
	}
112
113
	/**
114
	 * @since 0.5
115
	 * @return string
116
	 */
117
	public function getTimestamp() {
118
		return $this->timestamp;
119
	}
120
121
	/**
122
	 * @since 0.5
123
	 * @return string
124
	 */
125
	public function getType() {
126
		return $this->type;
127
	}
128
129
	/**
130
	 * @since 0.5
131
	 * @return array
132
	 */
133
	public function getDetails() {
134
		return $this->details;
135
	}
136
137
	/**
138
	 * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
139
	 */
140
	public function jsonSerialize() {
141
		return [
142
		'id' => $this->id,
143
		'type' => $this->type,
144
		'action' => $this->action,
145
		'timestamp' => $this->timestamp,
146
		'user' => $this->user,
147
		'pageidentifier' => $this->pageIdentifier,
148
		'comment' => $this->comment,
149
		'details' => $this->details,
150
		];
151
	}
152
153
	/**
154
	 * @param array $json
155
	 *
156
	 * @return self
157
	 */
158
	public static function jsonDeserialize( $json ) {
159
		return new self(
160
		$json['id'],
161
		$json['type'],
162
		$json['action'],
163
		$json['timestamp'],
164
		$json['user'],
165
		PageIdentifier::jsonDeserialize( $json['pageidentifier'] ),
166
		$json['comment'],
167
		$json['details']
168
		);
169
	}
170
171
}
172