Complex classes like Notifications 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 Notifications, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
33 | class Notifications { |
||
34 | const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
||
35 | |||
36 | /** @var AddressHandler */ |
||
37 | private $addressHandler; |
||
38 | |||
39 | /** @var IClientService */ |
||
40 | private $httpClientService; |
||
41 | |||
42 | /** @var DiscoveryManager */ |
||
43 | private $discoveryManager; |
||
44 | |||
45 | 1 | /** @var IJobList */ |
|
46 | private $jobList; |
||
47 | |||
48 | /** @var IConfig */ |
||
49 | 1 | private $config; |
|
50 | 1 | ||
51 | 1 | /** |
|
52 | * @param AddressHandler $addressHandler |
||
53 | * @param IClientService $httpClientService |
||
54 | * @param DiscoveryManager $discoveryManager |
||
55 | * @param IJobList $jobList |
||
56 | * @param IConfig $config |
||
57 | */ |
||
58 | public function __construct( |
||
71 | |||
72 | /** |
||
73 | * send server-to-server share to remote server |
||
74 | * |
||
75 | * @param string $token |
||
76 | * @param string $shareWith |
||
77 | * @param string $name |
||
78 | * @param int $remote_id |
||
79 | * @param string $owner |
||
80 | * @param string $ownerFederatedId |
||
81 | * @param string $sharedBy |
||
82 | * @param string $sharedByFederatedId |
||
83 | * @return bool |
||
84 | * @throws \OC\HintException |
||
85 | * @throws \OC\ServerNotAvailableException |
||
86 | */ |
||
87 | public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) { |
||
93 | |||
94 | /** |
||
95 | * ask owner to re-share the file with the given user |
||
96 | * |
||
97 | * @param string $token |
||
98 | * @param int $id remote Id |
||
99 | * @param int $shareId internal share Id |
||
100 | * @param string $remote remote address of the owner |
||
101 | * @param string $shareWith |
||
102 | * @param int $permission |
||
103 | * @return bool |
||
104 | * @throws \Exception |
||
105 | */ |
||
106 | public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) { |
||
132 | |||
133 | /** |
||
134 | * send server-to-server unshare to remote server |
||
135 | * |
||
136 | * @param string $remote url |
||
137 | * @param int $id share id |
||
138 | * @param string $token |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function sendRemoteUnShare($remote, $id, $token) { |
||
144 | |||
145 | /** |
||
146 | * send server-to-server unshare to remote server |
||
147 | * |
||
148 | * @param string $remote url |
||
149 | * @param int $id share id |
||
150 | * @param string $token |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function sendRevokeShare($remote, $id, $token) { |
||
156 | |||
157 | /** |
||
158 | * send notification to remote server if the permissions was changed |
||
159 | * |
||
160 | * @param string $remote |
||
161 | * @param int $remoteId |
||
162 | * @param string $token |
||
163 | * @param int $permissions |
||
164 | * @return bool |
||
165 | */ |
||
166 | public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
||
169 | |||
170 | /** |
||
171 | * forward accept reShare to remote server |
||
172 | * |
||
173 | * @param string $remote |
||
174 | * @param int $remoteId |
||
175 | * @param string $token |
||
176 | */ |
||
177 | public function sendAcceptShare($remote, $remoteId, $token) { |
||
180 | |||
181 | /** |
||
182 | * forward decline reShare to remote server |
||
183 | * |
||
184 | * @param string $remote |
||
185 | * @param int $remoteId |
||
186 | * @param string $token |
||
187 | */ |
||
188 | public function sendDeclineShare($remote, $remoteId, $token) { |
||
191 | |||
192 | /** |
||
193 | * inform remote server whether server-to-server share was accepted/declined |
||
194 | * |
||
195 | * @param string $remote |
||
196 | * @param string $token |
||
197 | * @param int $remoteId Share id on the remote host |
||
198 | * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
||
199 | * @param array $data |
||
200 | * @param int $try |
||
201 | * @return boolean |
||
202 | * @throws \Exception |
||
203 | */ |
||
204 | public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
||
237 | |||
238 | /** |
||
239 | * return current timestamp |
||
240 | * |
||
241 | * @return int |
||
242 | */ |
||
243 | protected function getTimestamp() { |
||
246 | |||
247 | /** |
||
248 | * try http post first with https and then with http as a fallback |
||
249 | * |
||
250 | * @param string $remoteDomain |
||
251 | * @param string $urlSuffix |
||
252 | * @param array $fields post parameters |
||
253 | * @return array |
||
254 | * @throws \Exception |
||
255 | */ |
||
256 | protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $useOcm = false) { |
||
301 | |||
302 | protected function sendOcmRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) { |
||
334 | |||
335 | protected function sendPreOcmRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) { |
||
365 | } |
||
366 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.