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 | 63 |
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 |
||
50 | 45 | protected function treatExceptions(array $errors, $throwRawException) |
|
51 | { |
||
52 | $treatedExceptions = [ |
||
53 | 45 | 'errors' => [], |
|
54 | 'extensions' => [ |
||
55 | 45 | 'warnings' => [], |
|
56 | 45 | ], |
|
57 | 45 | ]; |
|
58 | |||
59 | /** @var Error $error */ |
||
60 | 45 | foreach ($errors as $error) { |
|
61 | 12 | $rawException = $this->convertException($error->getPrevious()); |
|
62 | |||
63 | // Parse error or user error |
||
64 | 12 | if (null === $rawException) { |
|
65 | 4 | $treatedExceptions['errors'][] = $error; |
|
66 | 4 | continue; |
|
67 | } |
||
68 | |||
69 | 9 | if ($rawException instanceof UserError) { |
|
70 | 4 | $treatedExceptions['errors'][] = $error; |
|
71 | 4 | if ($rawException->getPrevious()) { |
|
72 | 1 | $this->logException($rawException->getPrevious()); |
|
73 | 1 | } |
|
74 | 4 | continue; |
|
75 | } |
||
76 | |||
77 | // user warnings |
||
78 | 6 | if ($rawException instanceof UserWarning) { |
|
79 | 5 | $treatedExceptions['extensions']['warnings'][] = $error; |
|
80 | 5 | if ($rawException->getPrevious()) { |
|
81 | 1 | $this->logException($rawException->getPrevious()); |
|
82 | 1 | } |
|
83 | 5 | continue; |
|
84 | } |
||
85 | |||
86 | // multiple errors |
||
87 | 2 | if ($rawException instanceof UserErrors) { |
|
88 | 1 | $rawExceptions = $rawException; |
|
89 | 1 | foreach ($rawExceptions->getErrors() as $rawException) { |
|
90 | 1 | $treatedExceptions['errors'][] = Error::createLocatedError($rawException, $error->nodes); |
|
91 | 1 | } |
|
92 | 1 | continue; |
|
93 | } |
||
94 | |||
95 | // if is a try catch exception wrapped in Error |
||
96 | 2 | if ($throwRawException) { |
|
97 | 1 | throw $rawException; |
|
98 | } |
||
99 | |||
100 | 1 | $this->logException($rawException); |
|
101 | |||
102 | 1 | $treatedExceptions['errors'][] = new Error( |
|
103 | 1 | $this->internalErrorMessage, |
|
104 | 1 | $error->nodes, |
|
105 | 1 | $rawException, |
|
106 | 1 | $error->getSource(), |
|
107 | 1 | $error->getPositions() |
|
108 | 1 | ); |
|
109 | 44 | } |
|
110 | |||
111 | 44 | return $treatedExceptions; |
|
112 | } |
||
113 | |||
165 |