| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 25 | public function testFail() |
||
| 26 | { |
||
| 27 | $owningSide = new DDC6613OwningSide(); |
||
| 28 | |||
| 29 | $this->_em->persist($owningSide); |
||
| 30 | $this->_em->flush(); |
||
| 31 | $this->_em->clear(); |
||
| 32 | |||
| 33 | $item1 = new DDC6613InverseSide(); |
||
| 34 | $item2 = new DDC6613InverseSide(); |
||
| 35 | |||
| 36 | $this->_em->persist($item1); |
||
| 37 | $this->_em->persist($item2); |
||
| 38 | $this->_em->flush(); |
||
| 39 | |||
| 40 | /* @var DDC6613OwningSide $foundOwningSide */ |
||
| 41 | $foundOwningSide = $this->_em->find(DDC6613OwningSide::class, $owningSide->id); |
||
| 42 | |||
| 43 | self::assertInstanceOf(DDC6613OwningSide::class, $foundOwningSide); |
||
| 44 | |||
| 45 | /* @var $phones PersistentCollection */ |
||
| 46 | $phones = $foundOwningSide->phones; |
||
| 47 | |||
| 48 | self::assertInstanceOf(PersistentCollection::class, $phones); |
||
| 49 | self::assertFalse($phones->isInitialized()); |
||
| 50 | self::assertFalse($phones->isDirty()); |
||
| 51 | |||
| 52 | $phones->add($item1); |
||
| 53 | |||
| 54 | self::assertFalse($phones->isInitialized()); |
||
| 55 | self::assertTrue($phones->isDirty()); |
||
| 56 | |||
| 57 | $this->_em->flush(); |
||
| 58 | |||
| 59 | self::assertFalse($phones->isInitialized()); |
||
| 60 | self::assertFalse($phones->isDirty()); |
||
| 61 | |||
| 62 | $phones->add($item2); |
||
| 63 | |||
| 64 | self::assertFalse($phones->isInitialized()); |
||
| 65 | self::assertTrue($phones->isDirty()); |
||
| 66 | |||
| 67 | $phones->initialize(); |
||
| 68 | |||
| 69 | self::assertTrue($phones->isInitialized()); |
||
| 70 | self::assertTrue($phones->isDirty()); |
||
| 71 | self::assertCount(2, $phones); |
||
| 72 | |||
| 73 | $this->_em->flush(); |
||
| 74 | |||
| 75 | self::assertFalse($phones->isDirty()); |
||
| 76 | self::assertTrue($phones->isInitialized()); |
||
| 77 | self::assertCount(2, $foundOwningSide->phones); |
||
| 78 | } |
||
| 79 | } |
||
| 107 | } |