| Conditions | 12 |
| Paths | 6 |
| Total Lines | 72 |
| Code Lines | 47 |
| Lines | 37 |
| Ratio | 51.39 % |
| 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 |
||
| 31 | public function visit(Visitor $visitor, Generator $generator, $data) |
||
| 32 | { |
||
| 33 | $generator->startObjectElement('ErrorMessage'); |
||
| 34 | |||
| 35 | $statusCode = $this->getStatus(); |
||
| 36 | $visitor->setStatus($statusCode); |
||
| 37 | $visitor->setHeader('Content-Type', $generator->getMediaType('ErrorMessage')); |
||
| 38 | |||
| 39 | $generator->startValueElement('errorCode', $statusCode); |
||
| 40 | $generator->endValueElement('errorCode'); |
||
| 41 | |||
| 42 | $generator->startValueElement('errorMessage', $this->httpStatusCodes[$statusCode]); |
||
| 43 | $generator->endValueElement('errorMessage'); |
||
| 44 | |||
| 45 | $errorDetails = ['fields' => []]; |
||
| 46 | if ($data instanceof RESTContentFieldValidationException && $this->translator) { |
||
| 47 | $errorDescription = $data->getMessage(); |
||
| 48 | |||
| 49 | foreach ($data->getFieldErrors() as $fieldTypeId => $translations) { |
||
| 50 | foreach ($translations as $languageCode => $validationErrors) { |
||
|
|
|||
| 51 | if (is_array($validationErrors)) { |
||
| 52 | foreach ($validationErrors as $validationError) { |
||
| 53 | View Code Duplication | if ($validationError instanceof Translatable) { |
|
| 54 | $errorDetails['fields'][$fieldTypeId][] = [ |
||
| 55 | 'type' => $validationError->getTarget(), |
||
| 56 | 'message' => $this->translator->trans( |
||
| 57 | $this->translationToString($validationError->getTranslatableMessage()), |
||
| 58 | $validationError->getTranslatableMessage()->values, |
||
| 59 | 'repository_exceptions' |
||
| 60 | ), |
||
| 61 | ]; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | View Code Duplication | } else if ($validationErrors instanceof Translatable) { |
|
| 65 | $errorDetails['fields'][$fieldTypeId][] = [ |
||
| 66 | 'type' => $validationErrors->getTarget(), |
||
| 67 | 'message' => $this->translator->trans( |
||
| 68 | $this->translationToString($validationErrors->getTranslatableMessage()), |
||
| 69 | $validationErrors->getTranslatableMessage()->values, |
||
| 70 | 'repository_exceptions' |
||
| 71 | ), |
||
| 72 | ]; |
||
| 73 | } else { |
||
| 74 | // TODO: exception, invalid ValidationError |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | View Code Duplication | } else if ($data instanceof Translatable && $this->translator) { |
|
| 79 | $errorDescription = $this->translator->trans($data->getMessageTemplate(), $data->getParameters(), 'repository_exceptions'); |
||
| 80 | } else { |
||
| 81 | $errorDescription = $data->getMessage(); |
||
| 82 | } |
||
| 83 | |||
| 84 | $generator->startValueElement('errorDescription', $errorDescription); |
||
| 85 | $generator->endValueElement('errorDescription'); |
||
| 86 | |||
| 87 | $generator->startValueElement('errorDetails', $errorDetails); |
||
| 88 | $generator->endValueElement('errorDetails'); |
||
| 89 | |||
| 90 | View Code Duplication | if ($this->debug) { |
|
| 91 | $generator->startValueElement('trace', $data->getTraceAsString()); |
||
| 92 | $generator->endValueElement('trace'); |
||
| 93 | |||
| 94 | $generator->startValueElement('file', $data->getFile()); |
||
| 95 | $generator->endValueElement('file'); |
||
| 96 | |||
| 97 | $generator->startValueElement('line', $data->getLine()); |
||
| 98 | $generator->endValueElement('line'); |
||
| 99 | } |
||
| 100 | |||
| 101 | $generator->endObjectElement('ErrorMessage'); |
||
| 102 | } |
||
| 103 | |||
| 123 |