Complex classes like SubStatement 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 SubStatement, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | final class SubStatement extends Object |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var Verb $verb The {@link Verb} |
||
| 23 | */ |
||
| 24 | private $verb; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var Actor The {@link Actor} |
||
| 28 | */ |
||
| 29 | private $actor; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var Object The {@link Object} |
||
| 33 | */ |
||
| 34 | private $object; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var Result The {@link Activity} {@link Result} |
||
| 38 | */ |
||
| 39 | private $result; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var \DateTime The timestamp of when the events described in this statement occurred |
||
| 43 | */ |
||
| 44 | private $created; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var Context The {@link Statement} {@link Context} |
||
| 48 | */ |
||
| 49 | private $context; |
||
| 50 | |||
| 51 | private $attachments; |
||
| 52 | |||
| 53 | public function __construct(Actor $actor, Verb $verb, Object $object, Result $result = null, Context $context = null, \DateTime $created = null, array $attachments = null) |
||
| 67 | |||
| 68 | public function withActor(Actor $actor) |
||
| 75 | |||
| 76 | public function withVerb(Verb $verb) |
||
| 83 | |||
| 84 | public function withObject(Object $object) |
||
| 91 | |||
| 92 | public function withResult(Result $result) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @deprecated since 1.2, to be removed in 3.0 |
||
| 102 | */ |
||
| 103 | public function withTimestamp(\DateTime $timestamp = null) |
||
| 112 | |||
| 113 | public function withCreated(\DateTime $created = null) |
||
| 120 | |||
| 121 | public function withContext(Context $context) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param Attachment[]|null $attachments |
||
| 131 | * |
||
| 132 | * @return self |
||
| 133 | */ |
||
| 134 | public function withAttachments(array $attachments = null) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Returns the Statement's {@link Verb}. |
||
| 144 | * |
||
| 145 | * @return Verb The Verb |
||
| 146 | */ |
||
| 147 | public function getVerb() |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Returns the Statement's {@link Actor}. |
||
| 154 | * |
||
| 155 | * @return Actor The Actor |
||
| 156 | */ |
||
| 157 | public function getActor() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Returns the Statement's {@link Object}. |
||
| 164 | * |
||
| 165 | * @return \Xabbuh\XApi\Model\Object The Object |
||
| 166 | */ |
||
| 167 | public function getObject() |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Returns the {@link Activity} {@link Result}. |
||
| 174 | * |
||
| 175 | * @return Result The Result |
||
| 176 | */ |
||
| 177 | public function getResult() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Returns the timestamp of when the events described in this statement |
||
| 184 | * occurred. |
||
| 185 | * |
||
| 186 | * @return \DateTime The timestamp |
||
| 187 | * |
||
| 188 | * @deprecated since 1.2, to be removed in 3.0 |
||
| 189 | */ |
||
| 190 | public function getTimestamp() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Returns the timestamp of when the events described in this statement |
||
| 199 | * occurred. |
||
| 200 | * |
||
| 201 | * @return \DateTime The timestamp |
||
| 202 | */ |
||
| 203 | public function getCreated() |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Returns the {@link Statement} {@link Context}. |
||
| 210 | * |
||
| 211 | * @return Context The Context |
||
| 212 | */ |
||
| 213 | public function getContext() |
||
| 217 | |||
| 218 | public function getAttachments() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Tests whether or not this Statement is a void Statement (i.e. it voids |
||
| 225 | * another Statement). |
||
| 226 | * |
||
| 227 | * @return bool True if the Statement voids another Statement, false otherwise |
||
| 228 | */ |
||
| 229 | public function isVoidStatement() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * {@inheritdoc} |
||
| 236 | */ |
||
| 237 | public function equals(Object $statement) |
||
| 299 | } |
||
| 300 |