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 |
||
| 23 | abstract class AbstractRoutesFactory |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var ObjectManager The object manager to be used for determining the repository |
||
| 27 | */ |
||
| 28 | protected $objectManager; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * RoutesFactory constructor. |
||
| 32 | * |
||
| 33 | * @param ObjectManager $objectManager The object manager to be used for determining the repositories |
||
| 34 | */ |
||
| 35 | public function __construct(ObjectManager $objectManager) |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Returns a repository for a given object type. |
||
| 42 | * |
||
| 43 | * @param string $objectType Name of desired entity type |
||
| 44 | * |
||
| 45 | * @return EntityRepository The repository responsible for the given object type |
||
| 46 | */ |
||
| 47 | public function getRepository($objectType) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Creates a new route instance. |
||
| 56 | * |
||
| 57 | * @return Zikula\RoutesModule\Entity\routeEntity The newly created entity instance |
||
| 58 | */ |
||
| 59 | public function createRoute() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Gets the list of identifier fields for a given object type. |
||
| 68 | * |
||
| 69 | * @param string $objectType The object type to be treated |
||
| 70 | * |
||
| 71 | * @return array List of identifier field names |
||
| 72 | */ |
||
| 73 | View Code Duplication | public function getIdFields($objectType = '') |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Checks whether a certain entity type uses composite keys or not. |
||
| 93 | * |
||
| 94 | * @param string $objectType The object type to retrieve |
||
| 95 | * |
||
| 96 | * @return Boolean Whether composite keys are used or not |
||
| 97 | */ |
||
| 98 | public function hasCompositeKeys($objectType) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Returns the object manager. |
||
| 105 | * |
||
| 106 | * @return ObjectManager |
||
| 107 | */ |
||
| 108 | public function getObjectManager() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Sets the object manager. |
||
| 115 | * |
||
| 116 | * @param ObjectManager $objectManager |
||
| 117 | * |
||
| 118 | * @return void |
||
| 119 | */ |
||
| 120 | public function setObjectManager($objectManager) |
||
| 124 | |||
| 125 | } |
||
| 126 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.