Conditions | 1 |
Paths | 1 |
Total Lines | 88 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
21 | public function properlyMapsSimplifiedConfig(): void |
||
22 | { |
||
23 | $config = [ |
||
24 | 'app_options' => [ |
||
25 | 'disable_track_param' => 'foo', |
||
26 | ], |
||
27 | |||
28 | 'entity_manager' => [ |
||
29 | 'connection' => [ |
||
30 | 'driver' => 'mysql', |
||
31 | 'host' => 'shlink_db', |
||
32 | 'port' => '3306', |
||
33 | ], |
||
34 | ], |
||
35 | ]; |
||
36 | $simplified = [ |
||
37 | 'disable_track_param' => 'bar', |
||
38 | 'short_domain_schema' => 'https', |
||
39 | 'short_domain_host' => 'doma.in', |
||
40 | 'validate_url' => false, |
||
41 | 'delete_short_url_threshold' => 50, |
||
42 | 'not_found_redirect_to' => 'foobar.com', |
||
43 | 'redis_servers' => [ |
||
44 | 'tcp://1.1.1.1:1111', |
||
45 | 'tcp://1.2.2.2:2222', |
||
46 | ], |
||
47 | 'db_config' => [ |
||
48 | 'dbname' => 'shlink', |
||
49 | 'user' => 'foo', |
||
50 | 'password' => 'bar', |
||
51 | 'port' => '1234', |
||
52 | ], |
||
53 | 'base_path' => '/foo/bar', |
||
54 | ]; |
||
55 | $expected = [ |
||
56 | 'app_options' => [ |
||
57 | 'disable_track_param' => 'bar', |
||
58 | ], |
||
59 | |||
60 | 'entity_manager' => [ |
||
61 | 'connection' => [ |
||
62 | 'driver' => 'mysql', |
||
63 | 'host' => 'shlink_db', |
||
64 | 'dbname' => 'shlink', |
||
65 | 'user' => 'foo', |
||
66 | 'password' => 'bar', |
||
67 | 'port' => '1234', |
||
68 | ], |
||
69 | ], |
||
70 | |||
71 | 'url_shortener' => [ |
||
72 | 'domain' => [ |
||
73 | 'schema' => 'https', |
||
74 | 'hostname' => 'doma.in', |
||
75 | ], |
||
76 | 'validate_url' => false, |
||
77 | 'not_found_short_url' => [ |
||
78 | 'redirect_to' => 'foobar.com', |
||
79 | 'enable_redirection' => true, |
||
80 | ], |
||
81 | ], |
||
82 | |||
83 | 'delete_short_urls' => [ |
||
84 | 'visits_threshold' => 50, |
||
85 | 'check_visits_threshold' => true, |
||
86 | ], |
||
87 | |||
88 | 'dependencies' => [ |
||
89 | 'aliases' => [ |
||
90 | 'lock_store' => 'redis_lock_store', |
||
91 | ], |
||
92 | ], |
||
93 | |||
94 | 'redis' => [ |
||
95 | 'servers' => [ |
||
96 | 'tcp://1.1.1.1:1111', |
||
97 | 'tcp://1.2.2.2:2222', |
||
98 | ], |
||
99 | ], |
||
100 | |||
101 | 'router' => [ |
||
102 | 'base_path' => '/foo/bar', |
||
103 | ], |
||
104 | ]; |
||
105 | |||
106 | $result = ($this->postProcessor)(array_merge($config, $simplified)); |
||
107 | |||
108 | $this->assertEquals(array_merge($expected, $simplified), $result); |
||
109 | } |
||
111 |