| Conditions | 1 |
| Paths | 1 |
| Total Lines | 134 |
| Code Lines | 99 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 100 | public function testUpgrade() |
||
| 101 | { |
||
| 102 | $output = new BufferedOutput(); |
||
| 103 | |||
| 104 | // null version check |
||
| 105 | $expectedData = array( |
||
| 106 | 'name' => 'modera/upgrade-bundle-test', |
||
| 107 | 'repositories' => array( |
||
| 108 | array( |
||
| 109 | 'type' => 'composer', |
||
| 110 | 'url' => 'http://packages.org', |
||
| 111 | ), |
||
| 112 | ), |
||
| 113 | 'require' => array( |
||
| 114 | 'test/dependency_1' => 'dev-master', |
||
| 115 | ), |
||
| 116 | ); |
||
| 117 | $this->assertEquals($expectedData, self::$composerFile->read()); |
||
| 118 | |||
| 119 | // 0.1.0 version check |
||
| 120 | $expectedData['require'] = array( |
||
| 121 | 'test/dependency_1' => '0.1.0', |
||
| 122 | 'test/dependency_2' => '0.1.0', |
||
| 123 | 'test/dependency_3' => '0.1.0', |
||
| 124 | ); |
||
| 125 | $expectedData['repositories'][] = array( |
||
| 126 | 'type' => 'vcs', |
||
| 127 | 'url' => 'ssh://[email protected]', |
||
| 128 | ); |
||
| 129 | $this->runUpdateDependenciesCommand($output); |
||
| 130 | $str = $output->fetch(); |
||
| 131 | $this->assertEquals('0.1.0', $this->getCurrentVersion()); |
||
| 132 | $this->assertEquals(1, substr_count($str, 'new Test\AddBundle\TestAddBundle()')); |
||
| 133 | $this->assertEquals(0, substr_count($str, 'new Test\RemoveBundle\TestRemoveBundle()')); |
||
| 134 | $this->assertEquals($expectedData, self::$composerFile->read()); |
||
| 135 | $this->assertTrue(is_file(self::$basePath.'/composer.backup.json')); |
||
| 136 | unlink(self::$basePath.'/composer.backup.json'); |
||
| 137 | |||
| 138 | // 0.1.0 version run commands |
||
| 139 | $this->runCommandsCommand($output); |
||
| 140 | $str = $output->fetch(); |
||
| 141 | $this->assertEquals(0, substr_count($str, 'help --format=json')); |
||
| 142 | $this->assertEquals(0, substr_count($str, 'help --format=txt')); |
||
| 143 | |||
| 144 | // emulate composer.json changes |
||
| 145 | $tmp = self::$composerFile->read(); |
||
| 146 | $tmp['require']['test/dependency_1'] = 'dev-master'; |
||
| 147 | self::$composerFile->write($tmp); |
||
| 148 | |||
| 149 | // 0.1.1 version check |
||
| 150 | $expectedData['require'] = array( |
||
| 151 | 'test/dependency_1' => '0.1.1', |
||
| 152 | 'test/dependency_2' => '0.1.0', |
||
| 153 | ); |
||
| 154 | unset($expectedData['repositories'][1]); |
||
| 155 | $expectedData['repositories'] = array_values($expectedData['repositories']); |
||
| 156 | $this->runUpdateDependenciesCommand($output); |
||
| 157 | $str = $output->fetch(); |
||
| 158 | $this->assertEquals('0.1.1', $this->getCurrentVersion()); |
||
| 159 | $this->assertEquals(0, substr_count($str, 'new Test\AddBundle\TestAddBundle()')); |
||
| 160 | $this->assertEquals(1, substr_count($str, 'new Test\RemoveBundle\TestRemoveBundle()')); |
||
| 161 | $this->assertEquals($expectedData, self::$composerFile->read()); |
||
| 162 | $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.0.backup.json')); |
||
| 163 | unlink(self::$basePath.'/composer.v0.1.0.backup.json'); |
||
| 164 | |||
| 165 | // 0.1.1 version run commands |
||
| 166 | $this->runCommandsCommand($output); |
||
| 167 | $str = $output->fetch(); |
||
| 168 | $this->assertEquals(1, substr_count($str, 'help --format=json')); |
||
| 169 | $this->assertEquals(0, substr_count($str, 'help --format=txt')); |
||
| 170 | |||
| 171 | // emulate composer.json changes |
||
| 172 | $tmp = self::$composerFile->read(); |
||
| 173 | $tmp['require']['test/dependency_2'] = 'dev-master'; |
||
| 174 | self::$composerFile->write($tmp); |
||
| 175 | |||
| 176 | // 0.1.2 version check |
||
| 177 | $expectedData['require'] = array( |
||
| 178 | 'test/dependency_1' => '0.1.1', |
||
| 179 | 'test/dependency_2' => '0.1.0', |
||
| 180 | 'test/dependency_4' => '0.1.0', |
||
| 181 | ); |
||
| 182 | $this->runUpdateDependenciesCommand($output); |
||
| 183 | $str = $output->fetch(); |
||
| 184 | $this->assertEquals('0.1.2', $this->getCurrentVersion()); |
||
| 185 | $this->assertEquals(0, substr_count($str, 'new Test\AddBundle\TestAddBundle()')); |
||
| 186 | $this->assertEquals(0, substr_count($str, 'new Test\RemoveBundle\TestRemoveBundle()')); |
||
| 187 | $this->assertEquals($expectedData, self::$composerFile->read()); |
||
| 188 | $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.1.backup.json')); |
||
| 189 | unlink(self::$basePath.'/composer.v0.1.1.backup.json'); |
||
| 190 | |||
| 191 | // 0.1.2 version run commands |
||
| 192 | $this->runCommandsCommand($output); |
||
| 193 | $str = $output->fetch(); |
||
| 194 | $this->assertEquals(0, substr_count($str, 'help --format=json')); |
||
| 195 | $this->assertEquals(1, substr_count($str, 'help --format=txt')); |
||
| 196 | |||
| 197 | // 0.1.3 version check |
||
| 198 | $this->runUpdateDependenciesCommand($output); |
||
| 199 | $str = $output->fetch(); |
||
| 200 | $this->assertEquals('0.1.3', $this->getCurrentVersion()); |
||
| 201 | $this->assertEquals(1, substr_count($str, 'Some foo instruction')); |
||
| 202 | $this->assertEquals(0, substr_count($str, 'Some bar instruction')); |
||
| 203 | $this->assertEquals(0, substr_count($str, 'Some baz instruction')); |
||
| 204 | $this->assertEquals($expectedData, self::$composerFile->read()); |
||
| 205 | $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.2.backup.json')); |
||
| 206 | unlink(self::$basePath.'/composer.v0.1.2.backup.json'); |
||
| 207 | |||
| 208 | // 0.1.4 version check |
||
| 209 | $this->runUpdateDependenciesCommand($output); |
||
| 210 | $str = $output->fetch(); |
||
| 211 | $this->assertEquals('0.1.4', $this->getCurrentVersion()); |
||
| 212 | $this->assertEquals(0, substr_count($str, 'Some foo instruction')); |
||
| 213 | $this->assertEquals(1, substr_count($str, 'Some bar instruction')); |
||
| 214 | $this->assertEquals(0, substr_count($str, 'Some baz instruction')); |
||
| 215 | $this->assertEquals($expectedData, self::$composerFile->read()); |
||
| 216 | $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.3.backup.json')); |
||
| 217 | unlink(self::$basePath.'/composer.v0.1.3.backup.json'); |
||
| 218 | |||
| 219 | // 0.1.5 version check |
||
| 220 | $expectedData['require'] = array( |
||
| 221 | 'test/dependency_1' => '0.1.1', |
||
| 222 | 'test/dependency_4' => '0.1.1', |
||
| 223 | ); |
||
| 224 | $this->runUpdateDependenciesCommand($output); |
||
| 225 | $str = $output->fetch(); |
||
| 226 | $this->assertEquals('0.1.5', $this->getCurrentVersion()); |
||
| 227 | $this->assertEquals(0, substr_count($str, 'Some foo instruction')); |
||
| 228 | $this->assertEquals(0, substr_count($str, 'Some bar instruction')); |
||
| 229 | $this->assertEquals(1, substr_count($str, 'Some baz instruction')); |
||
| 230 | $this->assertEquals($expectedData, self::$composerFile->read()); |
||
| 231 | $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.4.backup.json')); |
||
| 232 | unlink(self::$basePath.'/composer.v0.1.4.backup.json'); |
||
| 233 | } |
||
| 234 | } |
||
| 235 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..