Completed
Push — master ( a99496...5c0b02 )
by Oleg
02:28
created

Event::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 07 October 2016
5
 * @copyright (c) 2016, Web Marketing ROI
6
 */
7
namespace WebMarketingROI\OptimizelyPHP\Resource\v2;
8
9
use WebMarketingROI\OptimizelyPHP\Exception;
10
use WebMarketingROI\OptimizelyPHP\Resource\v2\EventFilter;
11
use WebMarketingROI\OptimizelyPHP\Resource\v2\InPageEventConfig;
12
13
/**
14
 * An Optimizely event.
15
 */
16
class Event
17
{
18
    /**
19
     * A machine readable name for this Event
20
     * @var string
21
     */
22
    private $apiName;
23
    
24
    /**
25
     * Whether or not this Event has been archived
26
     * @var boolean 
27
     */
28
    private $archived;
29
    
30
    /**
31
     * A category for this Event. Can be 'add_to_cart', 'save', 'search', 'share', 
32
     * 'purchase', 'convert', 'sign_up', 'subscribe' or 'other'.
33
     * @var type 
34
     */
35
    private $category;
36
    
37
    /**
38
     * Creation date for this Event
39
     * @var string 
40
     */
41
    private $created;
42
    
43
    /**
44
     * A description for this Event
45
     * @var string 
46
     */
47
    private $description;
48
    
49
    /**
50
     * A filter object for this Event
51
     * @var EventFilter 
52
     */
53
    private $eventFilter;
54
    
55
    /**
56
     * The type of this Event. Can be custom, click, pageview, classic_custom, 
57
     * classic_click, classic_pageview, classic_engagement, classic_revenue, 
58
     * classic_mobile_tap, classic_mobile_view, classic_mobile_session, 
59
     * classic_mobile_session_length or classic_mobile_num_session
60
     * @var string 
61
     */
62
    private $eventType;
63
    
64
    /**
65
     * Unique string identifier for this event within the project.
66
     * @var string
67
     */
68
    private $key;
69
    
70
    /**
71
     * A human readable name for this Event
72
     * @var string 
73
     */
74
    private $name;
75
    
76
    /**
77
     * The Page ID associated with this Event
78
     * @var integer 
79
     */
80
    private $pageId;
81
    
82
    /**
83
     * The parent Project ID of this Event
84
     * @var integer 
85
     */
86
    private $projectId;
87
    
88
    /**
89
     * The unique identifier of the Event
90
     * @var integer
91
     */
92
    private $id;
93
    
94
    /**
95
     * Whether or not this Event is a classic Event
96
     * @var boolean 
97
     */
98
    private $isClassic;
99
    
100
    /**
101
     * Whether this Event may be edited
102
     * @var boolean 
103
     */
104
    private $isEditable;
105
    
106
    /**
107
     * 
108
     * @var InPageEventConfig
109
     */
110
    private $config;
111
    
112
    /**
113
     * Constructor.
114
     */
115 9
    public function __construct($options = array())
116
    {
117 9
        foreach ($options as $name=>$value) {
118
            switch ($name) {                
119 8
                case 'api_name': $this->setApiName($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
120 8
                case 'archived': $this->setArchived($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
121 8
                case 'category': $this->setCategory($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
122 8
                case 'created': $this->setCreated($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
123 8
                case 'description': $this->setDescription($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
124 8
                case 'event_filter': $this->setEventFilter(new EventFilter($value)); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
125 8
                case 'event_type': $this->setEventType($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
126 8
                case 'key': $this->setKey($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
127 8
                case 'name': $this->setName($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
128 8
                case 'page_id': $this->setPageId($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
129 8
                case 'project_id': $this->setProjectId($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
130 8
                case 'id': $this->setId($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
131 8
                case 'is_classic': $this->setIsClassic($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
132 8
                case 'is_editable': $this->setIsEditable($value); break;                
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
133
                case 'config': $this->setConfig(new InPageEventConfig($value)); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
134
                default:
135
                    throw new Exception('Unknown option found in the Event entity: ' . $name);
136
            }
137 9
        }
138 9
    }
139
    
140
    /**
141
     * Returns this object as array.
142
     */
143 5
    public function toArray()
144
    {
145
        $options = array(
146 5
            'api_name' => $this->getApiName(),
147 5
            'archived' => $this->getArchived(),
148 5
            'category' => $this->getCategory(),
149 5
            'created' => $this->getCreated(),
150 5
            'description' => $this->getDescription(),
151 5
            'event_filter' => $this->getEventFilter()?$this->getEventFilter()->toArray():null,
152 5
            'event_type' => $this->getEventType(),
153 5
            'key' => $this->getKey(),
154 5
            'name' => $this->getName(),
155 5
            'page_id' => $this->getPageId(),
156 5
            'project_id' => $this->getProjectId(),
157 5
            'id' => $this->getId(),
158 5
            'is_classic' => $this->getIsClassic(),
159 5
            'is_editable' => $this->getIsEditable(),            
160 5
            'config' => $this->getConfig()?$this->getConfig()->toArray():null,
161 5
        );
162
        
163
        // Remove options with empty values
164 5
        $cleanedOptions = array();
165 5
        foreach ($options as $name=>$value) {
166 5
            if ($value!==null)
167 5
                $cleanedOptions[$name] = $value;
168 5
        }
169
        
170 5
        return $cleanedOptions;
171
    }
172
    
173 5
    public function getApiName()
174
    {
175 5
        return $this->apiName;
176
    }
177
    
178
    public function setApiName($apiName)
179
    {
180
        $this->apiName = $apiName;
181
    }
182
    
183 7
    public function getArchived()
184
    {
185 7
        return $this->archived;
186
    }
187
    
188 9
    public function setArchived($archived)
189
    {
190 9
        $this->archived = $archived;
191 9
    }
192
    
193 7
    public function getCategory()
194
    {
195 7
        return $this->category;
196
    }
197
    
198 9
    public function setCategory($category)
199
    {
200 9
        $this->category = $category;
201 9
    }
202
    
203 5
    public function getCreated()
204
    {
205 5
        return $this->created;
206
    }
207
    
208 9
    public function setCreated($created)
209
    {
210 9
        $this->created = $created;
211 9
    }
212
        
213 5
    public function getDescription()
214
    {
215 5
        return $this->description;
216
    }
217
    
218 9
    public function setDescription($description)
219
    {
220 9
        $this->description = $description;
221 9
    }
222
        
223 7
    public function getEventFilter()
224
    {
225 7
        return $this->eventFilter;
226
    }
227
    
228 7
    public function setEventFilter($eventFilter)
229
    {
230 7
        $this->eventFilter = $eventFilter;
231 7
    }
232
    
233 5
    public function getEventType()
234
    {
235 5
        return $this->eventType;
236
    }
237
    
238 9
    public function setEventType($eventType)
239
    {
240 9
        $this->eventType = $eventType;
241 9
    }
242
    
243 5
    public function getKey()
244
    {
245 5
        return $this->key;
246
    }
247
    
248 9
    public function setKey($key)
249
    {
250 9
        $this->key = $key;
251 9
    }
252
    
253 9
    public function getName()
254
    {
255 9
        return $this->name;
256
    }
257
    
258 9
    public function setName($name)
259
    {
260 9
        $this->name = $name;
261 9
    }
262
    
263 5
    public function getPageId()
264
    {
265 5
        return $this->pageId;
266
    }
267
    
268 9
    public function setPageId($pageId)
269
    {
270 9
        $this->pageId = $pageId;
271 9
    }
272
    
273 5
    public function getProjectId()
274
    {
275 5
        return $this->projectId;
276
    }
277
    
278 9
    public function setProjectId($projectId)
279
    {
280 9
        $this->projectId = $projectId;
281 9
    }
282
    
283 5
    public function getId()
284
    {
285 5
        return $this->id;
286
    }
287
    
288 9
    public function setId($id)
289
    {
290 9
        $this->id = $id;
291 9
    }
292
    
293 5
    public function getIsClassic()
294
    {
295 5
        return $this->isClassic;
296
    }
297
    
298 9
    public function setIsClassic($isClassic)
299
    {
300 9
        $this->isClassic = $isClassic;
301 9
    }
302
    
303 7
    public function getIsEditable()
304
    {
305 7
        return $this->isEditable;
306
    }
307
    
308 9
    public function setIsEditable($isEditable)
309
    {
310 9
        $this->isEditable = $isEditable;
311 9
    }  
312
    
313 5
    public function getConfig()
314
    {
315 5
        return $this->config;
316
    }
317
    
318
    public function setConfig($config)
319
    {
320
        $this->config = $config;
321
    }  
322
}
323
324
325
326
327
328
329