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