1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LPTracker\models; |
4
|
|
|
|
5
|
|
|
use LPTracker\exceptions\LPTrackerSDKException; |
6
|
|
|
|
7
|
|
|
class Stage extends Model |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var int |
11
|
|
|
*/ |
12
|
|
|
protected $id; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $name; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var bool |
21
|
|
|
*/ |
22
|
|
|
protected $notify; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
protected $inLeads; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
protected $inDeals; |
33
|
|
|
|
34
|
|
|
public function __construct(array $stageData = []) |
35
|
|
|
{ |
36
|
|
|
if (isset($stageData['id'])) { |
37
|
|
|
$this->id = (int) $stageData['id']; |
38
|
|
|
} |
39
|
|
|
if (isset($stageData['name'])) { |
40
|
|
|
$this->name = $stageData['name']; |
41
|
|
|
} |
42
|
|
|
if (isset($stageData['notify'])) { |
43
|
|
|
$this->notify = (bool) $stageData['notify']; |
44
|
|
|
} |
45
|
|
|
if (isset($stageData['in_leads'])) { |
46
|
|
|
$this->inLeads = (bool) $stageData['in_leads']; |
47
|
|
|
} |
48
|
|
|
if (isset($stageData['in_deals'])) { |
49
|
|
|
$this->inDeals = (bool) $stageData['in_deals']; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return bool |
55
|
|
|
* @throws LPTrackerSDKException |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
public function validate() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
if (empty($this->id)) { |
60
|
|
|
throw new LPTrackerSDKException('Stage ID is required'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (empty($this->name)) { |
64
|
|
|
throw new LPTrackerSDKException('Stage name is required'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return true; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function toArray() |
74
|
|
|
{ |
75
|
|
|
return [ |
76
|
|
|
'id' => $this->getId(), |
77
|
|
|
'name' => $this->getName(), |
78
|
|
|
'notify' => $this->shouldNotify(), |
79
|
|
|
'in_leads' => $this->shouldShowInLeads(), |
80
|
|
|
'in_deals' => $this->shouldShowInDeals(), |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return int |
86
|
|
|
*/ |
87
|
|
|
public function getId() |
88
|
|
|
{ |
89
|
|
|
return $this->id; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getName() |
96
|
|
|
{ |
97
|
|
|
return $this->name; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
|
|
public function shouldNotify() |
104
|
|
|
{ |
105
|
|
|
return $this->notify; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return bool |
110
|
|
|
*/ |
111
|
|
|
public function shouldShowInLeads() |
112
|
|
|
{ |
113
|
|
|
return $this->inLeads; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return bool |
118
|
|
|
*/ |
119
|
|
|
public function shouldShowInDeals() |
120
|
|
|
{ |
121
|
|
|
return $this->inDeals; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
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.