1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2016 Beñat Espiña <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace BenatEspina\StackExchangeApiClient\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The account merge model class. |
16
|
|
|
* |
17
|
|
|
* @author Beñat Espiña <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class AccountMerge implements Model |
20
|
|
|
{ |
21
|
|
|
protected $mergeDate; |
22
|
|
|
protected $newAccountId; |
23
|
|
|
protected $oldAccountId; |
24
|
|
|
|
25
|
|
|
public static function fromProperties(\DateTimeInterface $mergeDate, $newAccountId, $oldAccountId) |
26
|
|
|
{ |
27
|
|
|
$instance = new self(); |
28
|
|
|
$instance |
29
|
|
|
->setMergeDate($mergeDate) |
30
|
|
|
->setNewAccountId($newAccountId) |
31
|
|
|
->setOldAccountId($oldAccountId); |
32
|
|
|
|
33
|
|
|
return $instance; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public static function fromJson(array $data) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$instance = new self(); |
39
|
|
|
$instance |
40
|
|
|
->setMergeDate( |
41
|
|
|
array_key_exists('merge_date', $data) |
42
|
|
|
? new \DateTimeImmutable('@' . $data['merge_date']) |
43
|
|
|
: null |
44
|
|
|
) |
45
|
|
|
->setNewAccountId(array_key_exists('new_account_id', $data) ? $data['new_account_id'] : null) |
46
|
|
|
->setOldAccountId(array_key_exists('old_account_id', $data) ? $data['old_account_id'] : null); |
47
|
|
|
|
48
|
|
|
return $instance; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function setMergeDate(\DateTimeInterface $mergeDate = null) |
52
|
|
|
{ |
53
|
|
|
$this->mergeDate = $mergeDate; |
54
|
|
|
|
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getMergeDate() |
59
|
|
|
{ |
60
|
|
|
return $this->mergeDate; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setNewAccountId($newAccountId) |
64
|
|
|
{ |
65
|
|
|
$this->newAccountId = $newAccountId; |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getNewAccountId() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
return $this->newAccountId; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setOldAccountId($oldAccountId) |
76
|
|
|
{ |
77
|
|
|
$this->oldAccountId = $oldAccountId; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getOldAccountId() |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
return $this->oldAccountId; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.