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