| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 37 |
| 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 |
||
| 116 | public function testConfigFactoryGet() |
||
| 117 | { |
||
| 118 | $factory = new ConfigFactory(); |
||
| 119 | |||
| 120 | $factory->addDirectory(__DIR__ . '/Data/Config/Alpha'); |
||
| 121 | $factory->addDirectory(__DIR__ . '/Data/Config/Beta'); |
||
| 122 | |||
| 123 | $config = $factory->get('oof'); |
||
| 124 | |||
| 125 | $this->assertInstanceOf(ConfigInterface::class, $config); |
||
| 126 | $this->assertInstanceOf(AbstractConfig::class, $config); |
||
| 127 | $this->assertInstanceOf(Config::class, $config); |
||
| 128 | |||
| 129 | $this->assertEquals($this->path(__DIR__, 'Data', 'Config', 'Beta', 'oof.php'), $config->getFileName()); |
||
| 130 | |||
| 131 | $this->assertEquals('Service Name', $config['name']); |
||
| 132 | $this->assertEquals('main', $config['server']); |
||
| 133 | |||
| 134 | $servers = $config['servers']; |
||
| 135 | |||
| 136 | $this->assertIsArray($servers); |
||
| 137 | $this->assertArrayHasKey('main', $servers); |
||
| 138 | $this->assertArrayHasKey('alt', $servers); |
||
| 139 | |||
| 140 | $this->assertArrayHasKey($config['server'], $servers); |
||
| 141 | |||
| 142 | $main = $servers['main']; |
||
| 143 | |||
| 144 | $this->assertIsArray($main); |
||
| 145 | |||
| 146 | $this->assertArrayHasKey('host', $main); |
||
| 147 | $this->assertIsString($main['host']); |
||
| 148 | $this->assertEquals('http://www.service.com', $main['host']); |
||
| 149 | |||
| 150 | $this->assertArrayHasKey('port', $main); |
||
| 151 | $this->assertIsInt($main['port']); |
||
| 152 | $this->assertEquals(80, $main['port']); |
||
| 153 | |||
| 154 | $this->assertArrayHasKey('secure', $main); |
||
| 155 | $this->assertIsBool($main['secure']); |
||
| 156 | $this->assertEquals(false, $main['secure']); |
||
| 157 | |||
| 158 | $alt = $servers['alt']; |
||
| 159 | |||
| 160 | $this->assertIsArray($alt); |
||
| 161 | |||
| 162 | $this->assertArrayHasKey('host', $alt); |
||
| 163 | $this->assertIsString($alt['host']); |
||
| 164 | $this->assertEquals('https://www.service.com', $alt['host']); |
||
| 165 | |||
| 166 | $this->assertArrayHasKey('port', $alt); |
||
| 167 | $this->assertIsInt($alt['port']); |
||
| 168 | $this->assertEquals(443, $alt['port']); |
||
| 169 | |||
| 170 | $this->assertArrayHasKey('secure', $alt); |
||
| 171 | $this->assertIsBool($alt['secure']); |
||
| 172 | $this->assertEquals(true, $alt['secure']); |
||
| 173 | } |
||
| 175 |