Conditions | 1 |
Paths | 1 |
Total Lines | 80 |
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 |
||
19 | public function testDefaultEnum() |
||
20 | { |
||
21 | $enumType = new EnumType([ |
||
22 | 'name' => 'InternalStatus', |
||
23 | 'values' => [ |
||
24 | [ |
||
25 | 'name' => 'ACTIVE', |
||
26 | 'value' => 1, |
||
27 | ], |
||
28 | [ |
||
29 | 'name' => 'DISABLED', |
||
30 | 'value' => 0, |
||
31 | ], |
||
32 | ] |
||
33 | ]); |
||
34 | $schema = new Schema([ |
||
35 | 'query' => new ObjectType([ |
||
36 | 'name' => 'RootQuery', |
||
37 | 'fields' => [ |
||
38 | 'stringQuery' => [ |
||
39 | 'type' => new StringType(), |
||
40 | 'args' => [ |
||
41 | 'statObject' => new InputObjectType([ |
||
42 | 'name' => 'StatObjectType', |
||
43 | 'fields' => [ |
||
44 | 'status' => [ |
||
45 | 'type' => $enumType, |
||
46 | 'defaultValue' => 1 |
||
47 | ], |
||
48 | 'level' => new NonNullType(new IntType()) |
||
49 | ] |
||
50 | ]) |
||
51 | ], |
||
52 | 'resolve' => function ($source, $args) { |
||
53 | return sprintf('Result with level %s and status %s', |
||
54 | $args['statObject']['level'], $args['statObject']['status'] |
||
55 | ); |
||
56 | }, |
||
57 | ], |
||
58 | 'enumObject' => [ |
||
59 | 'type' => new ObjectType([ |
||
60 | 'name' => 'EnumObject', |
||
61 | 'fields' => [ |
||
62 | 'status' => $enumType |
||
63 | ] |
||
64 | ]), |
||
65 | 'resolve' => function() { |
||
66 | return [ |
||
67 | 'status' => null |
||
68 | ]; |
||
69 | } |
||
70 | ], |
||
71 | |||
72 | ] |
||
73 | ]) |
||
74 | ]); |
||
75 | |||
76 | $processor = new Processor($schema); |
||
77 | $processor->processPayload('{ stringQuery(statObject: { level: 1 }) }'); |
||
78 | $result = $processor->getResponseData(); |
||
79 | $this->assertEquals(['data' => [ |
||
80 | 'stringQuery' => 'Result with level 1 and status 1' |
||
81 | ]], $result); |
||
82 | |||
83 | $processor->processPayload('{ stringQuery(statObject: { level: 1, status: DISABLED }) }'); |
||
84 | $result = $processor->getResponseData(); |
||
85 | |||
86 | $this->assertEquals(['data' => [ |
||
87 | 'stringQuery' => 'Result with level 1 and status 0' |
||
88 | ]], $result); |
||
89 | |||
90 | $processor->processPayload('{ enumObject { status } }'); |
||
91 | $result = $processor->getResponseData(); |
||
92 | |||
93 | $this->assertEquals(['data' => [ |
||
94 | 'enumObject' => [ |
||
95 | 'status' => null |
||
96 | ] |
||
97 | ]], $result); |
||
98 | } |
||
99 | |||
100 | } |