| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 102 | public function testDefaultConfigurationFile() |
||
| 103 | { |
||
| 104 | $testFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.Monitor::CONFIG_FILENAME; |
||
| 105 | |||
| 106 | $configurationLoader = new ConfigurationLoader(); |
||
| 107 | $configurationDumper = new ConfigurationDumper(); |
||
| 108 | $filesystem = new Filesystem(); |
||
| 109 | |||
| 110 | $argsMock = $this->prophesize(Args::class); |
||
| 111 | $argsMock |
||
| 112 | ->getOption(Argument::type('string')) |
||
| 113 | ->willReturn(sys_get_temp_dir()); |
||
| 114 | $ioMock = $this->prophesize(IO::class); |
||
| 115 | $ioMock |
||
| 116 | ->writeLine(Argument::type('string')) |
||
| 117 | ->shouldBeCalled(); |
||
| 118 | |||
| 119 | $commandMock = $this->prophesize(Command::class); |
||
| 120 | |||
| 121 | $initHandler = new InitHandler( |
||
| 122 | $configurationLoader, |
||
| 123 | $configurationDumper, |
||
| 124 | $filesystem |
||
| 125 | ); |
||
| 126 | |||
| 127 | $initHandler->handle( |
||
| 128 | $argsMock->reveal(), |
||
| 129 | $ioMock->reveal(), |
||
| 130 | $commandMock->reveal() |
||
| 131 | ); |
||
| 132 | |||
| 133 | // Test the configuration of the enduser file |
||
| 134 | $this->assertEquals( |
||
| 135 | $testFile, |
||
| 136 | $configurationLoader->getConfigurationFilepath() |
||
| 137 | ); |
||
| 138 | |||
| 139 | $this->assertEquals( |
||
| 140 | [ |
||
| 141 | 'urls' => [ |
||
| 142 | 'google' => [ |
||
| 143 | 'url' => 'https://www.google.fr', |
||
| 144 | 'timeout' => 1, |
||
| 145 | 'status_code' => 200, |
||
| 146 | ], |
||
| 147 | ], |
||
| 148 | ], |
||
| 149 | Yaml::parse(file_get_contents($testFile)) |
||
| 150 | ); |
||
| 151 | |||
| 152 | unlink($testFile); |
||
| 153 | } |
||
| 154 | } |
||
| 155 |
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: