Conditions | 1 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 30 |
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 |
||
33 | public function testGraphQLSchemaFromDocumentationMustBeValid(): void |
||
34 | { |
||
35 | $types = $this->types; |
||
36 | $schema = new Schema([ |
||
37 | 'query' => new ObjectType([ |
||
38 | 'name' => 'query', |
||
39 | 'fields' => [ |
||
40 | 'posts' => [ |
||
41 | 'type' => Type::listOf($types->getOutput(Post::class)), // Use automated ObjectType for output |
||
42 | 'args' => [ |
||
43 | [ |
||
44 | 'name' => 'filter', |
||
45 | 'type' => $types->getFilter(Post::class), // Use automated filtering options |
||
46 | ], |
||
47 | [ |
||
48 | 'name' => 'sorting', |
||
49 | 'type' => $types->getSorting(Post::class), // Use automated sorting options |
||
50 | ], |
||
51 | ], |
||
52 | 'resolve' => function ($root, $args) use ($types): void { |
||
53 | $queryBuilder = $types->createFilteredQueryBuilder(Post::class, $args['filter'] ?? [], $args['sorting'] ?? []); |
||
|
|||
54 | |||
55 | // execute query... |
||
56 | }, |
||
57 | ], |
||
58 | ], |
||
59 | ]), |
||
60 | 'mutation' => new ObjectType([ |
||
61 | 'name' => 'mutation', |
||
62 | 'fields' => [ |
||
63 | 'createPost' => [ |
||
64 | 'type' => Type::nonNull($types->getOutput(Post::class)), |
||
65 | 'args' => [ |
||
66 | 'input' => Type::nonNull($types->getInput(Post::class)), // Use automated InputObjectType for input |
||
67 | ], |
||
68 | 'resolve' => function ($root, $args): void { |
||
2 ignored issues
–
show
|
|||
69 | // create new post and flush... |
||
70 | }, |
||
71 | ], |
||
72 | 'updatePost' => [ |
||
73 | 'type' => Type::nonNull($types->getOutput(Post::class)), |
||
74 | 'args' => [ |
||
75 | 'id' => Type::nonNull(Type::id()), // Use standard API when needed |
||
76 | 'input' => $types->getPartialInput(Post::class), // Use automated InputObjectType for partial input for updates |
||
77 | ], |
||
78 | 'resolve' => function ($root, $args): void { |
||
2 ignored issues
–
show
|
|||
79 | // update existing post and flush... |
||
80 | }, |
||
81 | ], |
||
82 | ], |
||
83 | ]), |
||
84 | ]); |
||
85 | |||
86 | $schema->assertValid(); |
||
87 | self::assertTrue(true, 'passed validation successfully'); |
||
88 | } |
||
182 |