| Conditions | 10 |
| Paths | 21 |
| Total Lines | 41 |
| Code Lines | 24 |
| 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 |
||
| 50 | private static function toString(JobInfo $jobInfo) |
||
| 51 | { |
||
| 52 | $jobError = null; |
||
| 53 | |||
| 54 | $jobDetail = $jobInfo->getDetail(); |
||
| 55 | if (null !== $jobDetail) { |
||
| 56 | $jobErrors = $jobDetail->getErrors(); |
||
| 57 | if (null !== $jobErrors && count($jobErrors) > 0) { |
||
| 58 | $jobError = $jobErrors[0]; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | if (!$jobError instanceof JobError) { |
||
| 63 | return 'Job execution failed with unknown error'; |
||
| 64 | } |
||
| 65 | |||
| 66 | $message = $jobError->getMessage(); |
||
| 67 | $status = $jobInfo->getStatus(); |
||
| 68 | if (0 === mb_strlen($message, Constraints::UTF_8)) { |
||
| 69 | if (JobInfo::STATUS_FAILED === $status) { |
||
| 70 | return 'Job execution failed'; |
||
| 71 | } elseif (JobInfo::STATUS_CANCELLED === $status) { |
||
| 72 | return 'Job execution cancelled'; |
||
| 73 | } |
||
| 74 | |||
| 75 | return 'Job execution failed with unknown error'; |
||
| 76 | } |
||
| 77 | |||
| 78 | $detail = $jobError->getDetail(); |
||
| 79 | if (0 === mb_strlen($detail, Constraints::UTF_8)) { |
||
| 80 | return $message; |
||
| 81 | } |
||
| 82 | |||
| 83 | $string = $detail; |
||
| 84 | |||
| 85 | $extraDetail = $jobError->getExtraDetail(); |
||
| 86 | if (mb_strlen($extraDetail, Constraints::UTF_8) > 0) { |
||
| 87 | $string .= ' (' . $extraDetail . ')'; |
||
| 88 | } |
||
| 89 | |||
| 90 | return $string; |
||
| 91 | } |
||
| 93 |