| Conditions | 28 |
| Paths | 816 |
| Total Lines | 156 |
| Code Lines | 108 |
| Lines | 18 |
| Ratio | 11.54 % |
| 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 |
||
| 35 | public function view() { |
||
| 36 | View Code Duplication | if (class_exists('FLang')) { |
|
| 37 | try { |
||
| 38 | FLang::setMainLang(Lang::get()); |
||
| 39 | FLang::setLangCode(Lang::get(), ''); |
||
| 40 | } catch (Exception $ex) {} |
||
|
|
|||
| 41 | } |
||
| 42 | // _context[0] => entry values |
||
| 43 | // _context[1] => fieldId |
||
| 44 | if (!is_array($this->_context) || empty($this->_context) || $this->_context[0] === 'null') { |
||
| 45 | $this->_Result->appendChild(new XMLElement('error', __('Parameters not found'))); |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | else if (count($this->_context) < self::NUMBER_OF_URL_PARAMETERS) { |
||
| 49 | $this->_Result->appendChild(new XMLElement('error', __('Not enough parameters'))); |
||
| 50 | return; |
||
| 51 | } |
||
| 52 | else if (count($this->_context) > self::NUMBER_OF_URL_PARAMETERS) { |
||
| 53 | $this->_Result->appendChild(new XMLElement('error', __('Too many parameters'))); |
||
| 54 | return; |
||
| 55 | } |
||
| 56 | |||
| 57 | $entriesId = explode(',', MySQL::cleanValue($this->_context[0])); |
||
| 58 | $entriesId = array_map(array('General', 'intval'), $entriesId); |
||
| 59 | View Code Duplication | if (!is_array($entriesId) || empty($entriesId)) { |
|
| 60 | $this->_Result->appendChild(new XMLElement('error', __('No entry no found'))); |
||
| 61 | return; |
||
| 62 | } |
||
| 63 | |||
| 64 | $parentFieldId = General::intval($this->_context[1]); |
||
| 65 | if ($parentFieldId < 1) { |
||
| 66 | $this->_Result->appendChild(new XMLElement('error', __('Parent field id not valid'))); |
||
| 67 | return; |
||
| 68 | } |
||
| 69 | |||
| 70 | $parentField = $this->fieldManager->fetch($parentFieldId); |
||
| 71 | View Code Duplication | if (!$parentField || empty($parentField)) { |
|
| 72 | $this->_Result->appendChild(new XMLElement('error', __('Parent field not found'))); |
||
| 73 | return; |
||
| 74 | } |
||
| 75 | |||
| 76 | View Code Duplication | if (!($parentField instanceof FieldRelationship)) { |
|
| 77 | $this->_Result->appendChild(new XMLElement('error', __('Parent field is `%s`, not `relationship field`', array($parentField->get('type'))))); |
||
| 78 | return; |
||
| 79 | } |
||
| 80 | |||
| 81 | // Get entries one by one since they may belong to |
||
| 82 | // different sections, which prevents us from |
||
| 83 | // passing an array of entryId. |
||
| 84 | foreach ($entriesId as $key => $entryId) { |
||
| 85 | $entry = $this->entryManager->fetch($entryId); |
||
| 86 | if (empty($entry)) { |
||
| 87 | $li = new XMLElement('li', null, array( |
||
| 88 | 'data-entry-id' => $entryId |
||
| 89 | )); |
||
| 90 | $header = new XMLElement('header', null, array('class' => 'frame-header no-content ignore-collapsible')); |
||
| 91 | $title = new XMLElement('h4'); |
||
| 92 | $title->appendChild(new XMLElement('strong', __('Entry %s not found', array($entryId)))); |
||
| 93 | $header->appendChild($title); |
||
| 94 | $options = new XMLElement('div', null, array('class' => 'destructor')); |
||
| 95 | $options->appendChild(new XMLElement('a', __('Un-link'), array( |
||
| 96 | 'class' => 'unlink ignore-collapsible', |
||
| 97 | 'data-unlink' => $entryId, |
||
| 98 | ))); |
||
| 99 | $header->appendChild($options); |
||
| 100 | $li->appendChild($header); |
||
| 101 | $this->_Result->appendChild($li); |
||
| 102 | } else { |
||
| 103 | $entry = $entry[0]; |
||
| 104 | $entrySection = $this->sectionManager->fetch($entry->get('section_id')); |
||
| 105 | $entryVisibleFields = $entrySection->fetchVisibleColumns(); |
||
| 106 | $entryFields = $entrySection->fetchFields(); |
||
| 107 | $entrySectionHandle = $this->getSectionName($entry, 'handle'); |
||
| 108 | |||
| 109 | $li = new XMLElement('li', null, array( |
||
| 110 | 'data-entry-id' => $entryId, |
||
| 111 | 'data-section' => $entrySectionHandle, |
||
| 112 | 'data-section-id' => $entrySection->get('id'), |
||
| 113 | 'data-timestamp' => $entry->get('modification_date'), |
||
| 114 | )); |
||
| 115 | if ($parentField->is('show_header')) { |
||
| 116 | $header = new XMLElement('header', null, array( |
||
| 117 | 'class' => 'frame-header', |
||
| 118 | 'data-orderable-handle' => '', |
||
| 119 | 'data-collapsible-handle' => '' |
||
| 120 | )); |
||
| 121 | $title = new XMLElement('h4', null, array('class' => 'ignore-collapsible')); |
||
| 122 | if (!$parentField->get('mode_header')) { |
||
| 123 | $title->appendChildArray($this->buildDefaultTitle($entry, $entryVisibleFields, $entryFields)); |
||
| 124 | } |
||
| 125 | else { |
||
| 126 | $title->setValue(ERFXSLTUTilities::processXSLT($parentField, $entry, $entrySectionHandle, $entryFields, 'mode_header')); |
||
| 127 | } |
||
| 128 | $header->appendChild($title); |
||
| 129 | |||
| 130 | $options = new XMLElement('div', null, array('class' => 'destructor')); |
||
| 131 | if ($parentField->is('allow_edit')) { |
||
| 132 | $title->setAttribute('data-edit', $entryId); |
||
| 133 | $options->appendChild(new XMLElement('a', __('Edit'), array( |
||
| 134 | 'class' => 'edit ignore-collapsible', |
||
| 135 | 'data-edit' => $entryId, |
||
| 136 | ))); |
||
| 137 | } |
||
| 138 | if ($parentField->is('allow_delete')) { |
||
| 139 | $options->appendChild(new XMLElement('a', __('Delete'), array( |
||
| 140 | 'class' => 'delete ignore-collapsible', |
||
| 141 | 'data-delete' => $entryId, |
||
| 142 | ))); |
||
| 143 | } |
||
| 144 | if ($parentField->is('allow_link')) { |
||
| 145 | $options->appendChild(new XMLElement('a', __('Replace'), array( |
||
| 146 | 'class' => 'unlink ignore-collapsible', |
||
| 147 | 'data-replace' => $entryId, |
||
| 148 | ))); |
||
| 149 | } |
||
| 150 | if ($parentField->is('allow_goto')) { |
||
| 151 | $options->appendChild(new XMLElement('a', __('Go to'), array( |
||
| 152 | 'class' => 'goto ignore-collapsible', |
||
| 153 | 'data-goto' => $entryId, |
||
| 154 | ))); |
||
| 155 | } |
||
| 156 | if ($parentField->is('allow_delete') || |
||
| 157 | $parentField->is('allow_link') || $parentField->is('allow_unlink') || |
||
| 158 | $parentField->is('allow_search')) { |
||
| 159 | $options->appendChild(new XMLElement('a', __('Un-link'), array( |
||
| 160 | 'class' => 'unlink ignore-collapsible', |
||
| 161 | 'data-unlink' => $entryId, |
||
| 162 | ))); |
||
| 163 | } |
||
| 164 | $header->appendChild($options); |
||
| 165 | $li->appendChild($header); |
||
| 166 | } |
||
| 167 | |||
| 168 | $content = ERFXSLTUTilities::processXSLT($parentField, $entry, $entrySectionHandle, $entryFields, 'mode', isset($_REQUEST['debug'])); |
||
| 169 | |||
| 170 | if ($content) { |
||
| 171 | $li->appendChild(new XMLElement('div', $content, array( |
||
| 172 | 'class' => 'content', |
||
| 173 | 'data-collapsible-content' => '', |
||
| 174 | ))); |
||
| 175 | } |
||
| 176 | else { |
||
| 177 | if ($parentField->is('show_header')) { |
||
| 178 | $header->setAttribute('class', $header->getAttribute('class') . ' no-content'); |
||
| 179 | } |
||
| 180 | else { |
||
| 181 | $content = new XMLElement('div', null, array('class' => 'content')); |
||
| 182 | $content->appendChildArray($this->buildDefaultTitle($entry, $entryVisibleFields, $entryFields)); |
||
| 183 | $li->appendChild($content); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | $this->_Result->appendChild($li); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 217 | } |