We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 11 |
Paths | 10 |
Total Lines | 65 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Tests | 33 |
CRAP Score | 11 |
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 | 69 | protected function treatExceptions(array $errors, $throwRawException) |
|
74 | { |
||
75 | $treatedExceptions = [ |
||
76 | 69 | 'errors' => [], |
|
77 | 'extensions' => [ |
||
78 | 'warnings' => [], |
||
79 | ], |
||
80 | ]; |
||
81 | |||
82 | /** @var GraphQLError $error */ |
||
83 | 69 | foreach ($errors as $error) { |
|
84 | 24 | $rawException = $this->convertException($error->getPrevious()); |
|
85 | |||
86 | // raw GraphQL Error or InvariantViolation exception |
||
87 | 24 | if (null === $rawException || $rawException instanceof GraphQLUserError) { |
|
88 | 9 | $treatedExceptions['errors'][] = $error; |
|
89 | 9 | continue; |
|
90 | } |
||
91 | |||
92 | // user error |
||
93 | 16 | if ($rawException instanceof $this->userErrorClass) { |
|
94 | 8 | $treatedExceptions['errors'][] = $error; |
|
95 | 8 | if ($rawException->getPrevious()) { |
|
96 | 5 | $this->logException($rawException->getPrevious()); |
|
97 | } |
||
98 | 8 | continue; |
|
99 | } |
||
100 | |||
101 | // user warning |
||
102 | 9 | if ($rawException instanceof $this->userWarningClass) { |
|
103 | 7 | $treatedExceptions['extensions']['warnings'][] = $error; |
|
104 | 7 | if ($rawException->getPrevious()) { |
|
105 | 3 | $this->logException($rawException->getPrevious(), LogLevel::WARNING); |
|
106 | } |
||
107 | 7 | continue; |
|
108 | } |
||
109 | |||
110 | // multiple errors |
||
111 | 3 | 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 | } |
||
116 | 1 | continue; |
|
117 | } |
||
118 | |||
119 | // if is a try catch exception wrapped in Error |
||
120 | 3 | if ($throwRawException) { |
|
121 | 2 | 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 | 1 | $rawException |
|
|
|||
133 | ); |
||
134 | } |
||
135 | |||
136 | 67 | return $treatedExceptions; |
|
137 | } |
||
138 | |||
224 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: