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