1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2015 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\Traits; |
13
|
|
|
|
14
|
|
|
use BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface; |
15
|
|
|
use BenatEspina\StackExchangeApiClient\Model\ShallowUser; |
16
|
|
|
use BenatEspina\StackExchangeApiClient\Util\Util; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Trait EditTrait. |
20
|
|
|
* |
21
|
|
|
* @author Beñat Espiña <[email protected]> |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
trait EditTrait |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Last edit date. |
27
|
|
|
* |
28
|
|
|
* @var \DateTime|null |
29
|
|
|
*/ |
30
|
|
|
protected $lastEditDate; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Last editor. |
34
|
|
|
* |
35
|
|
|
* @var \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface |
36
|
|
|
*/ |
37
|
|
|
protected $lastEditor; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Sets last edit date. |
41
|
|
|
* |
42
|
|
|
* @param \DateTime|null $lastEditDate The last edit date |
|
|
|
|
43
|
|
|
* |
44
|
|
|
* @return $this self Object |
45
|
|
|
*/ |
46
|
|
|
public function setLastEditDate(\DateTime $lastEditDate) |
47
|
|
|
{ |
48
|
|
|
$this->lastEditDate = $lastEditDate; |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Gets last edit date. |
55
|
|
|
* |
56
|
|
|
* @return \DateTime|null |
57
|
|
|
*/ |
58
|
|
|
public function getLastEditDate() |
59
|
|
|
{ |
60
|
|
|
return $this->lastEditDate; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Sets last editor. |
65
|
|
|
* |
66
|
|
|
* @param \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface $lastEditor The last editor. |
67
|
|
|
* |
68
|
|
|
* @return $this self Object |
69
|
|
|
*/ |
70
|
|
|
public function setLastEditor(ShallowUserInterface $lastEditor) |
71
|
|
|
{ |
72
|
|
|
$this->lastEditor = $lastEditor; |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Gets last editor. |
79
|
|
|
* |
80
|
|
|
* @return \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface |
81
|
|
|
*/ |
82
|
|
|
public function getLastEditor() |
83
|
|
|
{ |
84
|
|
|
return $this->lastEditor; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Loads the variables if the data exist into resource. It works like a constructor. |
89
|
|
|
* |
90
|
|
|
* @param null|mixed[] $resource The resource |
91
|
|
|
*/ |
92
|
|
|
protected function loadEdit($resource) |
93
|
|
|
{ |
94
|
|
|
$this->lastEditDate = Util::setIfDateTimeExists($resource, 'last_edit_date'); |
95
|
|
|
$this->lastEditor = new ShallowUser(Util::setIfArrayExists($resource, 'last_editor')); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.