Issues (3627)

CampaignBundle/Event/CampaignExecutionEvent.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2015 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\CampaignBundle\Event;
13
14
use Mautic\CampaignBundle\Entity\LeadEventLog;
15
use Mautic\LeadBundle\Entity\Lead;
16
use Symfony\Component\EventDispatcher\Event;
17
18
/**
19
 * Class CampaignExecutionEvent.
20
 *
21
 * @deprecated 2.13.0; to be removed in 3.0
22
 */
23
class CampaignExecutionEvent extends Event
24
{
25
    use EventArrayTrait;
26
    use ContextTrait;
27
28
    /**
29
     * @var Lead
30
     */
31
    protected $lead;
32
33
    /**
34
     * @var array
35
     */
36
    protected $event;
37
38
    /**
39
     * @var array
40
     */
41
    protected $eventDetails;
42
43
    /**
44
     * @var bool
45
     */
46
    protected $systemTriggered;
47
48
    /**
49
     * @var bool|array
50
     */
51
    protected $result;
52
53
    /**
54
     * @var array
55
     */
56
    protected $eventSettings;
57
58
    /**
59
     * @var LeadEventLog|null
60
     */
61
    protected $log;
62
63
    /**
64
     * @var bool
65
     */
66
    protected $logUpdatedByListener = false;
67
68
    /**
69
     * @var string
70
     */
71
    protected $channel;
72
73
    /**
74
     * @var int
75
     */
76
    protected $channelId;
77
78
    /**
79
     * @param bool $result
80
     */
81
    public function __construct(array $args, $result, LeadEventLog $log = null)
82
    {
83
        $this->lead            = $args['lead'];
84
        $this->event           = $args['event'];
85
        $this->eventDetails    = $args['eventDetails'];
86
        $this->systemTriggered = $args['systemTriggered'];
87
        $this->eventSettings   = $args['eventSettings'];
88
        $this->result          = $result;
89
        $this->log             = $log;
90
    }
91
92
    /**
93
     * @return Lead
94
     */
95
    public function getLead()
96
    {
97
        return $this->lead;
98
    }
99
100
    /**
101
     * Returns array with lead fields and owner ID if exist.
102
     *
103
     * @return array
104
     */
105
    public function getLeadFields()
106
    {
107
        $lead         = $this->getLead();
108
        $isLeadEntity = ($lead instanceof Lead);
109
110
        // In case Lead is a scalar value:
111
        if (!$isLeadEntity && !is_array($lead)) {
112
            $lead = [];
113
        }
114
115
        $leadFields             = $isLeadEntity ? $lead->getProfileFields() : $lead;
116
        $leadFields['owner_id'] = $isLeadEntity && ($owner = $lead->getOwner()) ? $owner->getId() : 0;
117
118
        return $leadFields;
119
    }
120
121
    /**
122
     * @return array
123
     */
124
    public function getEvent()
125
    {
126
        return ($this->event instanceof \Mautic\CampaignBundle\Entity\Event) ? $this->getEventArray($this->event) : $this->event;
127
    }
128
129
    /**
130
     * @return array
131
     */
132
    public function getConfig()
133
    {
134
        return $this->getEvent()['properties'];
135
    }
136
137
    /**
138
     * @return array
139
     */
140
    public function getEventDetails()
141
    {
142
        return $this->eventDetails;
143
    }
144
145
    /**
146
     * @return bool
147
     */
148
    public function getSystemTriggered()
149
    {
150
        return $this->systemTriggered;
151
    }
152
153
    /**
154
     * @return bool
155
     */
156
    public function getResult()
157
    {
158
        return $this->result;
159
    }
160
161
    /**
162
     * @param $result
163
     *
164
     * @return $this
165
     */
166
    public function setResult($result)
167
    {
168
        $this->result = $result;
169
170
        return $this;
171
    }
172
173
    /**
174
     * Set the result to failed.
175
     *
176
     * @param null $reason
177
     *
178
     * @return $this
179
     */
180
    public function setFailed($reason = null)
181
    {
182
        $this->result = [
183
            'failed' => 1,
184
            'reason' => $reason,
185
        ];
186
187
        return $this;
188
    }
189
190
    /**
191
     * @return mixed
192
     */
193
    public function getEventSettings()
194
    {
195
        return $this->eventSettings;
196
    }
197
198
    /**
199
     * Set a custom log entry to override auto-handling of the log entry.
200
     *
201
     * @return $this
202
     */
203
    public function setLogEntry(LeadEventLog $log)
204
    {
205
        $this->logUpdatedByListener = true;
206
        $this->log                  = $log;
207
208
        return $this;
209
    }
210
211
    /**
212
     * @return LeadEventLog
213
     */
214
    public function getLogEntry()
215
    {
216
        return $this->log;
217
    }
218
219
    /**
220
     * Returns if a listener updated the log entry.
221
     *
222
     * @return bool
223
     */
224
    public function wasLogUpdatedByListener()
225
    {
226
        return $this->logUpdatedByListener;
227
    }
228
229
    /**
230
     * @param string          $channel
231
     * @param string|int|null $channelId
232
     *
233
     * @return $this
234
     */
235
    public function setChannel($channel, $channelId = null)
236
    {
237
        if (null !== $this->log) {
238
            // Set the channel since we have the resource
239
            $this->log->setChannel($channel)
240
                      ->setChannelId($channelId);
241
        }
242
243
        $this->channel   = $channel;
244
        $this->channelId = $channelId;
0 ignored issues
show
Documentation Bug introduced by
It seems like $channelId can also be of type string. However, the property $channelId is declared as type integer. Maybe add an additional type check?

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 the id property of an instance of the Account 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.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
245
246
        return $this;
247
    }
248
249
    /**
250
     * @return mixed
251
     */
252
    public function getChannel()
253
    {
254
        return $this->channel;
255
    }
256
257
    /**
258
     * @return mixed
259
     */
260
    public function getChannelId()
261
    {
262
        return $this->channelId;
263
    }
264
}
265