We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 5 |
| Paths | 1 |
| Total Lines | 99 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 59 |
| CRAP Score | 5 |
| 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 |
||
| 19 | 27 | public function getFunctions() |
|
| 20 | { |
||
| 21 | return [ |
||
| 22 | 27 | new ExpressionFunction( |
|
| 23 | 27 | 'service', |
|
| 24 | function ($value) { |
||
| 25 | 2 | return sprintf('$container->get(%s)', $value); |
|
| 26 | } |
||
| 27 | 27 | ), |
|
| 28 | |||
| 29 | 27 | new ExpressionFunction( |
|
| 30 | 27 | 'parameter', |
|
| 31 | function ($value) { |
||
| 32 | 1 | return sprintf('$container->getParameter(%s)', $value); |
|
| 33 | } |
||
| 34 | 27 | ), |
|
| 35 | |||
| 36 | 27 | new ExpressionFunction( |
|
| 37 | 27 | 'isTypeOf', |
|
| 38 | function ($className) { |
||
| 39 | 1 | return sprintf('($className = %s) && $value instanceof $className', $className); |
|
| 40 | } |
||
| 41 | 27 | ), |
|
| 42 | |||
| 43 | 27 | new ExpressionFunction( |
|
| 44 | 27 | 'resolver', |
|
| 45 | function ($alias, $args = '[]') { |
||
| 46 | 8 | return sprintf('$container->get(\'overblog_graphql.resolver_resolver\')->resolve([%s, %s])', $alias, $args); |
|
| 47 | } |
||
| 48 | 27 | ), |
|
| 49 | |||
| 50 | 27 | new ExpressionFunction( |
|
| 51 | 27 | 'mutateAndGetPayloadCallback', |
|
| 52 | function ($mutateAndGetPayload) { |
||
| 53 | 2 | $code = 'function ($value) use ('.TypeGenerator::USE_FOR_CLOSURES.', $args, $info) { '; |
|
| 54 | 2 | $code .= 'return '.$mutateAndGetPayload.'; }'; |
|
| 55 | |||
| 56 | 2 | return $code; |
|
| 57 | } |
||
| 58 | 27 | ), |
|
| 59 | |||
| 60 | 27 | new ExpressionFunction( |
|
| 61 | 27 | 'idFetcherCallback', |
|
| 62 | function ($idFetcher) { |
||
| 63 | 2 | $code = 'function ($value) use ('.TypeGenerator::USE_FOR_CLOSURES.', $args, $info) { '; |
|
| 64 | 2 | $code .= 'return '.$idFetcher.'; }'; |
|
| 65 | |||
| 66 | 2 | return $code; |
|
| 67 | } |
||
| 68 | 27 | ), |
|
| 69 | |||
| 70 | 27 | new ExpressionFunction( |
|
| 71 | 27 | 'resolveSingleInputCallback', |
|
| 72 | function ($resolveSingleInput) { |
||
| 73 | 1 | $code = 'function ($value) use ('.TypeGenerator::USE_FOR_CLOSURES.', $args, $info) { '; |
|
| 74 | 1 | $code .= 'return '.$resolveSingleInput.'; }'; |
|
| 75 | |||
| 76 | 1 | return $code; |
|
| 77 | } |
||
| 78 | 27 | ), |
|
| 79 | |||
| 80 | 27 | new ExpressionFunction( |
|
| 81 | 27 | 'mutation', |
|
| 82 | function ($alias, $args = '[]') { |
||
| 83 | 2 | return sprintf('$container->get(\'overblog_graphql.mutation_resolver\')->resolve([%s, %s])', $alias, $args); |
|
| 84 | } |
||
| 85 | 27 | ), |
|
| 86 | |||
| 87 | 27 | new ExpressionFunction( |
|
| 88 | 27 | 'globalId', |
|
| 89 | function ($id, $typeName = null) { |
||
| 90 | 1 | $typeNameEmpty = null === $typeName || '""' === $typeName || 'null' === $typeName || 'false' === $typeName; |
|
| 91 | |||
| 92 | 1 | return sprintf( |
|
| 93 | 1 | '\\Overblog\\GraphQLBundle\\Relay\\Node\\GlobalId::toGlobalId(%s, %s)', |
|
| 94 | 1 | sprintf($typeNameEmpty ? '$info->parentType->name' : '%s', $typeName), |
|
| 95 | $id |
||
| 96 | 1 | ); |
|
| 97 | } |
||
| 98 | 27 | ), |
|
| 99 | |||
| 100 | 27 | new ExpressionFunction( |
|
| 101 | 27 | 'fromGlobalId', |
|
| 102 | function ($globalId) { |
||
| 103 | 1 | return sprintf( |
|
| 104 | 1 | '\\Overblog\\GraphQLBundle\\Relay\\Node\\GlobalId::fromGlobalId(%s)', |
|
| 105 | $globalId |
||
| 106 | 1 | ); |
|
| 107 | } |
||
| 108 | 27 | ), |
|
| 109 | |||
| 110 | 27 | new ExpressionFunction( |
|
| 111 | 27 | 'newObject', |
|
| 112 | 1 | function ($className, $args = '[]') { |
|
| 113 | 1 | return sprintf('(new \ReflectionClass(%s))->newInstanceArgs(%s)', $className, $args); |
|
| 114 | } |
||
| 115 | 27 | ), |
|
| 116 | 27 | ]; |
|
| 117 | } |
||
| 118 | } |
||
| 119 |