| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| Code Lines | 45 |
| 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 |
||
| 30 | public function testBasicFields() { |
||
| 31 | $user = $this->createUser(); |
||
| 32 | $node = $this->createNode([ |
||
| 33 | 'title' => 'Node in default language', |
||
| 34 | 'type' => 'test', |
||
| 35 | 'status' => 1, |
||
| 36 | 'uid' => $user->id(), |
||
| 37 | ]); |
||
| 38 | |||
| 39 | $translation = $node->addTranslation('fr', ['title' => 'French node']); |
||
| 40 | $translation->save(); |
||
| 41 | |||
| 42 | $created = (new DateTime())->setTimestamp($node->getCreatedTime())->format(DateTime::ISO8601); |
||
| 43 | $changed = (new DateTime())->setTimestamp($node->getChangedTime())->format(DateTime::ISO8601); |
||
| 44 | |||
| 45 | $values = [ |
||
| 46 | 'entityId' => $node->id(), |
||
| 47 | 'entityUuid' => $node->uuid(), |
||
| 48 | 'entityLabel' => $node->label(), |
||
| 49 | 'entityType' => $node->getEntityTypeId(), |
||
| 50 | 'entityBundle' => $node->bundle(), |
||
| 51 | 'entityLanguage' => [ |
||
| 52 | 'id' => $node->language()->getId(), |
||
| 53 | 'name' => $node->language()->getName(), |
||
| 54 | 'direction' => $node->language()->getDirection(), |
||
| 55 | 'weight' => $node->language()->getWeight(), |
||
| 56 | ], |
||
| 57 | 'entityUrl' => [ |
||
| 58 | 'path' => '/node/' . $node->id(), |
||
| 59 | ], |
||
| 60 | 'entityOwner' => [ |
||
| 61 | 'entityLabel' => $user->label(), |
||
| 62 | ], |
||
| 63 | // TODO: Fix this. |
||
| 64 | 'entityTranslation' => [ |
||
| 65 | 'entityLabel' => $translation->label(), |
||
| 66 | ], |
||
| 67 | 'entityPublished' => TRUE, |
||
| 68 | 'entityCreated' => $created, |
||
| 69 | 'entityChanged' => $changed, |
||
| 70 | 'viewAccess' => TRUE, |
||
| 71 | 'updateAccess' => TRUE, |
||
| 72 | 'deleteAccess' => FALSE, |
||
| 73 | ]; |
||
| 74 | |||
| 75 | $query = $this->getQueryFromFile('basic_fields.gql'); |
||
| 76 | |||
| 77 | // TODO: Check cache metadata. |
||
| 78 | $metadata = $this->defaultCacheMetaData(); |
||
| 79 | $metadata->addCacheContexts([ |
||
| 80 | 'user.node_grants:view', |
||
| 81 | ]); |
||
| 82 | |||
| 83 | $metadata->addCacheTags([ |
||
| 84 | 'node:1', |
||
| 85 | 'node_list', |
||
| 86 | 'user:1', |
||
| 87 | ]); |
||
| 88 | |||
| 89 | $this->assertResults($query, ['nid' => (string) $node->id()], [ |
||
| 90 | 'node' => ['entities' => [$values]], |
||
| 91 | ], $metadata); |
||
| 92 | } |
||
| 93 | |||
| 95 |