Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Lines | 54 |
Ratio | 100 % |
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 // phpcs:ignore Squiz.Commenting.FileComment.Missing |
||
15 | View Code Duplication | public function test_get_url() { |
|
16 | |||
17 | $url = Soft_Wp::get_url( 'simple' ); |
||
18 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org', $url ); |
||
19 | |||
20 | // Test invalid parameter. |
||
21 | $url = Soft_Wp::get_url( 'simple', array( 'invalid' => 'value' ) ); |
||
22 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org', $url ); |
||
23 | |||
24 | // Test path. |
||
25 | $url = Soft_Wp::get_url( 'simple', array( 'path' => 'value' ) ); |
||
26 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&path=value', $url ); |
||
27 | |||
28 | // Test path special chars. |
||
29 | $url = Soft_Wp::get_url( 'simple', array( 'path' => 'weird value!' ) ); |
||
30 | $v = rawurlencode( 'weird value!' ); |
||
31 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&path=' . $v, $url ); |
||
32 | |||
33 | // Test query. |
||
34 | $url = Soft_Wp::get_url( 'simple', array( 'query' => 'value' ) ); |
||
35 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&query=value', $url ); |
||
36 | |||
37 | // Test query special chars. |
||
38 | $url = Soft_Wp::get_url( 'simple', array( 'query' => 'key=value&key2=value2' ) ); |
||
39 | $v = rawurlencode( 'key=value&key2=value2' ); |
||
40 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&query=' . $v, $url ); |
||
41 | |||
42 | // Test anchor. |
||
43 | $url = Soft_Wp::get_url( 'simple', array( 'anchor' => 'value' ) ); |
||
44 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&anchor=value', $url ); |
||
45 | |||
46 | // Test anchor special chars. |
||
47 | $url = Soft_Wp::get_url( 'simple', array( 'anchor' => 'key=value&key2=value2' ) ); |
||
48 | $v = rawurlencode( 'key=value&key2=value2' ); |
||
49 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&anchor=' . $v, $url ); |
||
50 | |||
51 | // Test informing URL. |
||
52 | $url = Soft_Wp::get_url( 'https://wordpress.com/support' ); |
||
53 | $v = rawurlencode( 'https://wordpress.com/support' ); |
||
54 | $this->assertEquals( 'https://jetpack.com/redirect?url=' . $v . '&site=example.org', $url ); |
||
55 | |||
56 | // Test URL and query. |
||
57 | $url = Soft_Wp::get_url( 'https://wordpress.com/support', array( 'query' => 'key=value&key2=value2' ) ); |
||
58 | $v = rawurlencode( 'key=value&key2=value2' ); |
||
59 | $v_url = rawurlencode( 'https://wordpress.com/support' ); |
||
60 | $this->assertEquals( 'https://jetpack.com/redirect?url=' . $v_url . '&site=example.org&query=' . $v, $url ); |
||
61 | |||
62 | // Test URL and query, discarding info from url. |
||
63 | $url = Soft_Wp::get_url( 'https://wordpress.com/support?this=that#super', array( 'query' => 'key=value&key2=value2' ) ); |
||
64 | $v = rawurlencode( 'key=value&key2=value2' ); |
||
65 | $v_url = rawurlencode( 'https://wordpress.com/support' ); |
||
66 | $this->assertEquals( 'https://jetpack.com/redirect?url=' . $v_url . '&site=example.org&query=' . $v, $url ); |
||
67 | |||
68 | } |
||
69 | |||
76 |