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