| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| Code Lines | 40 |
| 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 |
||
| 123 | public function testDefaultConfigurationFile() |
||
| 124 | { |
||
| 125 | $testFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.'.test.yml'; |
||
| 126 | |||
| 127 | $configurationLoader = new ConfigurationLoader( |
||
| 128 | sys_get_temp_dir(), |
||
| 129 | '.test.yml' |
||
| 130 | ); |
||
| 131 | |||
| 132 | $configurationDumper = new ConfigurationDumper(); |
||
| 133 | $filesystem = new Filesystem(); |
||
| 134 | |||
| 135 | $argsMock = $this->prophesize(Args::class); |
||
| 136 | $ioMock = $this->prophesize(IO::class); |
||
| 137 | $ioMock |
||
| 138 | ->writeLine(Argument::type('string')) |
||
| 139 | ->shouldBeCalled(); |
||
| 140 | |||
| 141 | $commandMock = $this->prophesize(Command::class); |
||
| 142 | |||
| 143 | $initHandler = new InitHandler( |
||
| 144 | $configurationLoader, |
||
| 145 | $configurationDumper, |
||
| 146 | $filesystem |
||
| 147 | ); |
||
| 148 | |||
| 149 | $initHandler->handle( |
||
| 150 | $argsMock->reveal(), |
||
| 151 | $ioMock->reveal(), |
||
| 152 | $commandMock->reveal() |
||
| 153 | ); |
||
| 154 | |||
| 155 | // Test the configuration of the enduser file |
||
| 156 | $this->assertEquals( |
||
| 157 | $testFile, |
||
| 158 | $configurationLoader->getConfigurationFilepath() |
||
| 159 | ); |
||
| 160 | |||
| 161 | $this->assertEquals( |
||
| 162 | [ |
||
| 163 | 'server' => [ |
||
| 164 | 'hostname' => null, |
||
| 165 | 'port' => null, |
||
| 166 | 'use_ssl' => null, |
||
| 167 | 'auth' => [ |
||
| 168 | 'username' => null, |
||
| 169 | 'password' => null, |
||
| 170 | ], |
||
| 171 | ], |
||
| 172 | 'urls' => [ |
||
| 173 | 'google' => [ |
||
| 174 | 'url' => 'https://www.google.fr', |
||
| 175 | 'timeout' => 1, |
||
| 176 | 'status_code' => 200, |
||
| 177 | 'service_uid' => '', |
||
| 178 | ], |
||
| 179 | ], |
||
| 180 | ], |
||
| 181 | Yaml::parse(file_get_contents($testFile)) |
||
| 182 | ); |
||
| 183 | |||
| 184 | unlink($testFile); |
||
| 185 | } |
||
| 186 | } |
||
| 187 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: