| Conditions | 37 | 
| Paths | 1827 | 
| Total Lines | 143 | 
| Code Lines | 77 | 
| 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 | ||
| 33 | public function execute(array &$param_pool = null) | ||
| 34 |     { | ||
| 35 | $author_ids = array(); | ||
| 36 | |||
| 37 |         if (is_array($this->dsParamFILTERS) && !empty($this->dsParamFILTERS)) { | ||
| 38 |             foreach ($this->dsParamFILTERS as $field => $value) { | ||
| 39 |                 if (!is_array($value) && trim($value) == '') { | ||
| 40 | continue; | ||
| 41 | } | ||
| 42 | |||
| 43 | $ret = $this->__processAuthorFilter($field, $value); | ||
| 44 | |||
| 45 |                 if (empty($ret)) { | ||
| 46 | $author_ids = array(); | ||
| 47 | break; | ||
| 48 | } | ||
| 49 | |||
| 50 |                 if (empty($author_ids)) { | ||
| 51 | $author_ids = $ret; | ||
| 52 | continue; | ||
| 53 | } | ||
| 54 | |||
| 55 | $author_ids = array_intersect($author_ids, $ret); | ||
| 56 | } | ||
| 57 | |||
| 58 | $authors = AuthorManager::fetchByID(array_values($author_ids)); | ||
| 59 |         } else { | ||
| 60 | $authors = AuthorManager::fetch($this->dsParamSORT, $this->dsParamORDER); | ||
| 61 | } | ||
| 62 | |||
| 63 |         if ((!is_array($authors) || empty($authors)) && $this->dsParamREDIRECTONEMPTY === 'yes') { | ||
| 64 | throw new FrontendPageNotFoundException; | ||
| 65 |         } elseif (!is_array($authors) || empty($authors)) { | ||
| 66 | $result = $this->emptyXMLSet(); | ||
| 67 | return $result; | ||
| 68 |         } else { | ||
| 69 |             if ($this->_negate_result === true) { | ||
| 70 | return $this->negateXMLSet(); | ||
| 71 | } | ||
| 72 | |||
| 73 |             if (!$this->_param_output_only) { | ||
| 74 | $result = new XMLElement($this->dsParamROOTELEMENT); | ||
| 75 | } | ||
| 76 | |||
| 77 | $singleParam = false; | ||
| 78 | $key = 'ds-' . $this->dsParamROOTELEMENT; | ||
| 79 | |||
| 80 |             if (isset($this->dsParamPARAMOUTPUT)) { | ||
| 81 |                 if (!is_array($this->dsParamPARAMOUTPUT)) { | ||
| 82 | $this->dsParamPARAMOUTPUT = array($this->dsParamPARAMOUTPUT); | ||
| 83 | } | ||
| 84 | |||
| 85 | $singleParam = count($this->dsParamPARAMOUTPUT) === 1; | ||
| 86 | } | ||
| 87 | |||
| 88 |             foreach ($authors as $author) { | ||
| 89 |                 if (isset($this->dsParamPARAMOUTPUT)) { | ||
| 90 |                     foreach ($this->dsParamPARAMOUTPUT as $param) { | ||
| 91 | // The new style of paramater is `ds-datasource-handle.field-handle` | ||
| 92 |                         $param_key = $key . '.' . str_replace(':', '-', $param); | ||
| 93 | |||
| 94 |                         if (!is_array($param_pool[$param_key])) { | ||
| 95 | $param_pool[$param_key] = array(); | ||
| 96 | } | ||
| 97 | |||
| 98 | $param_pool[$param_key][] = ($param === 'name' ? $author->getFullName() : $author->get($param)); | ||
| 99 | |||
| 100 |                         if ($singleParam) { | ||
| 101 |                             if (!is_array($param_pool[$key])) { | ||
| 102 | $param_pool[$key] = array(); | ||
| 103 | } | ||
| 104 | |||
| 105 | $param_pool[$key][] = ($param === 'name' ? $author->getFullName() : $author->get($param)); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 |                 if ($this->_param_output_only) { | ||
| 111 | continue; | ||
| 112 | } | ||
| 113 | |||
| 114 |                 $xAuthor = new XMLElement('author'); | ||
| 115 | $xAuthor->setAttributeArray(array( | ||
| 116 |                     'id' => $author->get('id'), | ||
| 117 |                     'user-type' => $author->get('user_type'), | ||
| 118 |                     'primary-account' => $author->get('primary') | ||
| 119 | )); | ||
| 120 | |||
| 121 | // No included elements, so just create the Author XML | ||
| 122 |                 if (!isset($this->dsParamINCLUDEDELEMENTS) || !is_array($this->dsParamINCLUDEDELEMENTS) || empty($this->dsParamINCLUDEDELEMENTS)) { | ||
| 123 | $result->appendChild($xAuthor); | ||
| 124 |                 } else { | ||
| 125 | // Name | ||
| 126 |                     if (in_array('name', $this->dsParamINCLUDEDELEMENTS)) { | ||
| 127 | $xAuthor->appendChild( | ||
| 128 |                             new XMLElement('name', $author->getFullName()) | ||
| 129 | ); | ||
| 130 | } | ||
| 131 | |||
| 132 | // Username | ||
| 133 |                     if (in_array('username', $this->dsParamINCLUDEDELEMENTS)) { | ||
| 134 | $xAuthor->appendChild( | ||
| 135 |                             new XMLElement('username', $author->get('username')) | ||
| 136 | ); | ||
| 137 | } | ||
| 138 | |||
| 139 | |||
| 140 |                     if (in_array('email', $this->dsParamINCLUDEDELEMENTS)) { | ||
| 141 | $xAuthor->appendChild( | ||
| 142 |                             new XMLElement('email', $author->get('email')) | ||
| 143 | ); | ||
| 144 | } | ||
| 145 | |||
| 146 | // Author Token | ||
| 147 |                     if (in_array('author-token', $this->dsParamINCLUDEDELEMENTS) && $author->isTokenActive()) { | ||
| 148 | $xAuthor->appendChild( | ||
| 149 |                             new XMLElement('author-token', $author->createAuthToken()) | ||
| 150 | ); | ||
| 151 | } | ||
| 152 | |||
| 153 | // Default Area | ||
| 154 |                     if (in_array('default-area', $this->dsParamINCLUDEDELEMENTS) && !is_null($author->get('default_area'))) { | ||
| 155 | // Section | ||
| 156 |                         if ($section = SectionManager::fetch($author->get('default_area'))) { | ||
| 157 |                             $default_area = new XMLElement('default-area', $section->get('name')); | ||
| 158 |                             $default_area->setAttributeArray(array('id' => $section->get('id'), 'handle' => $section->get('handle'), 'type' => 'section')); | ||
| 159 | $xAuthor->appendChild($default_area); | ||
| 160 | |||
| 161 | // Pages | ||
| 162 |                         } else { | ||
| 163 |                             $default_area = new XMLElement('default-area', $author->get('default_area')); | ||
| 164 |                             $default_area->setAttribute('type', 'page'); | ||
| 165 | $xAuthor->appendChild($default_area); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | $result->appendChild($xAuthor); | ||
| 170 | } | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | return $result; | ||
| 175 | } | ||
| 176 | } | ||
| 177 |