Complex classes like VariantResults 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 VariantResults, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class VariantResults |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * The unique identifier for the Experiment this entity contains results for (if applicable). |
||
| 19 | * @var integer |
||
| 20 | */ |
||
| 21 | private $experimentId; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Indicates that this variant is the baseline that all other entities will |
||
| 25 | * be compared against. Also referred to as the 'Control' or 'Control Group'. |
||
| 26 | * @var boolean |
||
| 27 | */ |
||
| 28 | private $isBaseline; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * |
||
| 32 | * @var type |
||
| 33 | */ |
||
| 34 | private $level; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The relative difference in performance of this variant vs. the baseline |
||
| 38 | * variant. Lift is calculated as follows: (Winning Conversion Rate % - Old |
||
| 39 | * Conversion Rate %) - Old Conversion Rate % = % Improvement |
||
| 40 | * @var Datapoint |
||
| 41 | */ |
||
| 42 | private $lift; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * The name of the variant |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | private $name; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * |
||
| 52 | * @var number |
||
| 53 | */ |
||
| 54 | private $rate; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The scope that this variant represents. Can be 'variation', 'experiment' or 'campaign' |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | private $scope; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * |
||
| 64 | * @var Datapoint |
||
| 65 | */ |
||
| 66 | private $totalIncrease; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * |
||
| 70 | * @var number |
||
| 71 | */ |
||
| 72 | private $value; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * |
||
| 76 | * @var string |
||
| 77 | */ |
||
| 78 | private $variationId; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * |
||
| 82 | * @var type |
||
| 83 | */ |
||
| 84 | private $samples; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * |
||
| 88 | * @var type |
||
| 89 | */ |
||
| 90 | private $variance; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Constructor. |
||
| 94 | */ |
||
| 95 | 3 | public function __construct($options = array()) |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Returns this object as array. |
||
| 119 | */ |
||
| 120 | 1 | public function toArray() |
|
| 146 | |||
| 147 | 1 | public function getExperimentId() |
|
| 151 | |||
| 152 | 3 | public function setExperimentId($experimentId) |
|
| 156 | |||
| 157 | 1 | public function getIsBaseline() |
|
| 161 | |||
| 162 | 3 | public function setIsBaseline($isBaseline) |
|
| 166 | |||
| 167 | 1 | public function getLevel() |
|
| 171 | |||
| 172 | public function setLevel($level) |
||
| 176 | |||
| 177 | 1 | public function getLift() |
|
| 181 | |||
| 182 | 3 | public function setLift($lift) |
|
| 186 | |||
| 187 | 1 | public function getName() |
|
| 191 | |||
| 192 | 3 | public function setName($name) |
|
| 196 | |||
| 197 | 1 | public function getRate() |
|
| 201 | |||
| 202 | 3 | public function setRate($rate) |
|
| 206 | |||
| 207 | 1 | public function getScope() |
|
| 211 | |||
| 212 | 3 | public function setScope($scope) |
|
| 216 | |||
| 217 | 1 | public function getTotalIncrease() |
|
| 221 | |||
| 222 | 3 | public function setTotalIncrease($totalIncrease) |
|
| 226 | |||
| 227 | 1 | public function getValue() |
|
| 231 | |||
| 232 | 3 | public function setValue($value) |
|
| 236 | |||
| 237 | 1 | public function getVariationId() |
|
| 241 | |||
| 242 | 3 | public function setVariationId($variationId) |
|
| 246 | |||
| 247 | 1 | public function getSamples() |
|
| 251 | |||
| 252 | public function setSamples($samples) |
||
| 256 | |||
| 257 | 1 | public function getVariance() |
|
| 261 | |||
| 262 | public function setVariance($variance) |
||
| 266 | } |
||
| 267 | |||
| 275 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.