Complex classes like TPanelStyle 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 TPanelStyle, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class TPanelStyle extends TStyle |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var string the URL of the background image for the panel component |
||
| 29 | */ |
||
| 30 | private $_backImageUrl=null; |
||
| 31 | /** |
||
| 32 | * @var string alignment of the content in the panel. |
||
| 33 | */ |
||
| 34 | private $_direction=null; |
||
| 35 | /** |
||
| 36 | * @var string horizontal alignment of the contents within the panel |
||
| 37 | */ |
||
| 38 | private $_horizontalAlign=null; |
||
| 39 | /** |
||
| 40 | * @var string visibility and position of scroll bars |
||
| 41 | */ |
||
| 42 | private $_scrollBars=null; |
||
| 43 | /** |
||
| 44 | * @var boolean whether the content wraps within the panel |
||
| 45 | */ |
||
| 46 | private $_wrap=null; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Returns an array with the names of all variables of this object that should NOT be serialized |
||
| 50 | * because their value is the default one or useless to be cached for the next page loads. |
||
| 51 | * Reimplement in derived classes to add new variables, but remember to also to call the parent |
||
| 52 | * implementation first. |
||
| 53 | */ |
||
| 54 | protected function _getZappableSleepProps(&$exprops) |
||
| 55 | { |
||
| 56 | parent::_getZappableSleepProps($exprops); |
||
| 57 | if ($this->_backImageUrl===null) |
||
| 58 | $exprops[] = "\0TPanelStyle\0_backImageUrl"; |
||
| 59 | if ($this->_direction===null) |
||
| 60 | $exprops[] = "\0TPanelStyle\0_direction"; |
||
| 61 | if ($this->_horizontalAlign===null) |
||
| 62 | $exprops[] = "\0TPanelStyle\0_horizontalAlign"; |
||
| 63 | if ($this->_scrollBars===null) |
||
| 64 | $exprops[] = "\0TPanelStyle\0_scrollBars"; |
||
| 65 | if ($this->_wrap===null) |
||
| 66 | $exprops[] = "\0TPanelStyle\0_wrap"; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Adds attributes related to CSS styles to renderer. |
||
| 71 | * This method overrides the parent implementation. |
||
| 72 | * @param THtmlWriter the writer used for the rendering purpose |
||
| 73 | */ |
||
| 74 | public function addAttributesToRender($writer) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @return string the URL of the background image for the panel component. |
||
| 106 | */ |
||
| 107 | public function getBackImageUrl() |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Sets the URL of the background image for the panel component. |
||
| 114 | * @param string the URL |
||
| 115 | */ |
||
| 116 | public function setBackImageUrl($value) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return TContentDirection alignment of the content in the panel. Defaults to TContentDirection::NotSet. |
||
| 123 | */ |
||
| 124 | public function getDirection() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param TContentDirection alignment of the content in the panel. |
||
| 131 | */ |
||
| 132 | public function setDirection($value) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return boolean whether the content wraps within the panel. Defaults to true. |
||
| 139 | */ |
||
| 140 | public function getWrap() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Sets the value indicating whether the content wraps within the panel. |
||
| 147 | * @param boolean whether the content wraps within the panel. |
||
| 148 | */ |
||
| 149 | public function setWrap($value) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return THorizontalAlign the horizontal alignment of the contents within the panel, defaults to THorizontalAlign::NotSet. |
||
| 156 | */ |
||
| 157 | public function getHorizontalAlign() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Sets the horizontal alignment of the contents within the panel. |
||
| 164 | * @param THorizontalAlign the horizontal alignment |
||
| 165 | */ |
||
| 166 | public function setHorizontalAlign($value) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @return TScrollBars the visibility and position of scroll bars in a panel control, defaults to TScrollBars::None. |
||
| 173 | */ |
||
| 174 | public function getScrollBars() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param TScrollBars the visibility and position of scroll bars in a panel control. |
||
| 181 | */ |
||
| 182 | public function setScrollBars($value) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Sets the style attributes to default values. |
||
| 189 | * This method overrides the parent implementation by |
||
| 190 | * resetting additional TPanelStyle specific attributes. |
||
| 191 | */ |
||
| 192 | public function reset() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Copies the fields in a new style to this style. |
||
| 204 | * If a style field is set in the new style, the corresponding field |
||
| 205 | * in this style will be overwritten. |
||
| 206 | * @param TStyle the new style |
||
| 207 | */ |
||
| 208 | public function copyFrom($style) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Merges the style with a new one. |
||
| 228 | * If a style field is not set in this style, it will be overwritten by |
||
| 229 | * the new one. |
||
| 230 | * @param TStyle the new style |
||
| 231 | */ |
||
| 232 | public function mergeWith($style) |
||
| 249 | } |
||
| 250 | |||
| 296 |
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.