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 |
||
| 22 | class UUIDEntityTest extends UnitTestCase |
||
| 23 | { |
||
| 24 | //<editor-fold desc="Public Methods"> |
||
| 25 | /** |
||
| 26 | * @covers \Tfboe\FmLib\Entity\Helpers\UUIDEntity::getId |
||
| 27 | * @uses \Tfboe\FmLib\Entity\Helpers\IdGenerator::createIdFrom |
||
| 28 | */ |
||
| 29 | public function testId() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @covers \Tfboe\FmLib\Entity\Helpers\UUIDEntity::getEntityId |
||
| 39 | * @uses \Tfboe\FmLib\Entity\Helpers\IdGenerator::createIdFrom |
||
| 40 | */ |
||
| 41 | View Code Duplication | public function testEntityId() |
|
| 48 | //</editor-fold desc="Public Methods"> |
||
| 49 | |||
| 50 | //<editor-fold desc="Private Methods"> |
||
| 51 | /** |
||
| 52 | * @return MockObject|UUIDEntity |
||
| 53 | */ |
||
| 54 | private function mock(): MockObject |
||
| 58 | //</editor-fold desc="Private Methods"> |
||
| 59 | } |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: