Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 2 |
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 |
||
24 | public function testEmbedButtonEditorAccessCheck() { |
||
25 | // The anonymous user should have access to the plain_text format, but it |
||
26 | // hasn't been configured to use an editor yet. |
||
27 | $this->getRoute('plain_text', 'embed_test_default'); |
||
28 | $this->assertResponse(404); |
||
29 | $this->assertCacheContext('route'); |
||
30 | $this->assertNoCacheTag('config:editor.editor.embed_test'); |
||
31 | $this->assertNoCacheTag('config:embed.button.embed_test_default'); |
||
32 | |||
33 | // The anonymous user should not have permission to use embed_test format. |
||
34 | $this->getRoute('embed_test', 'embed_test_default'); |
||
35 | $this->assertResponse(403); |
||
36 | $this->assertCacheContext('route'); |
||
37 | $this->assertNoCacheTag('config:editor.editor.embed_test'); |
||
38 | $this->assertNoCacheTag('config:embed.button.embed_test_default'); |
||
39 | |||
40 | // Now login a user that can use the embed_test format. |
||
41 | $this->drupalLogin($this->webUser); |
||
42 | |||
43 | $this->getRoute('plain_text', 'embed_test_default'); |
||
44 | $this->assertResponse(404); |
||
45 | $this->assertCacheContext('route'); |
||
46 | $this->assertNoCacheTag('config:editor.editor.plain_text'); |
||
47 | $this->assertNoCacheTag('config:embed.button.embed_test_default'); |
||
48 | |||
49 | // Add an empty configuration for the plain_text editor configuration. |
||
50 | $editor = Editor::create([ |
||
51 | 'format' => 'plain_text', |
||
52 | 'editor' => 'ckeditor', |
||
53 | ]); |
||
54 | $editor->save(); |
||
55 | $this->getRoute('plain_text', 'embed_test_default'); |
||
56 | $this->assertResponse(403); |
||
57 | $this->assertCacheContext('route'); |
||
58 | $this->assertCacheTag('config:editor.editor.plain_text'); |
||
59 | $this->assertCacheTag('config:embed.button.embed_test_default'); |
||
60 | |||
61 | $this->getRoute('embed_test', 'embed_test_default'); |
||
62 | $this->assertResponse(200); |
||
63 | $this->assertCacheContext('route'); |
||
64 | $this->assertCacheTag('config:editor.editor.embed_test'); |
||
65 | $this->assertCacheTag('config:embed.button.embed_test_default'); |
||
66 | $this->assertText(static::SUCCESS); |
||
67 | |||
68 | // Test route with an empty request. |
||
69 | $this->getRoute('embed_test', 'embed_test_default', ''); |
||
70 | $this->assertResponse(404); |
||
71 | $this->assertCacheContext('route'); |
||
72 | $this->assertCacheTag('config:editor.editor.embed_test'); |
||
73 | $this->assertCacheTag('config:embed.button.embed_test_default'); |
||
74 | |||
75 | // Test route with an invalid text format. |
||
76 | $this->getRoute('invalid_editor', 'embed_test_default'); |
||
77 | $this->assertResponse(404); |
||
78 | $this->assertCacheContext('route'); |
||
79 | $this->assertNoCacheTag('config:editor.editor.invalid_editor'); |
||
80 | $this->assertNoCacheTag('config:embed.button.embed_test_default'); |
||
81 | |||
82 | // Test route with an invalid embed button. |
||
83 | $this->getRoute('embed_test', 'invalid_button'); |
||
84 | $this->assertResponse(404); |
||
85 | $this->assertCacheContext('route'); |
||
86 | $this->assertNoCacheTag('config:editor.editor.embed_test'); |
||
87 | $this->assertNoCacheTag('config:embed.button.invalid_button'); |
||
88 | } |
||
89 | |||
112 |
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.