Completed
Push — master ( ddef5e...4d3008 )
by Oleg
02:26
created

Experiment   D

Complexity

Total Complexity 80

Size/Duplication

Total Lines 471
Duplicated Lines 3.4 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 90.86%

Importance

Changes 0
Metric Value
dl 16
loc 471
ccs 169
cts 186
cp 0.9086
rs 4.8717
c 0
b 0
f 0
wmc 80
lcom 1
cbo 5

46 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 16 51 26
C toArray() 0 59 10
A getProjectId() 0 4 1
A setProjectId() 0 4 1
A getAudienceIds() 0 4 1
A setAudienceIds() 0 4 1
A getCampaignId() 0 4 1
A setCampaignId() 0 4 1
A getChanges() 0 4 1
A setChanges() 0 4 1
A getCreated() 0 4 1
A setCreated() 0 4 1
A getDescription() 0 4 1
A setDescription() 0 4 1
A getHoldback() 0 4 1
A setHoldback() 0 4 1
A getKey() 0 4 1
A setKey() 0 4 1
A getLastModified() 0 4 1
A setLastModified() 0 4 1
A getMetrics() 0 4 1
A setMetrics() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getSchedule() 0 4 1
A setSchedule() 0 4 1
A getStatus() 0 4 1
A setStatus() 0 4 1
A getVariations() 0 4 1
A setVariations() 0 4 1
A getId() 0 4 1
A setId() 0 4 1
A getIsClassic() 0 4 1
A setIsClassic() 0 4 1
A getType() 0 4 1
A setType() 0 4 1
A getAudienceConditions() 0 4 1
A setAudienceConditions() 0 4 1
A getConfig() 0 4 1
A setConfig() 0 4 1
A getAllocationPolicy() 0 4 1
A setAllocationPolicy() 0 4 1
A getEarliest() 0 4 1
A setEarliest() 0 4 1
A getPageIds() 0 4 1
A setPageIds() 0 4 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Experiment often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Experiment, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 05 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\Schedule;
11
use WebMarketingROI\OptimizelyPHP\Resource\v2\Variation;
12
use WebMarketingROI\OptimizelyPHP\Resource\v2\Change;
13
use WebMarketingROI\OptimizelyPHP\Resource\v2\Metric;
14
15
/**
16
 * An Optimizely experiment.
17
 */
18
class Experiment
19
{
20
    /**
21
     * The project the Experiment is in
22
     * @var integer
23
     */
24
    private $projectId;
25
    
26
    /**
27
     * List of IDs of all audiences the Experiment is targeted at
28
     * @var array[integer] 
29
     */
30
    private $audienceIds;
31
    
32
    /**
33
     * The ID for the Campaign that the Experiment is in
34
     * @var integer 
35
     */
36
    private $campaignId;
37
    
38
    /**
39
     * Experiment-level changes that will run before all Variations. Typically 
40
     * this is custom CSS or custom JavaScript.
41
     * @var array[Change] 
42
     */
43
    private $changes;
44
    
45
    /**
46
     * The time the experiment was initially created
47
     * @var string 
48
     */
49
    private $created;
50
    
51
    /**
52
     * The description or hypothesis for an Experiment
53
     * @var string 
54
     */
55
    private $description;
56
    
57
    /**
58
     * Percentage expressed as a number from 0-10000 to hold back from being 
59
     * included in the experiment
60
     * @var integer 
61
     */
62
    private $holdback;
63
    
64
    /**
65
     * Unique string identifier for this experiment within the project.
66
     * @var string
67
     */
68
    private $key;
69
    
70
    /**
71
     * The last time the experiment was modified
72
     * @var string 
73
     */
74
    private $lastModified;
75
    
76
    /**
77
     * An ordered list of metrics to track for the experiment
78
     * @var array[Metric] 
79
     */
80
    private $metrics;
81
    
82
    /**
83
     * Name of the Experiment
84
     * @var string 
85
     */
86
    private $name;
87
    
88
    /**
89
     * The last time the experiment was modified
90
     * @var Schedule 
91
     */
92
    private $schedule;
93
    
94
    /**
95
     * Current state of the experiment. Can be 'active', 'paused' or 'archived'.
96
     * @var string 
97
     */
98
    private $status;
99
    
100
    /**
101
     * A list of Variations that each define an experience to show in the context 
102
     * of the Experiment for the purpose of comparison against each other
103
     * @var array[Variation]
104
     */
105
    private $variations = array();
106
    
107
    /**
108
     * The unique identifier for the Experiment
109
     * @var integer 
110
     */
111
    private $id;
112
    
113
    /**
114
     * Whether or not the Experiment is a classic Experiment
115
     * @var boolean
116
     */
117
    private $isClassic;
118
    
119
    /**
120
     * Indicates whether this is a standalone a/b experiment or an experience within a personalization campaign
121
     * Can be a/b or personalization
122
     * @var string
123
     */
124
    private $type;
125
    
126
    /**
127
     * The audiences that should see this experiment. If the field is null or 
128
     * omitted, the experiment will target everyone. Multiple audiences can be 
129
     * combined with "and" or "or" using the same structure as audience conditions
130
     * @var string 
131
     */
132
    private $audienceConditions;
133
    
134
    /**
135
     * Traffic allocation policy across variations in this experiment
136
     * @var string 
137
     */
138
    private $allocationPolicy;
139
    
140
    /**
141
     * The first time the Experiment was activated
142
     * @var type 
143
     */
144
    private $earliest;
145
    
146
    /**
147
     * A list of Page IDs used in the Experiment. url_targeting or page_ids, but not both.
148
     */
149
    private $pageIds;
150
    
151
    /**
152
     * Constructor.
153
     */
154 7
    public function __construct($options = array())
155
    {
156 7
        foreach ($options as $name=>$value) {
157
            switch ($name) {
158 6
                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...
159 6
                case 'audience_ids': $this->setAudienceIds($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...
160 6
                case 'campaign_id': $this->setCampaignId($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...
161 6 View Code Duplication
                case 'changes': {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

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

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

Loading history...
162 6
                    $changes = array();
163 6
                    foreach ($value as $changeInfo) {
164 6
                        $changes[] = new Change($changeInfo);
165
                    }
166 6
                    $this->setChanges($changes); 
167 6
                    break;
168
                }
169 6
                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...
170 6
                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...
171 6
                case 'holdback': $this->setHoldback($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...
172 6
                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...
173 6
                case 'last_modified': $this->setLastModified($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...
174 6
                case 'metrics': {
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

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

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

Loading history...
175 6
                    $metrics = array();
176 6
                    foreach ($value as $metricInfo) {
177 6
                        $metrics[] = new Metric($metricInfo);
178
                    }
179 6
                    $this->setMetrics($metrics); 
180 6
                    break;    
181
                }
182 6
                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...
183 6
                case 'schedule': $this->setSchedule(new Schedule($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...
184 6
                case 'status': $this->setStatus($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...
185 6 View Code Duplication
                case 'variations': {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

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

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

Loading history...
186 6
                    $variations = array();
187 6
                    foreach ($value as $variationInfo) {
188 6
                        $variations[] = new Variation($variationInfo);
189
                    }
190 6
                    $this->setVariations($variations); 
191 6
                    break;
192
                }
193 5
                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...
194 5
                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...
195 1
                case 'type': $this->setType($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...
196 1
                case 'audience_conditions': $this->setAudienceConditions($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...
197
                case 'allocation_policy': $this->setAllocationPolicy($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...
198
                case 'earliest': $this->setEarliest($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...
199
                case 'page_ids': $this->setPageIds($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...
200
                default:
201 6
                    throw new Exception('Unknown option found in the Experiment entity: ' . $name);
202
            }
203
        }
204 7
    }
205
    
206
    /**
207
     * Returns this object as array.
208
     */
209 3
    public function toArray()
210
    {
211
        $options = array(
212 3
            'project_id' => $this->getProjectId(),
213 3
            'audience_ids' => $this->getAudienceIds(),
214 3
            'campaign_id' => $this->getCampaignId(),
215 3
            'created' => $this->getCreated(),
216 3
            'description' => $this->getDescription(),
217 3
            'holdback' => $this->getHoldback(),
218 3
            'key' => $this->getKey(),
219 3
            'last_modified' => $this->getLastModified(),
220 3
            'name' => $this->getName(),
221 3
            'schedule' => $this->getSchedule()?$this->getSchedule()->toArray():null,
222 3
            'status' => $this->getStatus(),            
223 3
            'id' => $this->getId(),
224 3
            'is_classic' => $this->getIsClassic(),
225 3
            'type' => $this->getType(),
226 3
            'audience_conditions' => $this->getAudienceConditions(),  
227 3
            'allocation_policy' => $this->getAllocationPolicy(),
228 3
            'earliest' => $this->getEarliest(),
229 3
            'page_ids' => $this->getPageIds(),
230
        );
231
        
232 3
        if ($this->getChanges()) {
233
            
234 3
            $options['changes'] = array();
235
            
236 3
            foreach ($this->getChanges() as $change) {
237 3
                $options['changes'][] = $change->toArray();
238
            }
239
        }
240
        
241 3
        if ($this->getMetrics()) {
242
            
243 3
            $options['metrics'] = array();
244
            
245 3
            foreach ($this->getMetrics() as $metric) {
246 3
                $options['metrics'][] = $metric->toArray();
247
            }
248
        }
249
        
250 3
        if ($this->getVariations()) {
251
            
252 3
            $options['variations'] = array();
253
            
254 3
            foreach ($this->getVariations() as $variation) {
255 3
                $options['variations'][] = $variation->toArray();
256
            }
257
        }
258
        
259
        // Remove options with empty values
260 3
        $cleanedOptions = array();
261 3
        foreach ($options as $name=>$value) {
262 3
            if ($value!==null)
263 3
                $cleanedOptions[$name] = $value;
264
        }
265
        
266 3
        return $cleanedOptions;
267
    }
268
    
269 5
    public function getProjectId()
270
    {
271 5
        return $this->projectId;
272
    }
273
    
274 7
    public function setProjectId($projectId)
275
    {
276 7
        $this->projectId = $projectId;
277 7
    }
278
    
279 4
    public function getAudienceIds()
280
    {
281 4
        return $this->audienceIds;
282
    }
283
    
284 7
    public function setAudienceIds($audienceIds)
285
    {
286 7
        $this->audienceIds = $audienceIds;
287 7
    }
288
    
289 4
    public function getCampaignId()
290
    {
291 4
        return $this->campaignId;
292
    }
293
    
294 7
    public function setCampaignId($campaignId)
295
    {
296 7
        $this->campaignId = $campaignId;
297 7
    }
298
    
299 4
    public function getChanges()
300
    {
301 4
        return $this->changes;
302
    }
303
    
304 7
    public function setChanges($changes)
305
    {
306 7
        $this->changes = $changes;
307 7
    }
308
    
309 4
    public function getCreated()
310
    {
311 4
        return $this->created;
312
    }
313
    
314 5
    public function setCreated($created)
315
    {
316 5
        $this->created = $created;
317 5
    }
318
    
319 4
    public function getDescription()
320
    {
321 4
        return $this->description;
322
    }
323
    
324 7
    public function setDescription($description)
325
    {
326 7
        $this->description = $description;
327 7
    }
328
    
329 4
    public function getHoldback()
330
    {
331 4
        return $this->holdback;
332
    }
333
    
334 7
    public function setHoldback($holdback)
335
    {
336 7
        $this->holdback = $holdback;
337 7
    }
338
    
339 4
    public function getKey()
340
    {
341 4
        return $this->key;
342
    }
343
    
344 7
    public function setKey($key)
345
    {
346 7
        $this->key = $key;
347 7
    }
348
    
349 4
    public function getLastModified()
350
    {
351 4
        return $this->lastModified;
352
    }
353
    
354 5
    public function setLastModified($lastModified)
355
    {
356 5
        $this->lastModified = $lastModified;
357 5
    }
358
    
359 4
    public function getMetrics()
360
    {
361 4
        return $this->metrics;
362
    }
363
    
364 7
    public function setMetrics($metrics)
365
    {
366 7
        $this->metrics = $metrics;
367 7
    }
368
    
369 7
    public function getName()
370
    {
371 7
        return $this->name;
372
    }
373
    
374 7
    public function setName($name)
375
    {
376 7
        $this->name = $name;
377 7
    }
378
    
379 4
    public function getSchedule()
380
    {
381 4
        return $this->schedule;
382
    }
383
    
384 7
    public function setSchedule($schedule)
385
    {
386 7
        $this->schedule = $schedule;
387 7
    }
388
    
389 4
    public function getStatus()
390
    {
391 4
        return $this->status;
392
    }
393
    
394 7
    public function setStatus($status)
395
    {
396 7
        $this->status = $status;
397 7
    }
398
    
399 4
    public function getVariations()
400
    {
401 4
        return $this->variations;
402
    }
403
    
404 7
    public function setVariations($variations)
405
    {
406 7
        $this->variations = $variations;
407 7
    }
408
    
409 4
    public function getId()
410
    {
411 4
        return $this->id;
412
    }
413
    
414 5
    public function setId($id)
415
    {
416 5
        $this->id = $id;
417 5
    }
418
    
419 4
    public function getIsClassic()
420
    {
421 4
        return $this->isClassic;
422
    }
423
    
424 5
    public function setIsClassic($isClassic)
425
    {
426 5
        $this->isClassic = $isClassic;
427 5
    }
428
    
429 3
    public function getType()
430
    {
431 3
        return $this->type;
432
    }
433
    
434 2
    public function setType($type)
435
    {
436 2
        $this->type = $type;
437 2
    }
438
    
439 3
    public function getAudienceConditions()
440
    {
441 3
        return $this->audienceConditions;
442
    }
443
    
444 2
    public function setAudienceConditions($audienceConditions)
445
    {
446 2
        $this->audienceConditions = $audienceConditions;
447 2
    }
448
    
449
    public function getConfig()
450
    {
451
        return $this->config;
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
452
    }
453
    
454
    public function setConfig($config)
455
    {
456
        $this->config = $config;
457
    }
458
    
459 3
    public function getAllocationPolicy()
460
    {
461 3
        return $this->allocationPolicy;
462
    }
463
    
464
    public function setAllocationPolicy($allocationPolicy)
465
    {
466
        $this->allocationPolicy = $allocationPolicy;
467
    }
468
    
469 3
    public function getEarliest()
470
    {
471 3
        return $this->earliest;
472
    }
473
    
474
    public function setEarliest($earliest)
475
    {
476
        $this->earliest = $earliest;
477
    }
478
    
479 3
    public function getPageIds()
480
    {
481 3
        return $this->pageIds;
482
    }
483
    
484
    public function setPageIds($pageIds)
485
    {
486
        $this->pageIds = $pageIds;
487
    }
488
}
489
490