We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 10 |
| Paths | 10 |
| Total Lines | 64 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 40 |
| CRAP Score | 10 |
| 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 |
||
| 73 | 47 | protected function treatExceptions(array $errors, $throwRawException) |
|
| 74 | { |
||
| 75 | $treatedExceptions = [ |
||
| 76 | 47 | 'errors' => [], |
|
| 77 | 'extensions' => [ |
||
| 78 | 47 | 'warnings' => [], |
|
| 79 | 47 | ], |
|
| 80 | 47 | ]; |
|
| 81 | |||
| 82 | /** @var Error $error */ |
||
| 83 | 47 | foreach ($errors as $error) { |
|
| 84 | 12 | $rawException = $this->convertException($error->getPrevious()); |
|
| 85 | |||
| 86 | // Parse error or user error |
||
| 87 | 12 | if (null === $rawException) { |
|
| 88 | 4 | $treatedExceptions['errors'][] = $error; |
|
| 89 | 4 | continue; |
|
| 90 | } |
||
| 91 | |||
| 92 | // user error |
||
| 93 | 9 | if ($rawException instanceof $this->userErrorClass) { |
|
| 94 | 4 | $treatedExceptions['errors'][] = $error; |
|
| 95 | 4 | if ($rawException->getPrevious()) { |
|
| 96 | 1 | $this->logException($rawException->getPrevious()); |
|
| 97 | 1 | } |
|
| 98 | 4 | continue; |
|
| 99 | } |
||
| 100 | |||
| 101 | // user warning |
||
| 102 | 6 | if ($rawException instanceof $this->userWarningClass) { |
|
| 103 | 5 | $treatedExceptions['extensions']['warnings'][] = $error; |
|
| 104 | 5 | if ($rawException->getPrevious()) { |
|
| 105 | 1 | $this->logException($rawException->getPrevious(), LogLevel::WARNING); |
|
| 106 | 1 | } |
|
| 107 | 5 | continue; |
|
| 108 | } |
||
| 109 | |||
| 110 | // multiple errors |
||
| 111 | 2 | if ($rawException instanceof UserErrors) { |
|
| 112 | 1 | $rawExceptions = $rawException; |
|
| 113 | 1 | foreach ($rawExceptions->getErrors() as $rawException) { |
|
| 114 | 1 | $treatedExceptions['errors'][] = Error::createLocatedError($rawException, $error->nodes); |
|
| 115 | 1 | } |
|
| 116 | 1 | continue; |
|
| 117 | } |
||
| 118 | |||
| 119 | // if is a try catch exception wrapped in Error |
||
| 120 | 2 | if ($throwRawException) { |
|
| 121 | 1 | throw $rawException; |
|
| 122 | } |
||
| 123 | |||
| 124 | 1 | $this->logException($rawException, LogLevel::CRITICAL); |
|
| 125 | |||
| 126 | 1 | $treatedExceptions['errors'][] = new Error( |
|
| 127 | 1 | $this->internalErrorMessage, |
|
| 128 | 1 | $error->nodes, |
|
| 129 | 1 | $rawException, |
|
| 130 | 1 | $error->getSource(), |
|
| 131 | 1 | $error->getPositions() |
|
| 132 | 1 | ); |
|
| 133 | 46 | } |
|
| 134 | |||
| 135 | 46 | return $treatedExceptions; |
|
| 136 | } |
||
| 137 | |||
| 184 |