| Conditions | 1 |
| Paths | 1 |
| Total Lines | 86 |
| Code Lines | 61 |
| 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 |
||
| 26 | public function testEntityQuery() { |
||
| 27 | $a = $this->createNode([ |
||
| 28 | 'title' => 'Node A', |
||
| 29 | 'type' => 'a', |
||
| 30 | ]); |
||
| 31 | |||
| 32 | $b = $this->createNode([ |
||
| 33 | 'title' => 'Node B', |
||
| 34 | 'type' => 'a', |
||
| 35 | ]); |
||
| 36 | |||
| 37 | $c = $this->createNode([ |
||
| 38 | 'title' => 'Node C', |
||
| 39 | 'type' => 'a', |
||
| 40 | ]); |
||
| 41 | |||
| 42 | $d = $this->createNode([ |
||
| 43 | 'title' => 'Node D', |
||
| 44 | 'type' => 'b', |
||
| 45 | ]); |
||
| 46 | |||
| 47 | $a->save(); |
||
| 48 | $b->save(); |
||
| 49 | $c->save(); |
||
| 50 | $d->save(); |
||
| 51 | |||
| 52 | // TODO: Check cache metadata. |
||
| 53 | $metadata = $this->defaultCacheMetaData(); |
||
| 54 | $metadata->addCacheContexts(['user.node_grants:view']); |
||
| 55 | $metadata->addCacheTags([ |
||
| 56 | 'entity_bundles', |
||
| 57 | 'entity_field_info', |
||
| 58 | 'entity_types', |
||
| 59 | 'node:' . $a->id(), |
||
| 60 | 'node:' . $b->id(), |
||
| 61 | 'node:' . $c->id(), |
||
| 62 | 'node:' . $d->id(), |
||
| 63 | 'node_list', |
||
| 64 | ]); |
||
| 65 | |||
| 66 | $this->assertResults($this->getQueryFromFile('entity_query.gql'), [], [ |
||
| 67 | 'a' => [ |
||
| 68 | 'entities' => [ |
||
| 69 | ['uuid' => $a->uuid()], |
||
| 70 | ['uuid' => $b->uuid()], |
||
| 71 | ['uuid' => $c->uuid()], |
||
| 72 | ], |
||
| 73 | 'count' => 3, |
||
| 74 | ], |
||
| 75 | 'b' => [ |
||
| 76 | 'entities' => [ |
||
| 77 | ['uuid' => $d->uuid()], |
||
| 78 | ], |
||
| 79 | 'count' => 1, |
||
| 80 | ], |
||
| 81 | 'limit' => [ |
||
| 82 | 'entities' => [ |
||
| 83 | ['uuid' => $a->uuid()], |
||
| 84 | ['uuid' => $b->uuid()], |
||
| 85 | ], |
||
| 86 | 'count' => 3, |
||
| 87 | ], |
||
| 88 | 'offset' => [ |
||
| 89 | 'entities' => [ |
||
| 90 | ['uuid' => $b->uuid()], |
||
| 91 | ['uuid' => $c->uuid()], |
||
| 92 | ], |
||
| 93 | 'count' => 3, |
||
| 94 | ], |
||
| 95 | 'offset_limit' => [ |
||
| 96 | 'entities' => [ |
||
| 97 | ['uuid' => $b->uuid()], |
||
| 98 | ], |
||
| 99 | 'count' => 3, |
||
| 100 | ], |
||
| 101 | 'all_nodes' => [ |
||
| 102 | 'entities' => [ |
||
| 103 | ['uuid' => $a->uuid()], |
||
| 104 | ['uuid' => $b->uuid()], |
||
| 105 | ['uuid' => $c->uuid()], |
||
| 106 | ['uuid' => $d->uuid()], |
||
| 107 | ], |
||
| 108 | 'count' => 4, |
||
| 109 | ], |
||
| 110 | ], $metadata); |
||
| 111 | } |
||
| 112 | |||
| 114 |