Complex classes like Locked 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 Locked, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | final class Locked implements Message |
||
| 20 | { |
||
| 21 | private $message; |
||
| 22 | |||
| 23 | 27 | public function __construct(Message $message) |
|
| 27 | |||
| 28 | 2 | public function hasContentType(): bool |
|
| 32 | |||
| 33 | 1 | public function contentType(): ContentType |
|
| 37 | |||
| 38 | 1 | public function withContentType(ContentType $contentType): Message |
|
| 42 | |||
| 43 | 2 | public function hasContentEncoding(): bool |
|
| 47 | |||
| 48 | 1 | public function contentEncoding(): ContentEncoding |
|
| 52 | |||
| 53 | 1 | public function withContentEncoding(ContentEncoding $contentEncoding): Message |
|
| 57 | |||
| 58 | 2 | public function hasHeaders(): bool |
|
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | 1 | public function headers(): MapInterface |
|
| 70 | |||
| 71 | 1 | public function withHeaders(MapInterface $headers): Message |
|
| 75 | |||
| 76 | 2 | public function hasDeliveryMode(): bool |
|
| 80 | |||
| 81 | 1 | public function deliveryMode(): DeliveryMode |
|
| 85 | |||
| 86 | 1 | public function withDeliveryMode(DeliveryMode $deliveryMode): Message |
|
| 90 | |||
| 91 | 2 | public function hasPriority(): bool |
|
| 95 | |||
| 96 | 1 | public function priority(): Priority |
|
| 100 | |||
| 101 | 1 | public function withPriority(Priority $priority): Message |
|
| 105 | |||
| 106 | 2 | public function hasCorrelationId(): bool |
|
| 110 | |||
| 111 | 1 | public function correlationId(): CorrelationId |
|
| 115 | |||
| 116 | 1 | public function withCorrelationId(CorrelationId $correlationId): Message |
|
| 120 | |||
| 121 | 2 | public function hasReplyTo(): bool |
|
| 125 | |||
| 126 | 1 | public function replyTo(): ReplyTo |
|
| 130 | |||
| 131 | 1 | public function withReplyTo(ReplyTo $replyTo): Message |
|
| 135 | |||
| 136 | 2 | public function hasExpiration(): bool |
|
| 140 | |||
| 141 | 1 | public function expiration(): ElapsedPeriod |
|
| 145 | |||
| 146 | 1 | public function withExpiration(ElapsedPeriod $expiration): Message |
|
| 150 | |||
| 151 | 2 | public function hasId(): bool |
|
| 155 | |||
| 156 | 1 | public function id(): Id |
|
| 160 | |||
| 161 | 1 | public function withId(Id $id): Message |
|
| 165 | |||
| 166 | 2 | public function hasTimestamp(): bool |
|
| 170 | |||
| 171 | 1 | public function timestamp(): PointInTimeInterface |
|
| 175 | |||
| 176 | 1 | public function withTimestamp(PointInTimeInterface $timestamp): Message |
|
| 180 | |||
| 181 | 2 | public function hasType(): bool |
|
| 185 | |||
| 186 | 1 | public function type(): Type |
|
| 190 | |||
| 191 | 1 | public function withType(Type $type): Message |
|
| 195 | |||
| 196 | 2 | public function hasUserId(): bool |
|
| 200 | |||
| 201 | 1 | public function userId(): UserId |
|
| 205 | |||
| 206 | 1 | public function withUserId(UserId $userId): Message |
|
| 210 | |||
| 211 | 2 | public function hasAppId(): bool |
|
| 215 | |||
| 216 | 1 | public function appId(): AppId |
|
| 220 | |||
| 221 | 1 | public function withAppId(AppId $appId): Message |
|
| 225 | |||
| 226 | 1 | public function body(): Str |
|
| 230 | } |
||
| 231 |