| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 211 |
| Code Lines | 95 |
| 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 |
||
| 136 | public function save($data) |
||
| 137 | { |
||
| 138 | $app = JFactory::getApplication(); |
||
| 139 | $dataArr = $app->input->get('jform', array(), 'array'); |
||
| 140 | $translationTable = RTranslationTable::setTranslationTableWithColumn($app->input->get('translationTableName', '')); |
||
| 141 | $translation = $app->input->get('translation', array(), 'array'); |
||
| 142 | |||
| 143 | if ($original = $this->getItem()) |
||
| 144 | { |
||
| 145 | $original = (array) $original->original; |
||
| 146 | } |
||
| 147 | else |
||
| 148 | { |
||
| 149 | $original = $app->input->get('original', array(), 'array'); |
||
| 150 | } |
||
| 151 | |||
| 152 | foreach ($translation as $translationKey => $translationData) |
||
| 153 | { |
||
| 154 | $allLanguages = RTranslationHelper::getAllContentLanguageCodes(); |
||
| 155 | |||
| 156 | if (!in_array($translationKey, $allLanguages) && $translationKey != 'no-language') |
||
| 157 | { |
||
| 158 | continue; |
||
| 159 | } |
||
| 160 | |||
| 161 | $data = array_merge($dataArr[$translationKey], $translationData); |
||
| 162 | |||
| 163 | $id = !empty($data['rctranslations_id']) ? (int) $data['rctranslations_id'] : 0; |
||
| 164 | |||
| 165 | if ($translationKey == 'no-language') |
||
| 166 | { |
||
| 167 | $data['rctranslations_language'] = $dataArr[$translationKey]['rctranslations_language']; |
||
| 168 | } |
||
| 169 | else |
||
| 170 | { |
||
| 171 | $data['rctranslations_language'] = $translationKey; |
||
| 172 | } |
||
| 173 | |||
| 174 | /** @var RedcoreTableTranslation $table */ |
||
| 175 | $table = $this->getTable(); |
||
| 176 | |||
| 177 | if (empty($id)) |
||
| 178 | { |
||
| 179 | $db = $this->getDbo(); |
||
| 180 | $query = $db->getQuery(true) |
||
| 181 | ->select('rctranslations_id') |
||
| 182 | ->from($db->qn(RTranslationTable::getTranslationsTableName($translationTable->table, ''))) |
||
| 183 | ->where('rctranslations_language = ' . $db->q($data['rctranslations_language'])); |
||
| 184 | |||
| 185 | foreach ($translationTable->primaryKeys as $primaryKey) |
||
| 186 | { |
||
| 187 | if (!empty($data[$primaryKey])) |
||
| 188 | { |
||
| 189 | $query->where($db->qn($primaryKey) . ' = ' . $db->q($data[$primaryKey])); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | $db->setQuery($query); |
||
| 194 | $id = $db->loadResult(); |
||
| 195 | } |
||
| 196 | |||
| 197 | // Check if the form is completely empty, and return an error if it is. |
||
| 198 | $dataFilled = RTranslationHelper::validateEmptyTranslationData($translationData, $translationTable->primaryKeys); |
||
| 199 | |||
| 200 | if (!$dataFilled) |
||
| 201 | { |
||
| 202 | $this->setError(JText::_('COM_REDCORE_TRANSLATIONS_SAVE_ERROR_EMPTY')); |
||
| 203 | |||
| 204 | if (!empty($id)) |
||
| 205 | { |
||
| 206 | $table->delete($id); |
||
| 207 | } |
||
| 208 | |||
| 209 | continue; |
||
| 210 | } |
||
| 211 | |||
| 212 | foreach ($translationTable->allColumns as $field) |
||
| 213 | { |
||
| 214 | if ($field['value_type'] == 'params' && $field['column_type'] == RTranslationTable::COLUMN_TRANSLATE) |
||
| 215 | { |
||
| 216 | $fieldName = $field['name']; |
||
| 217 | $paramsChanged = false; |
||
| 218 | |||
| 219 | if (!empty($data[$fieldName])) |
||
| 220 | { |
||
| 221 | $registry = new JRegistry; |
||
| 222 | $registry->loadString($original[$fieldName]); |
||
| 223 | $originalParams = $registry->toArray(); |
||
| 224 | |||
| 225 | foreach ($data[$fieldName] as $paramKey => $paramValue) |
||
| 226 | { |
||
| 227 | if ((!isset($originalParams[$paramKey]) && $paramValue != '') || $originalParams[$paramKey] != $paramValue) |
||
| 228 | { |
||
| 229 | $paramsChanged = true; |
||
| 230 | |||
| 231 | break; |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | if ($paramsChanged) |
||
| 236 | { |
||
| 237 | $data[$fieldName] = json_encode($data[$fieldName]); |
||
| 238 | } |
||
| 239 | else |
||
| 240 | { |
||
| 241 | $data[$fieldName] = ''; |
||
| 242 | } |
||
| 243 | } |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | $dispatcher = RFactory::getDispatcher(); |
||
| 248 | |||
| 249 | foreach ($translationTable->primaryKeys as $primaryKey) |
||
| 250 | { |
||
| 251 | $original[$primaryKey] = $data[$primaryKey]; |
||
| 252 | } |
||
| 253 | |||
| 254 | $isNew = true; |
||
| 255 | |||
| 256 | // Load the row if saving an existing item. |
||
| 257 | $table->load((int) $id); |
||
| 258 | |||
| 259 | if ($table->rctranslations_modified) |
||
| 260 | { |
||
| 261 | $isNew = false; |
||
| 262 | } |
||
| 263 | |||
| 264 | $data['rctranslations_originals'] = RTranslationTable::createOriginalValueFromColumns($original, $translationTable->columns); |
||
| 265 | |||
| 266 | // We run posthandler methods |
||
| 267 | foreach ($translationTable->allColumns as $field) |
||
| 268 | { |
||
| 269 | $postHandler = $field['posthandler']; |
||
| 270 | $fieldName = $field['name']; |
||
| 271 | |||
| 272 | if (!empty($postHandler) && $field['translate'] == '1') |
||
| 273 | { |
||
| 274 | $postHandlerFunctions = explode(',', $postHandler); |
||
| 275 | |||
| 276 | foreach ($postHandlerFunctions as $postHandlerFunction) |
||
| 277 | { |
||
| 278 | $postHandlerFunctionArray = explode('::', $postHandlerFunction); |
||
| 279 | |||
| 280 | if (empty($postHandlerFunctionArray[1])) |
||
| 281 | { |
||
| 282 | $postHandlerFunctionArray[1] = $postHandlerFunctionArray[0]; |
||
| 283 | $postHandlerFunctionArray[0] = 'RTranslationContentHelper'; |
||
| 284 | $postHandlerFunction = 'RTranslationContentHelper::' . $postHandlerFunction; |
||
| 285 | } |
||
| 286 | |||
| 287 | if (method_exists($postHandlerFunctionArray[0], $postHandlerFunctionArray[1])) |
||
| 288 | { |
||
| 289 | call_user_func_array( |
||
| 290 | array( |
||
| 291 | $postHandlerFunctionArray[0], |
||
| 292 | $postHandlerFunctionArray[1]), |
||
| 293 | array($field, &$data[$fieldName], &$data, $translationTable) |
||
| 294 | ); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | } |
||
| 298 | } |
||
| 299 | |||
| 300 | // Bind the data. |
||
| 301 | if (!$table->bind($data)) |
||
| 302 | { |
||
| 303 | $this->setError($table->getError()); |
||
| 304 | |||
| 305 | return false; |
||
| 306 | } |
||
| 307 | |||
| 308 | // Prepare the row for saving |
||
| 309 | $this->prepareTable($table); |
||
| 310 | |||
| 311 | // Check the data. |
||
| 312 | if (!$table->check()) |
||
| 313 | { |
||
| 314 | $this->setError($table->getError()); |
||
| 315 | |||
| 316 | return false; |
||
| 317 | } |
||
| 318 | |||
| 319 | // Trigger the onContentBeforeSave event. |
||
| 320 | $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew)); |
||
| 321 | |||
| 322 | if (in_array(false, $result, true)) |
||
| 323 | { |
||
| 324 | $this->setError($table->getError()); |
||
| 325 | |||
| 326 | return false; |
||
| 327 | } |
||
| 328 | |||
| 329 | // Store the data. |
||
| 330 | if (!$table->store()) |
||
| 331 | { |
||
| 332 | $this->setError($table->getError()); |
||
| 333 | |||
| 334 | return false; |
||
| 335 | } |
||
| 336 | |||
| 337 | // Trigger the onContentAfterSave event. |
||
| 338 | $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew)); |
||
| 339 | |||
| 340 | $this->setState($this->getName() . '.id', $table->rctranslations_id); |
||
| 341 | |||
| 342 | // Clear the cache |
||
| 343 | $this->cleanCache(); |
||
| 344 | } |
||
| 345 | |||
| 346 | return true; |
||
| 347 | } |
||
| 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