Conditions | 3 |
Paths | 4 |
Total Lines | 67 |
Code Lines | 39 |
Lines | 6 |
Ratio | 8.96 % |
Changes | 3 | ||
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 |
||
68 | public function testEntityEmbedButtonMarkup() { |
||
69 | // Ensure that the route is not accessible with text format without the |
||
70 | // button configured. |
||
71 | $this->getEmbedDialog('plain_text', 'node'); |
||
72 | $this->assertResponse(404, 'Embed dialog is not accessible with a filter that does not have an editor configuration.'); |
||
73 | |||
74 | // Add an empty configuration for the plain_text editor configuration. |
||
75 | $editor = Editor::create([ |
||
76 | 'format' => 'plain_text', |
||
77 | 'editor' => 'ckeditor', |
||
78 | ]); |
||
79 | $editor->save(); |
||
80 | $this->getEmbedDialog('plain_text', 'node'); |
||
81 | $this->assertResponse(403, 'Embed dialog is not accessible with a filter that does not have the embed button assigned to it.'); |
||
82 | |||
83 | // Ensure that the route is accessible with a valid embed button. |
||
84 | // 'Node' embed button is provided by default by the module and hence the |
||
85 | // request must be successful. |
||
86 | $this->getEmbedDialog('custom_format', 'node'); |
||
87 | $this->assertResponse(200, 'Embed dialog is accessible with correct filter format and embed button.'); |
||
88 | |||
89 | // Ensure form structure of the 'select' step and submit form. |
||
90 | $this->assertFieldByName('entity_id', '', 'Entity ID/UUID field is present.'); |
||
91 | |||
92 | // Check that 'Next' is a primary button. |
||
93 | $this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Next', 'Next is a primary button'); |
||
94 | |||
95 | $title = $this->node->getTitle() . ' (' . $this->node->id() . ')'; |
||
96 | $edit = ['entity_id' => $title]; |
||
97 | $response = $this->drupalPostAjaxForm(NULL, $edit, 'op'); |
||
98 | $plugins = [ |
||
99 | 'entity_reference:entity_reference_label', |
||
100 | 'entity_reference:entity_reference_entity_id', |
||
101 | 'view_mode:node.full', |
||
102 | 'view_mode:node.rss', |
||
103 | 'view_mode:node.search_index', |
||
104 | 'view_mode:node.search_result', |
||
105 | 'view_mode:node.teaser', |
||
106 | ]; |
||
107 | View Code Duplication | foreach ($plugins as $plugin) { |
|
|
|||
108 | $this->assertTrue(strpos($response[2]['data'], $plugin), 'Plugin ' . $plugin . ' is available in selection.'); |
||
109 | } |
||
110 | |||
111 | $this->container->get('config.factory')->getEditable('entity_embed.settings') |
||
112 | ->set('rendered_entity_mode', TRUE)->save(); |
||
113 | $this->displayPluginManager()->clearCachedDefinitions(); |
||
114 | |||
115 | $this->getEmbedDialog('custom_format', 'node'); |
||
116 | $title = $this->node->getTitle() . ' (' . $this->node->id() . ')'; |
||
117 | $edit = ['entity_id' => $title]; |
||
118 | $response = $this->drupalPostAjaxForm(NULL, $edit, 'op'); |
||
119 | |||
120 | $plugins = [ |
||
121 | 'entity_reference:entity_reference_label', |
||
122 | 'entity_reference:entity_reference_entity_id', |
||
123 | 'entity_reference:entity_reference_entity_view', |
||
124 | ]; |
||
125 | View Code Duplication | foreach ($plugins as $plugin) { |
|
126 | $this->assertTrue(strpos($response[2]['data'], $plugin), 'Plugin ' . $plugin . ' is available in selection.'); |
||
127 | } |
||
128 | /*$this->drupalPostForm(NULL, $edit, 'Next'); |
||
129 | // Ensure form structure of the 'embed' step and submit form. |
||
130 | $this->assertFieldByName('attributes[data-entity-embed-display]', 'Entity Embed Display plugin field is present.'); |
||
131 | |||
132 | // Check that 'Embed' is a primary button. |
||
133 | $this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Embed', 'Embed is a primary button');*/ |
||
134 | } |
||
135 | |||
173 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.