Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 37 |
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 |
||
57 | public function testEntityByIdWithTranslation() { |
||
58 | $node = $this->createNode([ |
||
59 | 'title' => 'English node', |
||
60 | 'type' => 'test', |
||
61 | ]); |
||
62 | $node->save(); |
||
63 | $node->addTranslation($this->frenchLangcode, ['title' => 'French node'])->save(); |
||
64 | $node->addTranslation($this->chineseSimplifiedLangcode, ['title' => 'Chinese simplified node'])->save(); |
||
65 | |||
66 | // Save a new draft. |
||
67 | $this |
||
68 | ->getNewDraft($node) |
||
69 | ->setPublished(FALSE) |
||
70 | ->setTitle('English node unpublished') |
||
71 | ->save(); |
||
72 | |||
73 | // TODO: Check chache metadata. |
||
74 | $metadata = $this->defaultCacheMetaData(); |
||
75 | $metadata->addCacheTags([ |
||
76 | 'entity_bundles', |
||
77 | 'entity_field_info', |
||
78 | 'entity_types', |
||
79 | 'node:1', |
||
80 | 'config:field.storage.node.body', |
||
81 | ]); |
||
82 | |||
83 | // Check English node. |
||
84 | $this->assertResults($this->getQueryFromFile('entity_by_id.gql'), [ |
||
85 | 'id' => $node->id(), |
||
86 | 'language' => 'en', |
||
87 | ], [ |
||
88 | 'nodeById' => [ |
||
89 | 'entityLabel' => 'English node', |
||
90 | ], |
||
91 | ], $metadata); |
||
92 | |||
93 | // Check French translation. |
||
94 | $this->assertResults($this->getQueryFromFile('entity_by_id.gql'), [ |
||
95 | 'id' => $node->id(), |
||
96 | 'language' => 'fr', |
||
97 | ], [ |
||
98 | 'nodeById' => [ |
||
99 | 'entityLabel' => 'French node', |
||
100 | ], |
||
101 | ], $metadata); |
||
102 | |||
103 | // Check Chinese simplified translation. |
||
104 | $this->assertResults($this->getQueryFromFile('entity_by_id.gql'), [ |
||
105 | 'id' => $node->id(), |
||
106 | 'language' => 'zh_hans', |
||
107 | ], [ |
||
108 | 'nodeById' => [ |
||
109 | 'entityLabel' => 'Chinese simplified node', |
||
110 | ], |
||
111 | ], $metadata); |
||
112 | } |
||
113 | |||
115 |