| Conditions | 12 |
| Paths | 128 |
| Total Lines | 39 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 51 | public function setDataFromRequest(App\Request $request) |
||
| 52 | { |
||
| 53 | if ($request->has('xmlExportType')) { |
||
| 54 | $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text')); |
||
|
|
|||
| 55 | } |
||
| 56 | $queryGenerator = $this->exportModel->getQueryGenerator(); |
||
| 57 | |||
| 58 | $cvId = $request->getInteger('viewname'); |
||
| 59 | $queryGenerator->initForCustomViewById($cvId); |
||
| 60 | |||
| 61 | $selectedIds = $request->getArray('selected_ids', \App\Purifier::ALNUM); |
||
| 62 | if ($selectedIds && 'all' !== $selectedIds[0]) { |
||
| 63 | $queryGenerator->addCondition('id', $selectedIds, 'e'); |
||
| 64 | } |
||
| 65 | $searchParams = \App\Condition::validSearchParams($this->moduelName, $request->getArray('search_params')); |
||
| 66 | if ($searchParams) { |
||
| 67 | $transformedSearchParams = $queryGenerator->parseBaseSearchParamsToCondition($searchParams); |
||
| 68 | $queryGenerator->parseAdvFilter($transformedSearchParams); |
||
| 69 | } |
||
| 70 | |||
| 71 | $operator = $request->isEmpty('operator') ? '' : $request->getByType('operator'); |
||
| 72 | if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduelName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) { |
||
| 73 | $queryGenerator->addCondition($request->getByType('search_key', \App\Purifier::ALNUM), $searchValue, $operator); |
||
| 74 | } |
||
| 75 | $queryGenerator->setStateCondition($request->getByType('entityState')); |
||
| 76 | |||
| 77 | if ($excludedIds = $request->getArray('excluded_ids', \App\Purifier::INTEGER)) { |
||
| 78 | $queryGenerator->addCondition('id', $excludedIds, 'n'); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (!$request->isEmpty('exportColumns', true) && $fields = $request->getArray('exportColumns', \App\Purifier::TEXT)) { |
||
| 82 | $this->exportModel->setFields($fields); |
||
| 83 | } else { |
||
| 84 | $fields = \App\CustomView::getInstance($this->moduelName)->getColumnsListByCvid($cvId); |
||
| 85 | array_walk($fields, function (&$fieldInfo) { |
||
| 86 | ['field_name' => $relatedFieldName, 'module_name' => $relatedModule, 'source_field_name' => $referenceField] = $fieldInfo; |
||
| 87 | $fieldInfo = $referenceField ? "{$relatedFieldName}:{$relatedModule}:{$referenceField}" : $relatedFieldName; |
||
| 88 | }); |
||
| 89 | $this->exportModel->setFields($fields); |
||
| 90 | } |
||
| 93 |