| Total Complexity | 51 |
| Total Lines | 358 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like RedcoreModelTranslation 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.
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 RedcoreModelTranslation, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class RedcoreModelTranslation extends RModelAdmin |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Method to get a single record. |
||
| 23 | * |
||
| 24 | * @param integer $pk The id of the primary key. |
||
| 25 | * |
||
| 26 | * @return mixed Object on success, false on failure. |
||
| 27 | */ |
||
| 28 | public function getItem($pk = null) |
||
| 29 | { |
||
| 30 | $app = JFactory::getApplication(); |
||
| 31 | $ids = $app->input->getString('id', ''); |
||
| 32 | $id = $app->input->getString('rctranslations_id', ''); |
||
| 33 | $table = RTranslationTable::setTranslationTableWithColumn($app->input->get('translationTableName', '')); |
||
| 34 | |||
| 35 | if (empty($table)) |
||
| 36 | { |
||
| 37 | // Translation table does not exist we are redirecting to manager |
||
| 38 | $app->redirect('index.php?option=com_redcore&view=translations'); |
||
| 39 | } |
||
| 40 | |||
| 41 | $db = $this->getDbo(); |
||
| 42 | $query = $db->getQuery(true); |
||
| 43 | $item = new stdClass; |
||
| 44 | |||
| 45 | $ids = explode('###', $ids); |
||
| 46 | |||
| 47 | $query->select('*') |
||
| 48 | ->from($db->qn($table->table)); |
||
| 49 | |||
| 50 | foreach ($table->primaryKeys as $key => $primaryKey) |
||
| 51 | { |
||
| 52 | $query->where($db->qn($primaryKey) . ' = ' . $db->q($ids[$key])); |
||
| 53 | } |
||
| 54 | |||
| 55 | $db->setQuery($query); |
||
| 56 | $item->original = $db->loadObject(); |
||
| 57 | |||
| 58 | $query = $db->getQuery(true) |
||
| 59 | ->select('*') |
||
| 60 | ->from($db->qn(RTranslationTable::getTranslationsTableName($table->table, ''))) |
||
| 61 | ->where('rctranslations_id = ' . $db->q($id)); |
||
| 62 | |||
| 63 | $db->setQuery($query); |
||
| 64 | $item->translation = $db->loadObject(); |
||
| 65 | |||
| 66 | if (empty($item->translation)) |
||
| 67 | { |
||
| 68 | $item->translation = new stdClass; |
||
| 69 | |||
| 70 | foreach ($table->columns as $column) |
||
| 71 | { |
||
| 72 | $item->translation->{$column} = null; |
||
| 73 | } |
||
| 74 | |||
| 75 | foreach ($table->primaryKeys as $primaryKey) |
||
| 76 | { |
||
| 77 | if (!empty($item->original->{$primaryKey})) |
||
| 78 | { |
||
| 79 | $item->translation->{$primaryKey} = $item->original->{$primaryKey}; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | $item->rctranslations_state = 1; |
||
| 84 | $item->rctranslations_modified = ''; |
||
| 85 | $item->rctranslations_modified_by = ''; |
||
| 86 | $item->rctranslations_language = JFactory::getApplication()->input->getString('language', ''); |
||
| 87 | $item->id = 0; |
||
| 88 | } |
||
| 89 | else |
||
| 90 | { |
||
| 91 | if (!empty($item->translation->rctranslations_originals)) |
||
| 92 | { |
||
| 93 | $registry = new JRegistry; |
||
|
|
|||
| 94 | $registry->loadString($item->translation->rctranslations_originals); |
||
| 95 | $item->translation->rctranslations_originals = $registry->toArray(); |
||
| 96 | } |
||
| 97 | |||
| 98 | $item->original->rctranslations_state = $item->rctranslations_state = $item->translation->rctranslations_state; |
||
| 99 | $item->original->rctranslations_modified = $item->rctranslations_modified = $item->translation->rctranslations_modified; |
||
| 100 | $item->original->rctranslations_modified_by = $item->rctranslations_modified_by = $item->translation->rctranslations_modified_by; |
||
| 101 | $item->original->rctranslations_language = $item->rctranslations_language = $item->translation->rctranslations_language; |
||
| 102 | $item->original->rctranslations_originals = $item->rctranslations_originals = $item->translation->rctranslations_originals; |
||
| 103 | $item->id = $item->translation->rctranslations_id; |
||
| 104 | } |
||
| 105 | |||
| 106 | foreach ($table->allColumns as $column) |
||
| 107 | { |
||
| 108 | if ($column['column_type'] != RTranslationTable::COLUMN_TRANSLATE) |
||
| 109 | { |
||
| 110 | $item->translation->{$column['name']} = $item->original->{$column['name']}; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($column['value_type'] == 'params' |
||
| 114 | && (empty($item->translation->{$column['name']}) || $item->translation->{$column['name']} == '{}')) |
||
| 115 | { |
||
| 116 | $item->translation->{$column['name']} = $item->original->{$column['name']}; |
||
| 117 | } |
||
| 118 | |||
| 119 | if ($column['value_type'] == 'readonlytext' |
||
| 120 | && (empty($item->translation->{$column['name']}) || $item->translation->{$column['name']} == '{}')) |
||
| 121 | { |
||
| 122 | $item->translation->{$column['name']} = $item->original->{$column['name']}; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | return $item; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Method to save the form data. |
||
| 131 | * |
||
| 132 | * @param array $data The form data. |
||
| 133 | * |
||
| 134 | * @return boolean True on success. |
||
| 135 | */ |
||
| 136 | public function save($data) |
||
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Method to get a form object. |
||
| 351 | * |
||
| 352 | * @param array $data Data for the form. |
||
| 353 | * @param boolean $loadData True if the form is to load its own data (default case), false if not. |
||
| 354 | * |
||
| 355 | * @return mixed A JForm object on success, false on failure |
||
| 356 | */ |
||
| 357 | public function getForm($data = array(), $loadData = true) |
||
| 379 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths