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 | 65 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Tests | 38 |
CRAP Score | 10.0125 |
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 | 5 | protected function treatExceptions(array $errors, $throwRawException) |
|
74 | { |
||
75 | $treatedExceptions = [ |
||
76 | 5 | 'errors' => [], |
|
77 | 'extensions' => [ |
||
78 | 5 | 'warnings' => [], |
|
79 | 5 | ], |
|
80 | 5 | ]; |
|
81 | |||
82 | /** @var GraphQLError $error */ |
||
83 | 5 | foreach ($errors as $error) { |
|
84 | 5 | $rawException = $this->convertException($error->getPrevious()); |
|
85 | |||
86 | // Parse error or user error |
||
87 | 5 | if (null === $rawException) { |
|
88 | 2 | $treatedExceptions['errors'][] = $error; |
|
89 | 2 | continue; |
|
90 | } |
||
91 | |||
92 | // user error |
||
93 | 4 | if ($rawException instanceof $this->userErrorClass) { |
|
94 | 2 | $treatedExceptions['errors'][] = $error; |
|
95 | 2 | if ($rawException->getPrevious()) { |
|
96 | $this->logException($rawException->getPrevious()); |
||
97 | } |
||
98 | 2 | continue; |
|
99 | } |
||
100 | |||
101 | // user warning |
||
102 | 3 | if ($rawException instanceof $this->userWarningClass) { |
|
103 | 2 | $treatedExceptions['extensions']['warnings'][] = $error; |
|
104 | 2 | if ($rawException->getPrevious()) { |
|
105 | 1 | $this->logException($rawException->getPrevious(), LogLevel::WARNING); |
|
106 | 1 | } |
|
107 | 2 | 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'][] = GraphQLError::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 GraphQLError( |
|
127 | 1 | $this->internalErrorMessage, |
|
128 | 1 | $error->nodes, |
|
129 | 1 | $error->getSource(), |
|
130 | 1 | $error->getPositions(), |
|
131 | 1 | $error->path, |
|
132 | $rawException |
||
133 | 1 | ); |
|
134 | 4 | } |
|
135 | |||
136 | 4 | return $treatedExceptions; |
|
137 | } |
||
138 | |||
190 |