Complex classes like MonolingualTextValue 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 MonolingualTextValue, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
35 | class MonolingualTextValue extends DataValue { |
||
36 | |||
37 | /** |
||
38 | * @var DIProperty[]|null |
||
39 | */ |
||
40 | private static $properties = null; |
||
41 | |||
42 | /** |
||
43 | * @var MonolingualTextValueParser |
||
44 | */ |
||
45 | private $monolingualTextValueParser = null; |
||
46 | |||
47 | /** |
||
48 | * @param string $typeid |
||
49 | 12 | */ |
|
50 | 12 | public function __construct( $typeid = '' ) { |
|
54 | |||
55 | /** |
||
56 | * @see RecordValue::setFieldProperties |
||
57 | * |
||
58 | * @param SMWDIProperty[] $properties |
||
59 | */ |
||
60 | public function setFieldProperties( array $properties ) { |
||
64 | |||
65 | /** |
||
66 | * @since 2.4 |
||
67 | * |
||
68 | * @return integer |
||
69 | 2 | */ |
|
70 | 2 | public function needsLanguageCode() { |
|
73 | |||
74 | /** |
||
75 | * @see DataValue::parseUserValue |
||
76 | * @note called by DataValue::setUserValue |
||
77 | * |
||
78 | * @param string $value |
||
79 | 10 | */ |
|
80 | protected function parseUserValue( $userValue ) { |
||
123 | |||
124 | /** |
||
125 | * @note called by MonolingualTextValueDescriptionDeserializer::deserialize |
||
126 | * and MonolingualTextValue::parseUserValue |
||
127 | * |
||
128 | * No explicit check is made on the validity of a language code and is |
||
129 | * expected to be done before calling this method. |
||
130 | * |
||
131 | * @since 2.4 |
||
132 | * |
||
133 | * @param string $userValue |
||
134 | * |
||
135 | * @return array |
||
136 | 10 | */ |
|
137 | 10 | public function getValuesFromString( $userValue ) { |
|
140 | |||
141 | /** |
||
142 | * @see DataValue::loadDataItem |
||
143 | * |
||
144 | * @param DataItem $dataItem |
||
145 | * |
||
146 | * @return boolean |
||
147 | 3 | */ |
|
148 | protected function loadDataItem( DataItem $dataItem ) { |
||
162 | |||
163 | /** |
||
164 | * @see DataValue::getShortWikiText |
||
165 | 3 | */ |
|
166 | public function getShortWikiText( $linker = null ) { |
||
169 | |||
170 | /** |
||
171 | 3 | * @see DataValue::getShortHTMLText |
|
172 | */ |
||
173 | public function getShortHTMLText( $linker = null ) { |
||
176 | |||
177 | /** |
||
178 | * @see DataValue::getLongWikiText |
||
179 | */ |
||
180 | public function getLongWikiText( $linker = null ) { |
||
183 | |||
184 | /** |
||
185 | * @see DataValue::getLongHTMLText |
||
186 | */ |
||
187 | public function getLongHTMLText( $linker = null ) { |
||
190 | |||
191 | /** |
||
192 | * @see DataValue::getWikiValue |
||
193 | */ |
||
194 | public function getWikiValue() { |
||
197 | |||
198 | /** |
||
199 | * @since 2.4 |
||
200 | * @note called by SMWResultArray::getNextDataValue |
||
201 | * |
||
202 | * @return DIProperty[] |
||
203 | 4 | */ |
|
204 | 4 | public static function getPropertyDataItems() { |
|
216 | 7 | ||
217 | /** |
||
218 | * @since 2.4 |
||
219 | 1 | * @note called by SMWResultArray::loadContent |
|
220 | 1 | * |
|
221 | 1 | * @return DataItem[] |
|
222 | */ |
||
223 | 1 | public function getDataItems() { |
|
244 | 2 | ||
245 | 2 | /** |
|
246 | * @since 2.4 |
||
247 | * |
||
248 | 2 | * @return DataValue|null |
|
249 | 2 | */ |
|
250 | public function getTextValueByLanguage( $languageCode ) { |
||
279 | |||
280 | private function newContainerSemanticData( $value ) { |
||
300 | 1 | ||
301 | private function newLanguageCodeValue( $languageCode ) { |
||
313 | |||
314 | } |
||
315 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..