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 |
||
65 | 62 | protected function treatExceptions(array $errors, $throwRawException) |
|
66 | { |
||
67 | $treatedExceptions = [ |
||
68 | 62 | 'errors' => [], |
|
69 | 'extensions' => [ |
||
70 | 'warnings' => [], |
||
71 | ], |
||
72 | ]; |
||
73 | |||
74 | /** @var GraphQLError $error */ |
||
75 | 62 | foreach ($errors as $error) { |
|
76 | 17 | $rawException = $this->convertException($error->getPrevious()); |
|
77 | |||
78 | // raw GraphQL Error or InvariantViolation exception |
||
79 | 17 | if (null === $rawException || $rawException instanceof GraphQLUserError) { |
|
80 | 9 | $treatedExceptions['errors'][] = $error; |
|
81 | 9 | continue; |
|
82 | } |
||
83 | |||
84 | // user error |
||
85 | 9 | if ($rawException instanceof $this->userErrorClass) { |
|
86 | 4 | $treatedExceptions['errors'][] = $error; |
|
87 | 4 | if ($rawException->getPrevious()) { |
|
88 | 1 | $this->logException($rawException->getPrevious()); |
|
89 | } |
||
90 | 4 | continue; |
|
91 | } |
||
92 | |||
93 | // user warning |
||
94 | 6 | if ($rawException instanceof $this->userWarningClass) { |
|
95 | 5 | $treatedExceptions['extensions']['warnings'][] = $error; |
|
96 | 5 | if ($rawException->getPrevious()) { |
|
97 | 1 | $this->logException($rawException->getPrevious(), LogLevel::WARNING); |
|
98 | } |
||
99 | 5 | continue; |
|
100 | } |
||
101 | |||
102 | // multiple errors |
||
103 | 2 | if ($rawException instanceof UserErrors) { |
|
104 | 1 | $rawExceptions = $rawException; |
|
105 | 1 | foreach ($rawExceptions->getErrors() as $rawException) { |
|
106 | 1 | $treatedExceptions['errors'][] = GraphQLError::createLocatedError($rawException, $error->nodes); |
|
107 | } |
||
108 | 1 | continue; |
|
109 | } |
||
110 | |||
111 | // if is a try catch exception wrapped in Error |
||
112 | 2 | if ($throwRawException) { |
|
113 | 1 | throw $rawException; |
|
114 | } |
||
115 | |||
116 | 1 | $this->logException($rawException, LogLevel::CRITICAL); |
|
117 | |||
118 | 1 | $treatedExceptions['errors'][] = new GraphQLError( |
|
119 | 1 | $this->internalErrorMessage, |
|
120 | 1 | $error->nodes, |
|
121 | 1 | $error->getSource(), |
|
122 | 1 | $error->getPositions(), |
|
123 | 1 | $error->path, |
|
124 | 1 | $rawException |
|
|
|||
125 | ); |
||
126 | } |
||
127 | |||
128 | 61 | return $treatedExceptions; |
|
129 | } |
||
130 | |||
183 |
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: