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  | 
            ||
| 21 | abstract class AbstractDataCoupler implements DataCouplerInterface  | 
            ||
| 22 | { | 
            ||
| 23 | /** @var DataAdapterInterface */  | 
            ||
| 24 | private $defaultAdapter;  | 
            ||
| 25 | /** @var array<DataEntityInterface> */  | 
            ||
| 26 | protected $dataEntityPrototypes = [];  | 
            ||
| 27 | /** @var string */  | 
            ||
| 28 | protected $connectorIdKey;  | 
            ||
| 29 | /** @var string */  | 
            ||
| 30 | protected $connectorDataGroup;  | 
            ||
| 31 | /** @var array */  | 
            ||
| 32 | protected $dependentDataGroups;  | 
            ||
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * DataCouplerInterface constructor.  | 
            ||
| 36 | *  | 
            ||
| 37 | * @param DataAdapterInterface $defaultAdapter  | 
            ||
| 38 | * @param DataEntityInterface[] ...$dataEntityPrototypes  | 
            ||
| 39 | */  | 
            ||
| 40 | final public function __construct(  | 
            ||
| 50 | |||
| 51 | /**  | 
            ||
| 52 | * Returns the DataAdapter instance.  | 
            ||
| 53 | *  | 
            ||
| 54 | * @return DataAdapterInterface  | 
            ||
| 55 | */  | 
            ||
| 56 | final public function getDataAdapter()  | 
            ||
| 60 | |||
| 61 | /**  | 
            ||
| 62 | * Gets all the entities those are depending from the given entity.  | 
            ||
| 63 | *  | 
            ||
| 64 | * @param DataEntityInterface $entity  | 
            ||
| 65 | * @return array<DataEntityInterface>  | 
            ||
| 66 | */  | 
            ||
| 67 | abstract public function getEntityDependencies(DataEntityInterface $entity);  | 
            ||
| 68 | |||
| 69 | /**  | 
            ||
| 70 | * Returns a new instance of the required entity.  | 
            ||
| 71 | *  | 
            ||
| 72 | * @param string $entityClassName  | 
            ||
| 73 | * @throws RuntimeException  | 
            ||
| 74 | * @return DataEntityInterface  | 
            ||
| 75 | */  | 
            ||
| 76 | View Code Duplication | protected function getNewEntityInstance($entityClassName)  | 
            |
| 84 | |||
| 85 | /**  | 
            ||
| 86 | * Gets raw depending entity data list for the given entity.  | 
            ||
| 87 | *  | 
            ||
| 88 | * @param DataEntityInterface $entity  | 
            ||
| 89 | * @return array  | 
            ||
| 90 | */  | 
            ||
| 91 | protected function getEntityDataSet(DataEntityInterface $entity)  | 
            ||
| 119 | }  | 
            ||
| 120 | 
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.