Conditions | 11 |
Paths | 17 |
Total Lines | 47 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
42 | public function aoewspreview_createDiff(array $params) { |
||
43 | $element = $params['element']; |
||
44 | |||
45 | if (($params['fieldName'] == 'tx_languagevisibility_visibility')) { |
||
46 | $diff = array(); |
||
47 | |||
48 | $recordNew = unserialize($params['newRecord'][$params['fieldName']]); |
||
49 | $recordOld = unserialize($params['oldRecord'][$params['fieldName']]); |
||
50 | |||
51 | $recordNew = is_array($recordNew) ? $recordNew : array(); |
||
52 | $recordOld = is_array($recordOld) ? $recordOld : array(); |
||
53 | |||
54 | $equalInBoth = array_intersect_assoc($recordNew, $recordOld); |
||
55 | $changedKeyOld = array_keys(array_diff_assoc($recordOld, $equalInBoth)); |
||
56 | $changedKeyNew = array_keys(array_diff_assoc($recordNew, $equalInBoth)); |
||
57 | $keyOfChangedLanguageSettings = array_unique(array_merge($changedKeyNew, $changedKeyOld)); |
||
58 | |||
59 | if (is_array($keyOfChangedLanguageSettings) && (count($keyOfChangedLanguageSettings) > 0)) { |
||
60 | foreach ( $keyOfChangedLanguageSettings as $key ) { |
||
61 | if (empty($recordOld[$key]) && ($recordNew[$key] == '-')) { |
||
62 | // this is equal, too! |
||
63 | // we need to inform the user what happens because he doesn't understand |
||
64 | // what happend if the field tx_languagevisibility_visibility was configured as critical field |
||
65 | // and if was just initialized with default values. |
||
66 | $diff[] = sprintf('%s Visibility was initialized with the default value (%s)', tx_mvc_common_typo3::getLanguageFlag($key, $params['newRecord']['pid']), $recordNew[$key]); |
||
67 | } elseif (empty($recordNew[$key])) { |
||
68 | // in this case an old visibility setting has been changed to an empty value, |
||
69 | // this can happen when a new workspace version is created |
||
70 | $diff[0] = 'Languagevisibility was changed from ' . serialize($recordOld) . ' to ' . serialize($recordNew); |
||
71 | } else { |
||
72 | $diff[] = sprintf('%s Visibility changed from <span class="diff-r">%s</span> to <span class="diff-g">%s</span>', tx_mvc_common_typo3::getLanguageFlag($key, $params['newRecord']['pid']), $GLOBALS['LANG']->sL('LLL:EXT:languagevisibility/locallang_db.xml:tx_languagevisibility_visibility.I.' . $recordOld[$key]), $GLOBALS['LANG']->sL('LLL:EXT:languagevisibility/locallang_db.xml:tx_languagevisibility_visibility.I.' . $recordNew[$key])); |
||
73 | } |
||
74 | } |
||
75 | } else { |
||
76 | // in this case the structure of the languagevisibility was changed but no visibility setting |
||
77 | } |
||
78 | |||
79 | if (count($diff) > 0) { |
||
80 | $element['diffResult'] = implode('<br />', $diff); |
||
81 | } else { |
||
82 | // element will be removed when returning "false" |
||
83 | $element = FALSE; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | return $element; |
||
88 | } |
||
89 | } |
||
90 |