Complex classes like SMWPropertyValue 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 SMWPropertyValue, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
33 | class SMWPropertyValue extends SMWDataValue { |
||
|
|||
34 | |||
35 | /** |
||
36 | * Avoid the display of a tooltip |
||
37 | */ |
||
38 | const OPT_NO_HIGHLIGHT = 'no.highlight'; |
||
39 | |||
40 | /** |
||
41 | * Cache for wiki page value object associated to this property, or |
||
42 | * null if no such page exists. Use getWikiPageValue() to get the data. |
||
43 | * @var SMWWikiPageValue |
||
44 | */ |
||
45 | protected $m_wikipage = null; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $linkAttributes = array(); |
||
51 | |||
52 | /** |
||
53 | * Cache for type value of this property, or null if not calculated yet. |
||
54 | * @var SMWTypesValue |
||
55 | */ |
||
56 | private $mPropTypeValue; |
||
57 | |||
58 | /** |
||
59 | * @var DIProperty |
||
60 | */ |
||
61 | private $inceptiveProperty = null; |
||
62 | |||
63 | /** |
||
64 | * @since 2.4 |
||
65 | * |
||
66 | * @param string $typeid |
||
67 | */ |
||
68 | 218 | public function __construct( $typeid ) { |
|
71 | |||
72 | /** |
||
73 | * Static function for creating a new property object from a |
||
74 | * propertyname (string) as a user might enter it. |
||
75 | * @note The resulting property object might be invalid if |
||
76 | * the provided name is not allowed. An object is returned |
||
77 | * in any case. |
||
78 | * |
||
79 | * @param string $propertyName |
||
80 | * |
||
81 | * @return SMWPropertyValue |
||
82 | */ |
||
83 | 131 | static public function makeUserProperty( $propertyLabel ) { |
|
86 | |||
87 | /** |
||
88 | * Static function for creating a new property object from a property |
||
89 | * identifier (string) as it might be used internally. This might be |
||
90 | * the DB key version of some property title text or the id of a |
||
91 | * predefined property (such as '_TYPE'). |
||
92 | * @note This function strictly requires an internal identifier, i.e. |
||
93 | * predefined properties must be referred to by their ID, and '-' is |
||
94 | * not supported for indicating inverses. |
||
95 | * @note The resulting property object might be invalid if |
||
96 | * the provided name is not allowed. An object is returned |
||
97 | * in any case. |
||
98 | */ |
||
99 | static public function makeProperty( $propertyid ) { |
||
105 | |||
106 | /** |
||
107 | * We use the internal wikipage object to store some of this objects data. |
||
108 | * Clone it to make sure that data can be modified independently from the |
||
109 | * original object's content. |
||
110 | */ |
||
111 | 1 | public function __clone() { |
|
116 | |||
117 | /** |
||
118 | * @note If the inceptive property and the property referenced in dataItem |
||
119 | * are not equal then the dataItem represents the end target to which the |
||
120 | * inceptive property has been redirected. |
||
121 | * |
||
122 | * @since 2.4 |
||
123 | * |
||
124 | * @return DIProperty |
||
125 | */ |
||
126 | 1 | public function getInceptiveProperty() { |
|
129 | |||
130 | /** |
||
131 | * Extended parsing function to first check whether value refers to pre-defined |
||
132 | * property, resolve aliases, and set internal property id accordingly. |
||
133 | * @todo Accept/enforce property namespace. |
||
134 | */ |
||
135 | 199 | protected function parseUserValue( $value ) { |
|
171 | |||
172 | /** |
||
173 | * @see SMWDataValue::loadDataItem() |
||
174 | * @param $dataitem SMWDataItem |
||
175 | * @return boolean |
||
176 | */ |
||
177 | 32 | protected function loadDataItem( SMWDataItem $dataItem ) { |
|
193 | |||
194 | /** |
||
195 | * @since 2.4 |
||
196 | * |
||
197 | * @param array $linkAttributes |
||
198 | */ |
||
199 | 1 | public function setLinkAttributes( array $linkAttributes ) { |
|
206 | |||
207 | 105 | public function setCaption( $caption ) { |
|
213 | |||
214 | public function setOutputFormat( $formatstring ) { |
||
220 | |||
221 | public function setInverse( $isinverse ) { |
||
224 | |||
225 | /** |
||
226 | * Return a wiki page value that can be used for displaying this |
||
227 | * property, or null if no such wiki page exists (for predefined |
||
228 | * properties without any label). |
||
229 | * @return SMWWikiPageValue or null |
||
230 | */ |
||
231 | 109 | public function getWikiPageValue() { |
|
251 | |||
252 | /** |
||
253 | * Return TRUE if this is a property that can be displayed, and not a pre-defined |
||
254 | * property that is used only internally and does not even have a user-readable name. |
||
255 | * @note Every user defined property is necessarily visible. |
||
256 | */ |
||
257 | 94 | public function isVisible() { |
|
260 | |||
261 | /** |
||
262 | * @since 2.2 |
||
263 | * |
||
264 | * @return boolean |
||
265 | */ |
||
266 | 177 | public function canUse() { |
|
269 | |||
270 | 40 | public function getShortWikiText( $linked = null ) { |
|
279 | |||
280 | 8 | public function getShortHTMLText( $linked = null ) { |
|
289 | |||
290 | 12 | public function getLongWikiText( $linked = null ) { |
|
299 | |||
300 | public function getLongHTMLText( $linked = null ) { |
||
309 | |||
310 | 68 | public function getWikiValue() { |
|
322 | |||
323 | /** |
||
324 | * If this property was not user defined, return the internal ID string referring to |
||
325 | * that property. Otherwise return FALSE; |
||
326 | */ |
||
327 | public function getPropertyID() { |
||
330 | |||
331 | /** |
||
332 | * Return an SMWTypesValue object representing the datatype of this |
||
333 | * property. |
||
334 | * @deprecated Types values are not a good way to exchange SMW type information. They are for input only. Use getPropertyTypeID() if you want the type id. This method will vanish in SMW 1.7. |
||
335 | */ |
||
336 | public function getTypesValue() { |
||
343 | |||
344 | /** |
||
345 | * Convenience method to find the type id of this property. Most callers |
||
346 | * should rather use DIProperty::findPropertyTypeId() directly. Note |
||
347 | * that this is not the same as getTypeID(), which returns the id of |
||
348 | * this property datavalue. |
||
349 | * |
||
350 | * @return string |
||
351 | */ |
||
352 | 4 | public function getPropertyTypeID() { |
|
359 | |||
360 | /** |
||
361 | * Create special highlighting for hinting at special properties. |
||
362 | */ |
||
363 | 51 | protected function highlightText( $text, $linker = null ) { |
|
385 | |||
386 | /** |
||
387 | * A function for registering/overwriting predefined properties for SMW. Should be called from |
||
388 | * within the hook 'smwInitProperties'. Ids should start with three underscores "___" to avoid |
||
389 | * current and future confusion with SMW built-ins. |
||
390 | * |
||
391 | * @deprecated Use DIProperty::registerProperty(). Will vanish before SMW 1.7. |
||
392 | */ |
||
393 | static public function registerProperty( $id, $typeid, $label = false, $show = false ) { |
||
396 | |||
397 | /** |
||
398 | * Add a new alias label to an existing datatype id. Note that every ID should have a primary |
||
399 | * label, either provided by SMW or registered with registerDatatype. This function should be |
||
400 | * called from within the hook 'smwInitDatatypes'. |
||
401 | * |
||
402 | * @deprecated Use DIProperty::registerPropertyAlias(). Will vanish before SMW 1.7. |
||
403 | */ |
||
404 | static public function registerPropertyAlias( $id, $label ) { |
||
407 | |||
408 | /** |
||
409 | * @see DIProperty::isUserDefined() |
||
410 | * |
||
411 | * @deprecated since 1.6 |
||
412 | */ |
||
413 | public function isUserDefined() { |
||
416 | |||
417 | /** |
||
418 | * @see DIProperty::isShown() |
||
419 | * |
||
420 | * @deprecated since 1.6 |
||
421 | */ |
||
422 | public function isShown() { |
||
425 | |||
426 | /** |
||
427 | * @see DIProperty::isInverse() |
||
428 | * |
||
429 | * @deprecated since 1.6 |
||
430 | */ |
||
431 | public function isInverse() { |
||
434 | |||
435 | /** |
||
436 | * Return a DB-key-like string: for visible properties, it is the actual DB key, |
||
437 | * for internal (invisible) properties, it is the property ID. The value agrees |
||
438 | * with the first component of getDBkeys() and it can be used in its place. |
||
439 | * @see DIProperty::getKey() |
||
440 | * |
||
441 | * @deprecated since 1.6 |
||
442 | */ |
||
443 | public function getDBkey() { |
||
446 | |||
447 | /** |
||
448 | * @see DIProperty::getLabel() |
||
449 | * |
||
450 | * @deprecated since 1.6 |
||
451 | */ |
||
452 | public function getText() { |
||
455 | |||
456 | 199 | private function doNormalizeUserValue( $value ) { |
|
490 | |||
491 | } |
||
492 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.