Complex classes like ChangeNotificationFilter 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 ChangeNotificationFilter, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class ChangeNotificationFilter { |
||
| 22 | |||
| 23 | const VALUE_CHANGE = 'smw-value-change'; |
||
| 24 | const SPECIFICATION_CHANGE = 'smw-specification-change'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var DIWikiPage |
||
| 28 | */ |
||
| 29 | private $subject; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var Store |
||
| 33 | */ |
||
| 34 | private $store; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var DataValueFactory |
||
| 38 | */ |
||
| 39 | private $dataValueFactory; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var array |
||
| 43 | */ |
||
| 44 | private $detectedProperties = array(); |
||
| 45 | |||
| 46 | /** |
||
| 47 | * In case detection matrix was stored as subobject on a property then match |
||
| 48 | * its pairs of property => subobjectKey so that later the Locator can find |
||
| 49 | * out which subobject contains the group that needs to be notified. |
||
| 50 | * |
||
| 51 | * @var array |
||
| 52 | */ |
||
| 53 | private $subSemanticDataMatch = array(); |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var string|null |
||
| 57 | */ |
||
| 58 | private $type = null; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var User|null |
||
| 62 | */ |
||
| 63 | private $agent = null; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var boolean |
||
| 67 | */ |
||
| 68 | private $canNotify = false; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var array |
||
| 72 | */ |
||
| 73 | private $propertyExemptionList = array(); |
||
| 74 | |||
| 75 | /** |
||
| 76 | 8 | * @var boolean |
|
| 77 | 8 | */ |
|
| 78 | 8 | private $isCommandLineMode = false; |
|
| 79 | 8 | ||
| 80 | 8 | /** |
|
| 81 | * @since 1.0 |
||
| 82 | * |
||
| 83 | * @param DIWikiPage $subject |
||
| 84 | * @param Store $store |
||
| 85 | */ |
||
| 86 | public function __construct( DIWikiPage $subject, Store $store ) { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @since 1.0 |
||
| 94 | * |
||
| 95 | * @param User $agent |
||
| 96 | */ |
||
| 97 | public function setAgent( User $agent ) { |
||
| 100 | 2 | ||
| 101 | /** |
||
| 102 | 2 | * @since 1.0 |
|
| 103 | 1 | * |
|
| 104 | 1 | * @param array $propertyExemptionList |
|
| 105 | */ |
||
| 106 | public function setPropertyExemptionList( array $propertyExemptionList ) { |
||
| 111 | 1 | ||
| 112 | 1 | /** |
|
| 113 | 1 | * @since 1.0 |
|
| 114 | 1 | * |
|
| 115 | 1 | * @param boolean $isCommandLineMode |
|
| 116 | 1 | */ |
|
| 117 | 1 | public function isCommandLineMode( $isCommandLineMode ) { |
|
| 120 | |||
| 121 | /** |
||
| 122 | * @since 1.0 |
||
| 123 | * |
||
| 124 | * @param CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator |
||
| 125 | * |
||
| 126 | * @return array |
||
| 127 | */ |
||
| 128 | 6 | public function findChangeEvent( CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator ) { |
|
| 137 | |||
| 138 | 6 | /** |
|
| 139 | 5 | * @see EchoEvent::create |
|
| 140 | 6 | * |
|
| 141 | 1 | * @since 1.0 |
|
| 142 | 1 | * |
|
| 143 | * @param boolean|null $hasChangeToNotifyAbout |
||
| 144 | 6 | * |
|
| 145 | * @return array |
||
| 146 | */ |
||
| 147 | public function getEventRecord( $hasChangeToNotifyAbout = false ) { |
||
| 167 | |||
| 168 | 6 | /** |
|
| 169 | * @since 1.0 |
||
| 170 | * |
||
| 171 | * @param CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator |
||
| 172 | 6 | * |
|
| 173 | 6 | * @return boolean|null |
|
| 174 | */ |
||
| 175 | public function hasChangeToNotifyAbout( CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator ) { |
||
| 214 | |||
| 215 | 4 | // 2.4 compat |
|
| 216 | private function getFixedPropertyValueBy( $tableChangeOp, $key ) { |
||
| 219 | |||
| 220 | // 2.4 compat |
||
| 221 | private function getDataItemById( $id ) { |
||
| 222 | return method_exists( $this->store->getObjectIds(), 'getDataItemForId' ) ? $this->store->getObjectIds()->getDataItemForId( $id ) : $this->store->getObjectIds()->getDataItemById( $id ); |
||
| 223 | } |
||
| 224 | |||
| 225 | private function doFilterOnFieldChangeOps( $property, $tableChangeOp, $fieldChangeOps ) { |
||
| 263 | 4 | ||
| 264 | 1 | private function doCompareNotificationsOnValuesWithOps( $property, $dataItem, $fieldChangeOp ) { |
|
| 300 | |||
| 301 | private function doCompareOnPropertyValues( $dataItem, $propertyValues, $fieldChangeOp, $subobjectName = null ) { |
||
| 306 | 2 | ||
| 307 | 2 | private function doCompareFields( $value, $fieldChangeOp, $dataItem, $subobjectName ) { |
|
| 360 | |||
| 361 | } |
||
| 362 |
If an expression can have both
false, andnullas possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.