Conditions | 7 |
Paths | 24 |
Total Lines | 63 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 56 |
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 |
||
182 | public function createLinkedIssue(Issue $issue, $project_key, $link_name, $link_direction, array $component_ids) |
||
183 | { |
||
184 | $create_fields = array( |
||
185 | 'description' => 'See ' . $issue->getKey() . '.', |
||
186 | 'components' => array(), |
||
187 | ); |
||
188 | |||
189 | foreach ( $this->_copyCustomFields as $custom_field ) { |
||
190 | if ( isset($this->_customFieldsMap[$custom_field]) ) { |
||
191 | $custom_field_id = $this->_customFieldsMap[$custom_field]; |
||
192 | $create_fields[$custom_field_id] = $this->getIssueCustomField($issue, $custom_field_id); |
||
193 | } |
||
194 | } |
||
195 | |||
196 | foreach ( $component_ids as $component_id ) { |
||
197 | $create_fields['components'][] = array('id' => (string)$component_id); |
||
198 | } |
||
199 | |||
200 | $create_issue_result = $this->jiraApi->createIssue( |
||
201 | $project_key, |
||
202 | $issue->get('summary'), |
||
1 ignored issue
–
show
|
|||
203 | $this->getChangelogEntryIssueTypeId(), |
||
204 | $create_fields |
||
205 | ); |
||
206 | |||
207 | $raw_create_issue_result = $create_issue_result->getResult(); |
||
208 | |||
209 | if ( array_key_exists('errors', $raw_create_issue_result) ) { |
||
210 | throw new \RuntimeException(sprintf( |
||
211 | 'Failed to create linked issue for "%s" issue. Errors: ' . PHP_EOL . '%s', |
||
212 | $issue->getKey(), |
||
213 | print_r($raw_create_issue_result['errors'], true) |
||
214 | )); |
||
215 | } |
||
216 | |||
217 | if ( $link_direction === self::LINK_DIRECTION_INWARD ) { |
||
218 | $issue_link_result = $this->jiraApi->api( |
||
1 ignored issue
–
show
|
|||
219 | Api::REQUEST_POST, |
||
220 | '/rest/api/2/issueLink', |
||
221 | array( |
||
222 | 'type' => array('name' => $link_name), |
||
223 | 'inwardIssue' => array('key' => $raw_create_issue_result['key']), |
||
224 | 'outwardIssue' => array('key' => $issue->getKey()), |
||
225 | ) |
||
226 | ); |
||
227 | } |
||
228 | elseif ( $link_direction === self::LINK_DIRECTION_OUTWARD ) { |
||
229 | $issue_link_result = $this->jiraApi->api( |
||
1 ignored issue
–
show
|
|||
230 | Api::REQUEST_POST, |
||
231 | '/rest/api/2/issueLink', |
||
232 | array( |
||
233 | 'type' => array('name' => $link_name), |
||
234 | 'inwardIssue' => array('key' => $issue->getKey()), |
||
235 | 'outwardIssue' => array('key' => $raw_create_issue_result['key']), |
||
236 | ) |
||
237 | ); |
||
238 | } |
||
239 | else { |
||
240 | throw new \InvalidArgumentException('The "' . $link_direction . '" link direction isn\'t valid.'); |
||
241 | } |
||
242 | |||
243 | return $raw_create_issue_result['key']; |
||
244 | } |
||
245 | |||
332 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: