Conditions | 2 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
42 | protected function setUp() : void |
||
43 | { |
||
44 | $this->personType = new ObjectType([ |
||
45 | 'name' => 'Person', |
||
46 | 'fields' => [ |
||
47 | 'firstName' => [ |
||
48 | 'type' => Type::string(), |
||
49 | ], |
||
50 | ], |
||
51 | ]); |
||
52 | |||
53 | $this->bookType = new ObjectType([ |
||
54 | 'name' => 'Book', |
||
55 | 'fields' => [ |
||
56 | 'title' => [ |
||
57 | 'type' => Type::string(), |
||
58 | 'resolve' => static function ($book) { |
||
59 | return $book['title']; |
||
60 | }, |
||
61 | ], |
||
62 | 'author' => [ |
||
63 | 'type' => $this->personType, |
||
64 | 'resolve' => static function ($book) { |
||
65 | return $book['author']; |
||
66 | }, |
||
67 | ], |
||
68 | ], |
||
69 | ]); |
||
70 | |||
71 | $this->query = new ObjectType(['name' => 'Query']); |
||
72 | |||
73 | $this->schema = new Schema([ |
||
74 | 'query' => $this->query, |
||
75 | 'mutation' => new ObjectType([ |
||
76 | 'name' => 'Mutation', |
||
77 | 'fields' => function () { |
||
78 | return [ |
||
79 | 'updateBook' => new ValidatedFieldDefinition([ |
||
80 | 'name' => 'updateBook', |
||
81 | 'type' => $this->bookType, |
||
82 | 'args' => [ |
||
83 | 'bookId' => [ |
||
84 | 'type' => Type::id(), |
||
85 | 'errorCodes' => ['bookNotFound'], |
||
86 | 'validate' => function ($bookId) { |
||
87 | if (isset($this->data['books'][$bookId])) { |
||
88 | return 0; |
||
89 | } |
||
90 | |||
91 | return ['bookNotFound', 'Unknown book!']; |
||
92 | }, |
||
93 | ], |
||
94 | ], |
||
95 | 'resolve' => static function ($value) : bool { |
||
96 | return !!$value; |
||
97 | }, |
||
136 |