Complex classes like ManyToManyParser 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 ManyToManyParser, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class ManyToManyParser { |
||
| 13 | private $table; |
||
| 14 | private $member; |
||
| 15 | private $joinTable; |
||
| 16 | private $myFkField; |
||
| 17 | private $fkField; |
||
| 18 | private $targetEntity; |
||
| 19 | private $targetEntityClass; |
||
| 20 | private $targetEntityTable; |
||
| 21 | private $myPk; |
||
| 22 | private $inversedBy; |
||
| 23 | private $pk; |
||
| 24 | private $instance; |
||
| 25 | private $whereValues; |
||
| 26 | |||
| 27 | public function __construct($instance, $member=null) { |
||
| 32 | |||
| 33 | public function init($annot=false) { |
||
| 48 | |||
| 49 | private function _init($class,$annot){ |
||
| 80 | |||
| 81 | public function getMember() { |
||
| 84 | |||
| 85 | public function setMember($member) { |
||
| 89 | |||
| 90 | public function getJoinTable() { |
||
| 93 | |||
| 94 | public function setJoinTable($joinTable) { |
||
| 98 | |||
| 99 | public function getMyFkField() { |
||
| 102 | |||
| 103 | public function setMyFkField($myFkField) { |
||
| 107 | |||
| 108 | public function getFkField() { |
||
| 111 | |||
| 112 | public function setFkField($fkField) { |
||
| 116 | |||
| 117 | public function getTargetEntity() { |
||
| 120 | |||
| 121 | public function setTargetEntity($targetEntity) { |
||
| 125 | |||
| 126 | public function getTargetEntityClass() { |
||
| 129 | |||
| 130 | public function setTargetEntityClass($targetEntityClass) { |
||
| 134 | |||
| 135 | public function getTargetEntityTable() { |
||
| 138 | |||
| 139 | public function setTargetEntityTable($targetEntityTable) { |
||
| 143 | |||
| 144 | public function getMyPk() { |
||
| 147 | |||
| 148 | public function setMyPk($myPk) { |
||
| 152 | |||
| 153 | public function getPk() { |
||
| 156 | |||
| 157 | public function setPk($pk) { |
||
| 161 | |||
| 162 | public function getInversedBy() { |
||
| 165 | |||
| 166 | public function setInversedBy($inversedBy) { |
||
| 170 | |||
| 171 | public function getInstance() { |
||
| 174 | |||
| 175 | public function setInstance($instance) { |
||
| 179 | |||
| 180 | public function getSQL($alias="",$aliases=null){ |
||
| 196 | |||
| 197 | public function getConcatSQL(){ |
||
| 200 | |||
| 201 | public function getParserWhereMask($mask="'{value}'"){ |
||
| 204 | |||
| 205 | private function getParserConcatWhereMask($mask="'{value}'"){ |
||
| 208 | |||
| 209 | |||
| 210 | public function generateConcatSQL(){ |
||
| 220 | |||
| 221 | public function addValue($value){ |
||
| 224 | /** |
||
| 225 | * @return array|null |
||
| 226 | */ |
||
| 227 | public function getWhereValues() { |
||
| 232 | |||
| 233 | } |
||
| 234 |