1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Audiens\AdobeClient\Entity\Target; |
4
|
|
|
|
5
|
|
|
use Audiens\AdobeClient\Entity\HydratableTrait; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Audience |
9
|
|
|
*/ |
10
|
|
|
class Audience |
11
|
|
|
{ |
12
|
|
|
const TARGET_RULE_AND = 'AND'; |
13
|
|
|
const TARGET_RULE_OR = 'OR'; |
14
|
|
|
|
15
|
|
|
use HydratableTrait; |
16
|
|
|
|
17
|
|
|
/** @var int */ |
18
|
|
|
protected $id; |
19
|
|
|
|
20
|
|
|
/** @var string */ |
21
|
|
|
protected $name; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
protected $description; |
25
|
|
|
|
26
|
|
|
/** @var \DateTime */ |
27
|
|
|
protected $modifiedAt; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
protected $targetRuleLogicalCondition; |
31
|
|
|
|
32
|
|
|
/** @var array */ |
33
|
|
|
protected $targetRuleConditions = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return int |
37
|
|
|
*/ |
38
|
|
|
public function getId() |
39
|
|
|
{ |
40
|
|
|
return $this->id; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param int $id |
45
|
|
|
*/ |
46
|
|
|
public function setId($id) |
47
|
|
|
{ |
48
|
|
|
$this->id = $id; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getName() |
55
|
|
|
{ |
56
|
|
|
return $this->name; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $name |
61
|
|
|
*/ |
62
|
|
|
public function setName($name) |
63
|
|
|
{ |
64
|
|
|
$this->name = $name; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getDescription() |
71
|
|
|
{ |
72
|
|
|
return $this->description; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $description |
77
|
|
|
*/ |
78
|
|
|
public function setDescription($description) |
79
|
|
|
{ |
80
|
|
|
$this->description = $description; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return \DateTime |
85
|
|
|
*/ |
86
|
|
|
public function getModifiedAt() |
87
|
|
|
{ |
88
|
|
|
return $this->modifiedAt; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param \DateTime $modifiedAt |
93
|
|
|
*/ |
94
|
|
|
public function setModifiedAt($modifiedAt) |
95
|
|
|
{ |
96
|
|
|
$this->modifiedAt = $modifiedAt; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getTargetRuleLogicalCondition() |
103
|
|
|
{ |
104
|
|
|
return $this->targetRuleLogicalCondition; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string $targetRuleLogicalCondition |
109
|
|
|
*/ |
110
|
|
|
public function setTargetRuleLogicalCondition($targetRuleLogicalCondition) |
111
|
|
|
{ |
112
|
|
|
$this->targetRuleLogicalCondition = $targetRuleLogicalCondition; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
|
|
public function getTargetRuleConditions() |
119
|
|
|
{ |
120
|
|
|
return $this->targetRuleConditions; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param array $targetRuleConditions |
125
|
|
|
*/ |
126
|
|
|
public function setTargetRuleConditions($targetRuleConditions) |
127
|
|
|
{ |
128
|
|
|
$this->targetRuleConditions = $targetRuleConditions; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function toArray() |
132
|
|
|
{ |
133
|
|
|
$returnArray = [ |
134
|
|
|
'name' => $this->getName(), |
135
|
|
|
'description' => $this->getDescription(), |
136
|
|
|
]; |
137
|
|
|
|
138
|
|
|
if (!empty($this->targetRuleLogicalCondition)) { |
139
|
|
|
$returnArray['targetRule'] = [$this->targetRuleLogicalCondition => $this->getTargetRuleConditions()]; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $returnArray; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @override |
147
|
|
|
*/ |
148
|
|
|
public static function fromArray(array $objectArray) |
149
|
|
|
{ |
150
|
|
|
$object = new self(); |
151
|
|
|
self::getHydrator()->hydrate($objectArray, $object); |
152
|
|
|
|
153
|
|
|
if (isset($objectArray['targetRule']) && count($objectArray['targetRule']) > 0) { |
154
|
|
|
foreach ($objectArray['targetRule'] as $logical => $rule) { |
155
|
|
|
$object->targetRuleLogicalCondition = $logical; |
|
|
|
|
156
|
|
|
$object->targetRuleConditions = $rule; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return $object; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.