| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 36 |
| 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 |
||
| 20 | public function testInvoke() |
||
| 21 | { |
||
| 22 | $container = $this->getMockBuilder(ContainerInterface::class) |
||
| 23 | ->setMethods(['get', 'has']) |
||
| 24 | ->getMock(); |
||
| 25 | |||
| 26 | $config = [ |
||
| 27 | 'doctrine' => [ |
||
| 28 | 'reddogs_doctrine_migrations' => [ |
||
| 29 | 'testkey' => [ |
||
| 30 | 'table_name' => 'testTableName', |
||
| 31 | 'directory' => 'testDirectory', |
||
| 32 | 'namespace' => 'TestNameSpace' |
||
| 33 | ] |
||
| 34 | ] |
||
| 35 | ] |
||
| 36 | ]; |
||
| 37 | |||
| 38 | $container->expects($this->at(0)) |
||
| 39 | ->method('get') |
||
| 40 | ->with($this->equalTo('config')) |
||
| 41 | ->will($this->returnValue($config)); |
||
| 42 | |||
| 43 | $entityManager = $this->getMockBuilder(EntityManager::class) |
||
| 44 | ->disableOriginalConstructor() |
||
| 45 | ->setMethods(['getConnection']) |
||
| 46 | ->getMock(); |
||
| 47 | $connection = $this->createMock(Connection::class); |
||
| 48 | $entityManager->expects($this->once()) |
||
| 49 | ->method('getConnection') |
||
| 50 | ->will($this->returnValue($connection)); |
||
| 51 | |||
| 52 | |||
| 53 | $container->expects($this->at(1)) |
||
| 54 | ->method('get') |
||
| 55 | ->with($this->equalTo(EntityManager::class)) |
||
| 56 | ->will($this->returnValue($entityManager)); |
||
| 57 | |||
| 58 | $service = $this->factory->__invoke($container, MigrateAllCommand::class); |
||
| 59 | |||
| 60 | $this->assertInstanceOf(MigrateAllCommand::class, $service); |
||
| 61 | $configurations = $service->getConfigurations(); |
||
| 62 | $this->assertCount(1, $configurations); |
||
| 63 | $this->assertArrayHasKey('testkey', $configurations); |
||
| 64 | |||
| 65 | $this->assertSame('testTableName', $configurations['testkey']->getMigrationsTableName()); |
||
| 66 | $this->assertSame('testDirectory', $configurations['testkey']->getMigrationsDirectory()); |
||
| 67 | $this->assertSame('TestNameSpace', $configurations['testkey']->getMigrationsNamespace()); |
||
| 68 | |||
| 69 | $migrations = $service->getMigrations(); |
||
|
|
|||
| 70 | } |
||
| 71 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.