Completed
Push — master ( 0ca99d...7c70a3 )
by Oleg
02:52
created

Event::__construct()   C

Complexity

Conditions 16
Paths 16

Size

Total Lines 23
Code Lines 19

Duplication

Lines 23
Ratio 100 %

Code Coverage

Tests 18
CRAP Score 16.747

Importance

Changes 0
Metric Value
cc 16
eloc 19
nc 16
nop 1
dl 23
loc 23
ccs 18
cts 21
cp 0.8571
crap 16.747
rs 5.2678
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Resource\v2\EventFilter;
10
11
/**
12
 * An Optimizely event.
13
 */
14
class Event
15
{
16
    /**
17
     * A machine readable name for this Event
18
     * @var string
19
     */
20
    private $apiName;
21
    
22
    /**
23
     * Whether or not this Event has been archived
24
     * @var boolean 
25
     */
26
    private $archived;
27
    
28
    /**
29
     * A category for this Event. Can be 'add_to_cart', 'save', 'search', 'share', 
30
     * 'purchase', 'convert', 'sign_up', 'subscribe' or 'other'.
31
     * @var type 
32
     */
33
    private $category;
34
    
35
    /**
36
     * Creation date for this Event
37
     * @var string 
38
     */
39
    private $created;
40
    
41
    /**
42
     * A description for this Event
43
     * @var string 
44
     */
45
    private $description;
46
    
47
    /**
48
     * A filter object for this Event
49
     * @var EventFilter 
50
     */
51
    private $eventFilter;
52
    
53
    /**
54
     * The type of this Event. Can be custom, click, pageview, classic_custom, 
55
     * classic_click, classic_pageview, classic_engagement, classic_revenue, 
56
     * classic_mobile_tap, classic_mobile_view, classic_mobile_session, 
57
     * classic_mobile_session_length or classic_mobile_num_session
58
     * @var string 
59
     */
60
    private $eventType;
61
    
62
    /**
63
     * Unique string identifier for this event within the project.
64
     * @var string
65
     */
66
    private $key;
67
    
68
    /**
69
     * A human readable name for this Event
70
     * @var string 
71
     */
72
    private $name;
73
    
74
    /**
75
     * The Page ID associated with this Event
76
     * @var integer 
77
     */
78
    private $pageId;
79
    
80
    /**
81
     * The parent Project ID of this Event
82
     * @var integer 
83
     */
84
    private $projectId;
85
    
86
    /**
87
     * The unique identifier of the Event
88
     * @var integer
89
     */
90
    private $id;
91
    
92
    /**
93
     * Whether or not this Event is a classic Event
94
     * @var boolean 
95
     */
96
    private $isClassic;
97
    
98
    /**
99
     * Whether this Event may be edited
100
     * @var boolean 
101
     */
102
    private $isEditable;
103
    
104
    /**
105
     * Constructor.
106
     */
107 9 View Code Duplication
    public function __construct($options = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
108
    {
109 9
        foreach ($options as $name=>$value) {
110
            switch ($name) {                
111 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...
112 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...
113 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...
114 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...
115 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...
116 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...
117 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...
118 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...
119 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...
120 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...
121 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...
122 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...
123 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...
124 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...
125
                default:
126
                    throw new \Exception('Unknown option: ' . $name);
127
            }
128 9
        }
129 9
    }
130
    
131
    /**
132
     * Returns this object as array.
133
     */
134 5 View Code Duplication
    public function toArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

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