Conditions | 2 |
Paths | 1 |
Total Lines | 74 |
Code Lines | 33 |
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 |
||
15 | public function testInternalVariableArgument() |
||
16 | { |
||
17 | $type1 = new ObjectType([ |
||
18 | 'name' => 'Type1', |
||
19 | 'fields' => [ |
||
20 | 'id' => new IdType(), |
||
21 | 'name' => new StringType(), |
||
22 | ], |
||
23 | ]); |
||
24 | $type2 = new ObjectType([ |
||
25 | 'name' => 'Type2', |
||
26 | 'fields' => [ |
||
27 | 'id' => new IdType(), |
||
28 | 'title' => new StringType(), |
||
29 | ], |
||
30 | ]); |
||
31 | |||
32 | $unionType = new UnionType([ |
||
33 | 'name' => 'Union', |
||
34 | 'types' => [$type1, $type2], |
||
35 | 'resolveType' => function ($value) use ($type1, $type2) { |
||
36 | if (isset($value['name'])) { |
||
37 | return $type1; |
||
38 | } |
||
39 | |||
40 | return $type2; |
||
41 | }, |
||
42 | ]); |
||
43 | |||
44 | $schema = new Schema([ |
||
45 | 'query' => new ObjectType([ |
||
46 | 'name' => 'RootQuery', |
||
47 | 'fields' => [ |
||
48 | 'list' => [ |
||
49 | 'type' => new ListType($unionType), |
||
50 | 'resolve' => function () { |
||
51 | return [ |
||
52 | [ |
||
53 | 'id' => 1, |
||
54 | 'name' => 'name', |
||
55 | ], |
||
56 | [ |
||
57 | 'id' => 2, |
||
58 | 'title' => 'title', |
||
59 | ], |
||
60 | ]; |
||
61 | }, |
||
62 | ], |
||
63 | ], |
||
64 | ]), |
||
65 | ]); |
||
66 | $processor = new Processor($schema); |
||
67 | $response = $processor->processPayload(' |
||
|
|||
68 | { |
||
69 | list { |
||
70 | ...UnitFragment |
||
71 | } |
||
72 | } |
||
73 | |||
74 | fragment UnitFragment on Union { |
||
75 | __typename |
||
76 | |||
77 | ... on Type1 { |
||
78 | id |
||
79 | name |
||
80 | } |
||
81 | ... on Type2 { |
||
82 | id |
||
83 | title |
||
84 | } |
||
85 | } |
||
86 | ')->getResponseData(); |
||
87 | |||
88 | } |
||
89 | } |
||
90 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.