We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 6 |
| Paths | 2 |
| Total Lines | 79 |
| Code Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 65 |
| CRAP Score | 6.0001 |
| Changes | 6 | ||
| Bugs | 2 | 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 |
||
| 132 | 15 | ->end() |
|
| 133 | // normalized relay-connection |
||
| 134 | 15 | ->beforeNormalization() |
|
| 135 | 15 | ->ifTrue($typeKeyExists) |
|
| 136 | 15 | ->then($this->relayNormalizer('relay-connection', 'Overblog\GraphQLBundle\Relay\Connection\ConnectionDefinition')) |
|
| 137 | 15 | ->end() |
|
| 138 | // normalized relay-node |
||
| 139 | 15 | ->beforeNormalization() |
|
| 140 | 15 | ->ifTrue($typeKeyExists) |
|
| 141 | 15 | ->then($this->relayNormalizer('relay-node', 'Overblog\GraphQLBundle\Relay\Node\NodeDefinition')) |
|
| 142 | 15 | ->end() |
|
| 143 | // normalized relay-mutation-input |
||
| 144 | 15 | ->beforeNormalization() |
|
| 145 | 15 | ->ifTrue($typeKeyExists) |
|
| 146 | 15 | ->then($this->relayNormalizer('relay-mutation-input', 'Overblog\GraphQLBundle\Relay\Mutation\InputDefinition')) |
|
| 147 | 15 | ->end() |
|
| 148 | // normalized relay-mutation-payload |
||
| 149 | 15 | ->beforeNormalization() |
|
| 150 | ->ifTrue(function ($types) { return !empty($types) && is_array($types); }) |
||
| 151 | 15 | ->then($this->relayNormalizer('relay-mutation-payload', 'Overblog\GraphQLBundle\Relay\Mutation\PayloadDefinition')) |
|
| 152 | 15 | ->end(); |
|
| 153 | 15 | } |
|
| 154 | |||
| 155 | private function relayNormalizer($typeToTreat, $definitionBuilderClass) |
||
| 156 | { |
||
| 157 | 15 | return function ($types) use ($typeToTreat, $definitionBuilderClass) { |
|
| 158 | 15 | foreach ($types as $name => $type) { |
|
| 159 | 15 | if (isset($type['type']) && is_string($type['type']) && $typeToTreat === $type['type']) { |
|
| 160 | 6 | $config = isset($type['config']) && is_array($type['config']) ? $type['config'] : []; |
|
| 161 | 6 | $config['name'] = $name; |
|
| 162 | |||
| 163 | /** @var MappingInterface $builder */ |
||
| 164 | 6 | $builder = new $definitionBuilderClass(); |
|
| 165 | |||
| 166 | 6 | $connectionDefinition = $builder->toMappingDefinition($config); |
|
| 167 | |||
| 168 | 6 | $types = array_replace($types, $connectionDefinition); |
|
| 169 | 6 | } |
|
| 170 | 15 | } |
|
| 171 | |||
| 172 | 15 | return $types; |
|
| 173 | 15 | }; |
|
| 174 | } |
||
| 175 | |||
| 176 | 15 | private function normalizedConfigTypeKey($type) |
|
| 177 | { |
||
| 178 | 15 | return '_'.str_replace('-', '_', $type).'_config'; |
|
| 179 | } |
||
| 180 | } |
||
| 181 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: