| Conditions | 10 |
| Paths | 17 |
| Total Lines | 39 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 37 | public function recognitionData() |
||
| 38 | { |
||
| 39 | $recognition = $this->recognition()->latest()->first(); |
||
| 40 | |||
| 41 | if (! $recognition) { |
||
| 42 | return [ |
||
| 43 | 'labels' => null, |
||
| 44 | 'faces' => null, |
||
| 45 | 'moderation' => null, |
||
| 46 | 'texts' => null, |
||
| 47 | ]; |
||
| 48 | } |
||
| 49 | |||
| 50 | // null indicates that the "recognition" has not been ran for the category |
||
| 51 | $labels = $faces = $moderation = $texts = null; |
||
| 52 | |||
| 53 | if ($recognition->labels && is_array($recognition->labels['Labels'])) { |
||
| 54 | $labels = $recognition->labels['Labels']; |
||
| 55 | } |
||
| 56 | |||
| 57 | if ($recognition->faces && is_array($recognition->faces['FaceDetails'])) { |
||
| 58 | $faces = $recognition->faces['FaceDetails']; |
||
| 59 | } |
||
| 60 | |||
| 61 | Log::info('before moderation'); |
||
| 62 | if ($recognition->moderation && is_array($recognition->moderation['ModerationLabels'])) { |
||
| 63 | Log::info('after', $recognition->moderation['ModerationLabels']); |
||
| 64 | $moderation = $recognition->moderation['ModerationLabels']; |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($recognition->ocr && is_array($recognition->ocr['TextDetections'])) { |
||
| 68 | $texts = $recognition->ocr['TextDetections']; |
||
| 69 | } |
||
| 70 | |||
| 71 | return [ |
||
| 72 | 'labels' => $labels, |
||
| 73 | 'faces' => $faces, |
||
| 74 | 'moderation' => $moderation, |
||
| 75 | 'texts' => $texts, |
||
| 76 | ]; |
||
| 79 |