Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 9 | class Ticket4646InstanceOfTest extends OrmFunctionalTestCase |
||
| 10 | { |
||
| 11 | protected function setUp() |
||
| 12 | { |
||
| 13 | parent::setUp(); |
||
| 14 | |||
| 15 | $this->_schemaTool->createSchema([ |
||
| 16 | $this->_em->getClassMetadata(Person::class), |
||
| 17 | $this->_em->getClassMetadata(Employee::class), |
||
| 18 | ]); |
||
| 19 | } |
||
| 20 | |||
| 21 | View Code Duplication | public function testInstanceOf() |
|
| 22 | { |
||
| 23 | $this->loadData(); |
||
| 24 | |||
| 25 | $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfTest\Person p |
||
| 26 | WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfTest\Person'; |
||
| 27 | $query = $this->_em->createQuery($dql); |
||
| 28 | $result = $query->getResult(); |
||
| 29 | |||
| 30 | $this->assertCount(2, $result); |
||
| 31 | |||
| 32 | foreach ($result as $r) { |
||
| 33 | $this->assertInstanceOf(Person::class, $r); |
||
| 34 | if ($r instanceof Employee) { |
||
| 35 | $this->assertEquals('bar', $r->getName()); |
||
| 36 | } else { |
||
| 37 | $this->assertEquals('foo', $r->getName()); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | private function loadData() |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 122 |