| Conditions | 7 |
| Paths | 6 |
| Total Lines | 74 |
| Code Lines | 43 |
| 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 postProcessTca(array $tca) |
||
| 43 | { |
||
| 44 | $GLOBALS['TCA'] = $tca; |
||
| 45 | |||
| 46 | $additionalColumns = [ |
||
| 47 | 'tx_aoe_dbsquenzer_protectoverwrite_till' => [ |
||
| 48 | 'label' => 'LLL:EXT:aoe_dbsequenzer/Resources/Private/Language/locallang_db.xml:protectoverwrite_till', |
||
| 49 | 'config' => [ |
||
| 50 | 'type' => 'user', |
||
| 51 | 'userFunc' => 'Aoe\AoeDbSequenzer\Form\OverwriteTillElement->render', |
||
| 52 | 'eval' => 'datetime' |
||
| 53 | ] |
||
| 54 | ], |
||
| 55 | 'tx_aoe_dbsquenzer_protectoverwrite_mode' => [ |
||
| 56 | 'label' => 'LLL:EXT:aoe_dbsequenzer/Resources/Private/Language/locallang_db.xml:protected_mode', |
||
| 57 | 'config' => [ |
||
| 58 | 'type' => 'user', |
||
| 59 | 'userFunc' => 'Aoe\AoeDbSequenzer\Form\OverwriteModeElement->render', |
||
| 60 | ] |
||
| 61 | ] |
||
| 62 | ]; |
||
| 63 | |||
| 64 | $columnNames = []; |
||
| 65 | $columnNames[] = OverwriteProtectionService::OVERWRITE_PROTECTION_TILL; |
||
| 66 | $columnNames[] = OverwriteProtectionService::OVERWRITE_PROTECTION_MODE; |
||
| 67 | $columnNamesStr = ' ' . implode(', ', $columnNames); |
||
| 68 | |||
| 69 | $newFieldsString = '--palette--;LLL:EXT:aoe_dbsequenzer/Resources/Private/Language/locallang_db.xml:protectoverwrite_headline;tx_aoe_dbsequenzer'; |
||
| 70 | $newFieldsStringRegex = preg_quote($newFieldsString, '/'); |
||
| 71 | |||
| 72 | foreach ($this->getTcaTablesWithOverwriteProtectionSupport() as $table) { |
||
| 73 | // add columnsConfig at END of TCA-configuration |
||
| 74 | ExtensionManagementUtility::addTCAcolumns($table, $additionalColumns); |
||
| 75 | |||
| 76 | ExtensionManagementUtility::addFieldsToPalette( |
||
| 77 | $table, |
||
| 78 | 'tx_aoe_dbsequenzer', |
||
| 79 | $columnNamesStr |
||
| 80 | ); |
||
| 81 | |||
| 82 | ExtensionManagementUtility::addToAllTCAtypes( |
||
| 83 | $table, |
||
| 84 | $newFieldsString |
||
| 85 | ); |
||
| 86 | |||
| 87 | // move columnsConfig from END of TCA-configuration to BEGIN of TCA-configuration |
||
| 88 | if (is_array($GLOBALS['TCA'][$table]['types'])) { |
||
| 89 | foreach ($GLOBALS['TCA'][$table]['types'] as &$tableTypeConfig) { |
||
| 90 | if (array_key_exists('showitem', $tableTypeConfig) && |
||
| 91 | preg_match('/' . $newFieldsStringRegex . '$/i', $tableTypeConfig['showitem'])) { |
||
| 92 | |||
| 93 | $showItems = &$tableTypeConfig['showitem']; |
||
| 94 | |||
| 95 | // 1. delete columnsConfig at END of TCA-configuration |
||
| 96 | $showItems = preg_replace('/,\s?' . $newFieldsStringRegex . '/i', '', $showItems); |
||
| 97 | |||
| 98 | // 2. add columnsConfig at BEGIN of TCA-configuration |
||
| 99 | if (preg_match('/^--div--/i', $showItems)) { |
||
| 100 | // first entry is an tab |
||
| 101 | $firstColumnEntry = substr($showItems, 0, stripos($showItems, ',') + 1); |
||
| 102 | $showItems = str_replace($firstColumnEntry, '', $showItems); |
||
| 103 | $showItems = $firstColumnEntry . $newFieldsString . ',' . $showItems; |
||
| 104 | } else { |
||
| 105 | // first entry is no tab |
||
| 106 | $showItems = $newFieldsString . ',' . $showItems; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | $tca = $GLOBALS['TCA']; |
||
| 114 | return [$tca]; |
||
| 115 | } |
||
| 116 | |||
| 129 |