| Conditions | 11 |
| Paths | 30 |
| Total Lines | 30 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 71 | public function addThrowable(string $fieldName, Throwable $throwable) |
||
| 72 | { |
||
| 73 | $prefix = $this->prefix ? ($this->prefix . '.' . $fieldName) : $fieldName; |
||
| 74 | if ($throwable instanceof ErrorBagAwareException) { |
||
| 75 | $this->merge($throwable->getErrorBag()); |
||
| 76 | return; |
||
| 77 | } |
||
| 78 | if ($validationErrors = $this->extractValidationErrors($throwable)) { |
||
| 79 | $expectedPrefix = $prefix . '.'; |
||
| 80 | foreach ($validationErrors as $key => $validationError) { |
||
| 81 | if (('' . $key) !== $prefix && strpos($key, $expectedPrefix) !== 0) { |
||
| 82 | if ($key === '') { |
||
| 83 | $key = $prefix; |
||
| 84 | } else { |
||
| 85 | $key = $expectedPrefix . $key; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | if (!is_array($validationError)) { |
||
| 89 | $validationError = [$validationError]; |
||
| 90 | } |
||
| 91 | foreach ($validationError as $error) { |
||
| 92 | $this->errors[$key][] = new ErrorBagField($error, null, $throwable); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | return; |
||
| 96 | } |
||
| 97 | $this->errors[$prefix][] = new ErrorBagField( |
||
| 98 | $throwable->getMessage(), |
||
| 99 | $throwable instanceof LocalizationableException ? $throwable->getI18n() : null, |
||
| 100 | $throwable |
||
| 101 | ); |
||
| 178 |