Complex classes like Page 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 Page, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class Page |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * URL of the Page |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $editUrl; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Name of the Page |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | private $name; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * ID of the Page's project |
||
| 30 | * @var integer |
||
| 31 | */ |
||
| 32 | private $projectId; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Code to determine Experiment start |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $activationCode; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Page activation type. Can be immediate, manual, polling or callback |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $activationType; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | private $apiName; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Whether the Page has been archived |
||
| 54 | * @var boolean |
||
| 55 | */ |
||
| 56 | private $archived; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * The category this Page is grouped under. Can be article, cart, category, |
||
| 60 | * checkout, home, landing_page, pricing, product_detail, search_results or other |
||
| 61 | * @var string |
||
| 62 | */ |
||
| 63 | private $category; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Conditions that activate the Page |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | private $conditions; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Unique string identifier for this page within the project. |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | private $key; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Type of Page. Can be single_url, url_set or global |
||
| 79 | * @var string |
||
| 80 | */ |
||
| 81 | private $pageType; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Date created |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | private $created; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * The unique identifier of the Page |
||
| 91 | * @var integer |
||
| 92 | */ |
||
| 93 | private $id; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Date last modified |
||
| 97 | * @var string |
||
| 98 | */ |
||
| 99 | private $lastModified; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Constructor. |
||
| 103 | */ |
||
| 104 | 7 | public function __construct($options = array()) |
|
| 127 | |||
| 128 | /** |
||
| 129 | * Returns this object as array. |
||
| 130 | */ |
||
| 131 | 3 | public function toArray() |
|
| 159 | |||
| 160 | 5 | public function getEditUrl() |
|
| 164 | |||
| 165 | 7 | public function setEditUrl($editUrl) |
|
| 169 | |||
| 170 | 7 | public function getName() |
|
| 174 | |||
| 175 | 7 | public function setName($name) |
|
| 179 | |||
| 180 | 5 | public function getProjectId() |
|
| 184 | |||
| 185 | 7 | public function setProjectId($projectId) |
|
| 189 | |||
| 190 | 5 | public function getActivationCode() |
|
| 194 | |||
| 195 | 4 | public function setActivationCode($activationCode) |
|
| 199 | |||
| 200 | 5 | public function getActivationType() |
|
| 204 | |||
| 205 | 7 | public function setActivationType($activationType) |
|
| 209 | |||
| 210 | 3 | public function getApiName() |
|
| 214 | |||
| 215 | public function setApiName($apiName) |
||
| 219 | |||
| 220 | 5 | public function getArchived() |
|
| 224 | |||
| 225 | 7 | public function setArchived($archived) |
|
| 229 | |||
| 230 | 3 | public function getCategory() |
|
| 234 | |||
| 235 | 7 | public function setCategory($category) |
|
| 239 | |||
| 240 | 3 | public function getConditions() |
|
| 244 | |||
| 245 | 7 | public function setConditions($conditions) |
|
| 249 | |||
| 250 | 3 | public function getKey() |
|
| 254 | |||
| 255 | 7 | public function setKey($key) |
|
| 259 | |||
| 260 | 3 | public function getPageType() |
|
| 264 | |||
| 265 | 7 | public function setPageType($pageType) |
|
| 269 | |||
| 270 | 3 | public function getCreated() |
|
| 274 | |||
| 275 | 7 | public function setCreated($created) |
|
| 279 | |||
| 280 | 3 | public function getId() |
|
| 284 | |||
| 285 | 7 | public function setId($id) |
|
| 289 | |||
| 290 | 3 | public function getLastModified() |
|
| 294 | |||
| 295 | 7 | public function setLastModified($lastModified) |
|
| 299 | } |
||
| 300 | |||
| 308 |