Complex classes like Activity 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 Activity, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class Activity implements \OCP\Activity\IExtension { |
||
| 29 | const FILTER_PASSMAN = 'passman'; |
||
| 30 | const APP_NAME = 'passman'; |
||
| 31 | const TYPE_ITEM_ACTION = 'passman_item_action'; |
||
| 32 | const TYPE_ITEM_EXPIRED = 'passman_item_expired'; |
||
| 33 | const TYPE_ITEM_SHARED = 'passman_item_shared'; |
||
| 34 | const TYPE_ITEM_RENAMED = 'passman_item_renamed'; |
||
| 35 | |||
| 36 | const SUBJECT_ITEM_CREATED = 'item_created'; |
||
| 37 | const SUBJECT_ITEM_CREATED_SELF = 'item_created_self'; |
||
| 38 | const SUBJECT_ITEM_EDITED = 'item_edited'; |
||
| 39 | const SUBJECT_ITEM_EDITED_SELF = 'item_edited_self'; |
||
| 40 | const SUBJECT_APPLY_REV = 'item_apply_revision'; |
||
| 41 | const SUBJECT_APPLY_REV_SELF = 'item_apply_revision_self'; |
||
| 42 | const SUBJECT_ITEM_DELETED = 'item_deleted'; |
||
| 43 | const SUBJECT_ITEM_DELETED_SELF = 'item_deleted_self'; |
||
| 44 | const SUBJECT_ITEM_RECOVERED = 'item_recovered'; |
||
| 45 | const SUBJECT_ITEM_RECOVERED_SELF = 'item_recovered_self'; |
||
| 46 | const SUBJECT_ITEM_DESTROYED = 'item_destroyed'; |
||
| 47 | const SUBJECT_ITEM_DESTROYED_SELF = 'item_destroyed_self'; |
||
| 48 | const SUBJECT_ITEM_EXPIRED = 'item_expired'; |
||
| 49 | const SUBJECT_ITEM_SHARED = 'item_shared'; |
||
| 50 | const SUBJECT_ITEM_SHARE_RECEIVED = 'item_share_received'; |
||
| 51 | const SUBJECT_ITEM_SHARED_PUBLICLY = 'item_shared_publicly'; |
||
| 52 | const SUBJECT_ITEM_RENAMED = 'item_renamed'; |
||
| 53 | const SUBJECT_ITEM_RENAMED_SELF = 'item_renamed_self'; |
||
| 54 | |||
| 55 | |||
| 56 | protected $URLGenerator; |
||
| 57 | |||
| 58 | public function __construct( IURLGenerator $URLGenerator) { |
||
| 61 | |||
| 62 | |||
| 63 | /** |
||
| 64 | * The extension can return an array of additional notification types. |
||
| 65 | * If no additional types are to be added false is to be returned |
||
| 66 | * |
||
| 67 | * @param string $languageCode |
||
| 68 | * @return array|false |
||
| 69 | */ |
||
| 70 | public function getNotificationTypes($languageCode) { |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The extension can filter the types based on the filter if required. |
||
| 82 | * In case no filter is to be applied false is to be returned unchanged. |
||
| 83 | * |
||
| 84 | * @param array $types |
||
| 85 | * @param string $filter |
||
| 86 | * @return array|false |
||
| 87 | */ |
||
| 88 | public function filterNotificationTypes($types, $filter) { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * For a given method additional types to be displayed in the settings can be returned. |
||
| 94 | * In case no additional types are to be added false is to be returned. |
||
| 95 | * |
||
| 96 | * @param string $method |
||
| 97 | * @return array|false |
||
| 98 | */ |
||
| 99 | public function getDefaultTypes($method) { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * The extension can translate a given message to the requested languages. |
||
| 119 | * If no translation is available false is to be returned. |
||
| 120 | * |
||
| 121 | * @param string $app |
||
| 122 | * @param string $text |
||
| 123 | * @param array $params |
||
| 124 | * @param boolean $stripPath |
||
| 125 | * @param boolean $highlightParams |
||
| 126 | * @param string $languageCode |
||
| 127 | * @return string|false |
||
| 128 | */ |
||
| 129 | public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
||
| 173 | |||
| 174 | /** |
||
| 175 | * The extension can define the type of parameters for translation |
||
| 176 | * |
||
| 177 | * Currently known types are: |
||
| 178 | * * file => will strip away the path of the file and add a tooltip with it |
||
| 179 | * * username => will add the avatar of the user |
||
| 180 | * |
||
| 181 | * @param string $app |
||
| 182 | * @param string $text |
||
| 183 | * @return array|false |
||
| 184 | */ |
||
| 185 | public function getSpecialParameterList($app, $text) { |
||
| 221 | |||
| 222 | /** |
||
| 223 | * A string naming the css class for the icon to be used can be returned. |
||
| 224 | * If no icon is known for the given type false is to be returned. |
||
| 225 | * |
||
| 226 | * @param string $type |
||
| 227 | * @return string|false |
||
| 228 | */ |
||
| 229 | public function getTypeIcon($type) { |
||
| 241 | |||
| 242 | /** |
||
| 243 | * The extension can define the parameter grouping by returning the index as integer. |
||
| 244 | * In case no grouping is required false is to be returned. |
||
| 245 | * |
||
| 246 | * @param array $activity |
||
| 247 | * @return integer|false |
||
| 248 | */ |
||
| 249 | public function getGroupParameter($activity) { |
||
| 252 | |||
| 253 | /** |
||
| 254 | * The extension can define additional navigation entries. The array returned has to contain two keys 'top' |
||
| 255 | * and 'apps' which hold arrays with the relevant entries. |
||
| 256 | * If no further entries are to be added false is no be returned. |
||
| 257 | * |
||
| 258 | * @return array|false |
||
| 259 | */ |
||
| 260 | public function getNavigation() { |
||
| 273 | |||
| 274 | /** |
||
| 275 | * The extension can check if a customer filter (given by a query string like filter=abc) is valid or not. |
||
| 276 | * |
||
| 277 | * @param string $filterValue |
||
| 278 | * @return boolean |
||
| 279 | */ |
||
| 280 | public function isFilterValid($filterValue) { |
||
| 283 | |||
| 284 | /** |
||
| 285 | * For a given filter the extension can specify the sql query conditions including parameters for that query. |
||
| 286 | * In case the extension does not know the filter false is to be returned. |
||
| 287 | * The query condition and the parameters are to be returned as array with two elements. |
||
| 288 | * E.g. return array('`app` = ? and `message` like ?', array('mail', 'ownCloud%')); |
||
| 289 | * |
||
| 290 | * @param string $filter |
||
| 291 | * @return array|false |
||
| 292 | */ |
||
| 293 | public function getQueryForFilter($filter) { |
||
| 303 | } |