Conditions | 1 |
Paths | 1 |
Total Lines | 52 |
Code Lines | 32 |
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 |
||
48 | public function testSanitizeUrl() |
||
49 | { |
||
50 | // Strip line feeds |
||
51 | $this->assertSame( |
||
52 | 'One fish, Two fish, Red fish, Blue fish.', |
||
53 | UrlHelper::sanitizeUrl(implode( |
||
54 | "", |
||
55 | [ |
||
56 | "One fish, ", |
||
57 | PHP_EOL, |
||
58 | "Two fish, ", |
||
59 | "\r", |
||
60 | "Red fish, ", |
||
61 | "\n", |
||
62 | "Blue fish.", |
||
63 | ] |
||
64 | )) |
||
65 | ); |
||
66 | // Strip Twig code |
||
67 | $this->assertSame( |
||
68 | '', |
||
69 | UrlHelper::sanitizeUrl('{{ craft.app.config.general.actionTrigger }}') |
||
70 | ); |
||
71 | // Strip object syntax Twig code |
||
72 | $this->assertSame( |
||
73 | '', |
||
74 | UrlHelper::sanitizeUrl('{ craft.app.config.general.actionTrigger }') |
||
75 | ); |
||
76 | // Strip URL-encoded Twig code |
||
77 | $this->assertSame( |
||
78 | '', |
||
79 | UrlHelper::sanitizeUrl('%7B%7B%20craft.app.config.general.actionTrigger%20%7D%7D') |
||
80 | ); |
||
81 | // Strip URL-encoded object syntax Twig code |
||
82 | $this->assertSame( |
||
83 | '', |
||
84 | UrlHelper::sanitizeUrl('%7B%20craft.app.config.general.actionTrigger%20%7D') |
||
85 | ); |
||
86 | // Strip HTML entity-encoded Twig code |
||
87 | $this->assertSame( |
||
88 | '', |
||
89 | UrlHelper::sanitizeUrl('{{ craft.app.config.general.actionTrigger }}') |
||
90 | ); |
||
91 | // Strip HTML entity-encoded object syntax Twig code |
||
92 | $this->assertSame( |
||
93 | '', |
||
94 | UrlHelper::sanitizeUrl('{ craft.app.config.general.actionTrigger }') |
||
95 | ); |
||
96 | // Strip HTML |
||
97 | $this->assertSame( |
||
98 | '/woof/hello', |
||
99 | UrlHelper::sanitizeUrl('/woof/<blockquote>hello</blockquote>') |
||
100 | ); |
||
103 |