Complex classes like Layout 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 Layout, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class Layout extends AbstractEntity |
||
| 29 | { |
||
| 30 | // 配置ID |
||
| 31 | /** 配置ID: 未使用 */ |
||
| 32 | const TARGET_ID_UNUSED = 0; |
||
| 33 | const TARGET_ID_HEAD = 1; |
||
| 34 | const TARGET_ID_BODY_AFTER = 2; |
||
| 35 | const TARGET_ID_HEADER = 3; |
||
| 36 | const TARGET_ID_CONTENTS_TOP = 4; |
||
| 37 | const TARGET_ID_SIDE_LEFT = 5; |
||
| 38 | const TARGET_ID_MAIN_TOP = 6; |
||
| 39 | const TARGET_ID_MAIN_BOTTOM = 7; |
||
| 40 | const TARGET_ID_SIDE_RIGHT = 8; |
||
| 41 | const TARGET_ID_CONTENTS_BOTTOM = 9; |
||
| 42 | const TARGET_ID_FOOTER = 10; |
||
| 43 | const TARGET_ID_DRAWER = 11; |
||
| 44 | const TARGET_ID_CLOSE_BODY_BEFORE = 12; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * トップページ用レイアウト |
||
| 48 | */ |
||
| 49 | const DEFAULT_LAYOUT_TOP_PAGE = 1; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * 下層ページ用レイアウト |
||
| 53 | */ |
||
| 54 | const DEFAULT_LAYOUT_UNDERLAYER_PAGE = 2; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | public function __toString() |
||
| 63 | |||
| 64 | public function isDefault() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return Page[] |
||
| 71 | */ |
||
| 72 | public function getPages() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param integer|null $targetId |
||
| 84 | * |
||
| 85 | * @return Block[] |
||
| 86 | */ |
||
| 87 | public function getBlocks($targetId = null) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @param integer $targetId |
||
| 119 | * |
||
| 120 | * @return BlockPosition[] |
||
| 121 | */ |
||
| 122 | public function getBlockPositionsByTargetId($targetId) |
||
| 130 | |||
| 131 | public function getUnused() |
||
| 135 | |||
| 136 | public function getHead() |
||
| 140 | |||
| 141 | public function getBodyAfter() |
||
| 145 | |||
| 146 | public function getHeader() |
||
| 150 | |||
| 151 | public function getContentsTop() |
||
| 155 | |||
| 156 | public function getSideLeft() |
||
| 160 | |||
| 161 | public function getMainTop() |
||
| 165 | |||
| 166 | public function getMainBottom() |
||
| 170 | |||
| 171 | public function getSideRight() |
||
| 175 | |||
| 176 | public function getContentsBottom() |
||
| 180 | |||
| 181 | public function getFooter() |
||
| 185 | |||
| 186 | public function getDrawer() |
||
| 190 | |||
| 191 | public function getCloseBodyBefore() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Get ColumnNum |
||
| 198 | * |
||
| 199 | * @return integer |
||
| 200 | */ |
||
| 201 | public function getColumnNum() |
||
| 205 | |||
| 206 | // ----------------------- |
||
| 207 | // generated by doctrine |
||
| 208 | // ----------------------- |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @var integer |
||
| 212 | * |
||
| 213 | * @ORM\Column(name="id", type="integer", options={"unsigned":true}) |
||
| 214 | * @ORM\Id |
||
| 215 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
| 216 | */ |
||
| 217 | private $id; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @var string |
||
| 221 | * |
||
| 222 | * @ORM\Column(name="layout_name", type="string", length=255, nullable=true) |
||
| 223 | */ |
||
| 224 | private $name; |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @var \DateTime |
||
| 228 | * |
||
| 229 | * @ORM\Column(name="create_date", type="datetimetz") |
||
| 230 | */ |
||
| 231 | private $create_date; |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @var \DateTime |
||
| 235 | * |
||
| 236 | * @ORM\Column(name="update_date", type="datetimetz") |
||
| 237 | */ |
||
| 238 | private $update_date; |
||
| 239 | |||
| 240 | /** |
||
| 241 | * @var \Doctrine\Common\Collections\Collection |
||
| 242 | * |
||
| 243 | * @ORM\OneToMany(targetEntity="Eccube\Entity\BlockPosition", mappedBy="Layout", cascade={"persist","remove"}) |
||
| 244 | */ |
||
| 245 | private $BlockPositions; |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @var \Doctrine\Common\Collections\Collection |
||
| 249 | * |
||
| 250 | * @ORM\OneToMany(targetEntity="Eccube\Entity\PageLayout", mappedBy="Layout", cascade={"persist","remove"}) |
||
| 251 | * @ORM\OrderBy({"sort_no" = "ASC"}) |
||
| 252 | */ |
||
| 253 | private $PageLayouts; |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @var \Eccube\Entity\Master\DeviceType |
||
| 257 | * |
||
| 258 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\DeviceType") |
||
| 259 | * @ORM\JoinColumns({ |
||
| 260 | * @ORM\JoinColumn(name="device_type_id", referencedColumnName="id") |
||
| 261 | * }) |
||
| 262 | */ |
||
| 263 | private $DeviceType; |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Constructor |
||
| 267 | */ |
||
| 268 | public function __construct() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Get id |
||
| 276 | * |
||
| 277 | * @return integer |
||
| 278 | */ |
||
| 279 | public function getId() |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Set name |
||
| 286 | * |
||
| 287 | * @param string $name |
||
| 288 | * |
||
| 289 | * @return Layout |
||
| 290 | */ |
||
| 291 | public function setName($name) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Get name |
||
| 300 | * |
||
| 301 | * @return string |
||
| 302 | */ |
||
| 303 | public function getName() |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Set createDate |
||
| 310 | * |
||
| 311 | * @param \DateTime $createDate |
||
| 312 | * |
||
| 313 | * @return Layout |
||
| 314 | */ |
||
| 315 | public function setCreateDate($createDate) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Get createDate |
||
| 324 | * |
||
| 325 | * @return \DateTime |
||
| 326 | */ |
||
| 327 | public function getCreateDate() |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Set updateDate |
||
| 334 | * |
||
| 335 | * @param \DateTime $updateDate |
||
| 336 | * |
||
| 337 | * @return Layout |
||
| 338 | */ |
||
| 339 | public function setUpdateDate($updateDate) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Get updateDate |
||
| 348 | * |
||
| 349 | * @return \DateTime |
||
| 350 | */ |
||
| 351 | public function getUpdateDate() |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Add blockPosition |
||
| 358 | * |
||
| 359 | * @param \Eccube\Entity\BlockPosition $blockPosition |
||
| 360 | * |
||
| 361 | * @return Layout |
||
| 362 | */ |
||
| 363 | public function addBlockPosition(\Eccube\Entity\BlockPosition $blockPosition) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Remove blockPosition |
||
| 372 | * |
||
| 373 | * @param \Eccube\Entity\BlockPosition $blockPosition |
||
| 374 | */ |
||
| 375 | public function removeBlockPosition(\Eccube\Entity\BlockPosition $blockPosition) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Get blockPositions |
||
| 382 | * |
||
| 383 | * @return \Doctrine\Common\Collections\Collection |
||
| 384 | */ |
||
| 385 | public function getBlockPositions() |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Add pageLayoutLayout |
||
| 392 | * |
||
| 393 | * @param \Eccube\Entity\PageLayout $PageLayout |
||
| 394 | * |
||
| 395 | * @return Layout |
||
| 396 | */ |
||
| 397 | public function addPageLayout(\Eccube\Entity\PageLayout $PageLayout) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Remove pageLayoutLayout |
||
| 406 | * |
||
| 407 | * @param \Eccube\Entity\PageLayout $PageLayout |
||
| 408 | */ |
||
| 409 | public function removePageLayout(\Eccube\Entity\PageLayout $PageLayout) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Get pageLayoutLayouts |
||
| 416 | * |
||
| 417 | * @return \Doctrine\Common\Collections\Collection |
||
| 418 | */ |
||
| 419 | public function getPageLayouts() |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Set deviceType |
||
| 426 | * |
||
| 427 | * @param \Eccube\Entity\Master\DeviceType $deviceType |
||
| 428 | * |
||
| 429 | * @return Layout |
||
| 430 | */ |
||
| 431 | public function setDeviceType(\Eccube\Entity\Master\DeviceType $deviceType = null) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Get deviceType |
||
| 440 | * |
||
| 441 | * @return \Eccube\Entity\Master\DeviceType |
||
| 442 | */ |
||
| 443 | public function getDeviceType() |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Check layout can delete or not |
||
| 450 | * |
||
| 451 | * @return boolean |
||
| 452 | */ |
||
| 453 | public function isDeletable() |
||
| 461 | } |
||
| 462 | } |
||
| 463 |