Conditions | 2 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
74 | public function testStringCodeType() : void |
||
75 | { |
||
76 | $schema = new Schema([ |
||
77 | 'query' => new ObjectType(['name' => 'Query']), |
||
78 | 'mutation' => new ObjectType([ |
||
79 | 'name' => 'Mutation', |
||
80 | 'fields' => function () { |
||
81 | return [ |
||
82 | 'updateBook' => new ValidatedFieldDefinition([ |
||
83 | 'name' => 'updateBook', |
||
84 | 'type' => Type::boolean(), |
||
85 | 'args' => [ |
||
86 | 'bookId' => [ |
||
87 | 'type' => Type::id(), |
||
88 | 'errorCodes' => [ |
||
89 | 'invalidBookId' |
||
90 | ], |
||
91 | 'validate' => function ($bookId) { |
||
92 | return empty($bookId) ? ['invalidBookId', "Invalid Book Id"] : 0; |
||
93 | }, |
||
94 | ], |
||
95 | ], |
||
96 | 'resolve' => static function ($value) : bool { |
||
97 | return !!$value; |
||
98 | }, |
||
99 | ]), |
||
100 | ]; |
||
101 | }, |
||
102 | ]), |
||
103 | ]); |
||
104 | |||
105 | $res = GraphQL::executeQuery( |
||
106 | $schema, |
||
107 | Utils::nowdoc(' |
||
108 | mutation UpdateBook( |
||
109 | $bookId:ID |
||
110 | ) { |
||
111 | updateBook (bookId: $bookId) { |
||
112 | valid |
||
113 | fields { |
||
114 | bookId { |
||
115 | code |
||
116 | msg |
||
117 | } |
||
118 | } |
||
119 | result |
||
120 | } |
||
121 | } |
||
122 | '), |
||
123 | [], |
||
124 | null, |
||
125 | ['bookId' => null] |
||
126 | ); |
||
127 | |||
128 | static::assertEmpty($res->errors); |
||
129 | static::assertEquals($res->data['updateBook']['fields']['bookId']['code'], "invalidBookId"); |
||
130 | static::assertEquals($res->data['updateBook']['fields']['bookId']['msg'], "Invalid Book Id"); |
||
131 | } |
||
133 |