| Conditions | 1 |
| Paths | 1 |
| Total Lines | 88 |
| Code Lines | 57 |
| 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 |
||
| 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 | 'locale' => 'es', |
||
| 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 | ]; |
||
| 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 | 'translator' => [ |
||
| 84 | 'locale' => 'es', |
||
| 85 | ], |
||
| 86 | |||
| 87 | 'delete_short_urls' => [ |
||
| 88 | 'visits_threshold' => 50, |
||
| 89 | 'check_visits_threshold' => true, |
||
| 90 | ], |
||
| 91 | |||
| 92 | 'dependencies' => [ |
||
| 93 | 'aliases' => [ |
||
| 94 | 'lock_store' => 'redis_lock_store', |
||
| 95 | ], |
||
| 96 | ], |
||
| 97 | |||
| 98 | 'redis' => [ |
||
| 99 | 'servers' => [ |
||
| 100 | 'tcp://1.1.1.1:1111', |
||
| 101 | 'tcp://1.2.2.2:2222', |
||
| 102 | ], |
||
| 103 | ], |
||
| 104 | ]; |
||
| 105 | |||
| 106 | $result = ($this->postProcessor)(array_merge($config, $simplified)); |
||
| 107 | |||
| 108 | $this->assertEquals(array_merge($expected, $simplified), $result); |
||
| 109 | } |
||
| 111 |