| Conditions | 2 |
| Paths | 2 |
| Total Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 40 | protected function registerConnection( |
||
| 41 | FieldDefinitionNode &$fieldDefinition, |
||
| 42 | ObjectTypeDefinitionNode &$parentType, |
||
| 43 | ?int $defaultCount = null, |
||
| 44 | ?int $maxCount = null, |
||
| 45 | ?ObjectTypeDefinitionNode $edgeType = null |
||
| 46 | ): void { |
||
| 47 | // Register cursor specific pagination type |
||
| 48 | $this->addCursorPaginationInfoType(); |
||
| 49 | |||
| 50 | $fieldTypeName = ASTHelper::getUnderlyingTypeName($fieldDefinition); |
||
| 51 | |||
| 52 | if ($edgeType) { |
||
| 53 | $connectionEdgeName = $edgeType->name->value; |
||
| 54 | $connectionTypeName = "{$connectionEdgeName}Connection"; |
||
| 55 | } else { |
||
| 56 | $connectionEdgeName = "{$fieldTypeName}Edge"; |
||
| 57 | $connectionTypeName = "{$fieldTypeName}Connection"; |
||
| 58 | } |
||
| 59 | |||
| 60 | $connectionFieldName = addslashes(ConnectionField::class); |
||
| 61 | $connectionType = PartialParser::objectTypeDefinition(/** @lang GraphQL */ <<<GRAPHQL |
||
| 62 | "A paginated list of $fieldTypeName edges." |
||
| 63 | type $connectionTypeName { |
||
| 64 | "Pagination information about the list of edges." |
||
| 65 | pageInfo: CursorPageInfo! @field(resolver: "{$connectionFieldName}@pageInfoResolver") |
||
| 66 | |||
| 67 | "A list of $fieldTypeName edges." |
||
| 68 | edges: [$connectionEdgeName] @field(resolver: "{$connectionFieldName}@edgeResolver") |
||
| 69 | } |
||
| 70 | GRAPHQL |
||
| 71 | ); |
||
| 72 | $this->addPaginationWrapperType($connectionType); |
||
| 73 | |||
| 74 | $connectionEdge = $edgeType |
||
| 75 | ?? $this->documentAST->types[$connectionEdgeName] |
||
| 76 | ?? PartialParser::objectTypeDefinition(/** @lang GraphQL */ <<<GRAPHQL |
||
| 77 | "An edge that contains a node of type $fieldTypeName and a cursor." |
||
| 78 | type $connectionEdgeName { |
||
| 79 | "The $fieldTypeName node." |
||
| 80 | node: $fieldTypeName |
||
| 81 | } |
||
| 82 | GRAPHQL |
||
| 83 | ); |
||
| 84 | $this->documentAST->setTypeDefinition($connectionEdge); |
||
| 85 | |||
| 86 | $inputValueDefinitions = [ |
||
| 87 | self::countArgument('first', $defaultCount, $maxCount), |
||
| 88 | "\"A cursor after which elements are returned.\"\nafter: String", |
||
| 89 | ]; |
||
| 90 | |||
| 91 | $connectionArguments = PartialParser::inputValueDefinitions($inputValueDefinitions); |
||
| 92 | |||
| 93 | $fieldDefinition->arguments = ASTHelper::mergeNodeList($fieldDefinition->arguments, $connectionArguments); |
||
| 94 | $fieldDefinition->type = PartialParser::namedType($connectionTypeName); |
||
| 95 | $parentType->fields = ASTHelper::mergeNodeList($parentType->fields, [$fieldDefinition]); |
||
|
|
|||
| 96 | } |
||
| 97 | |||
| 124 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..