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  | 
            ||
| 17 | class Database  | 
            ||
| 18 | { | 
            ||
| 19 | /**  | 
            ||
| 20 | * @var DatabaseContainer  | 
            ||
| 21 | */  | 
            ||
| 22 | protected $container;  | 
            ||
| 23 | |||
| 24 | /**  | 
            ||
| 25 | * @param DatabaseContainer $container  | 
            ||
| 26 | */  | 
            ||
| 27 | 1 | public function __construct(DatabaseContainer $container)  | 
            |
| 31 | |||
| 32 | /**  | 
            ||
| 33 | * @param string Schema class-name  | 
            ||
| 34 | *  | 
            ||
| 35 | * @return Schema  | 
            ||
| 36 | */  | 
            ||
| 37 | 1 | View Code Duplication | public function getSchema($schema)  | 
            
| 53 | |||
| 54 | /**  | 
            ||
| 55 | * @param Table $from  | 
            ||
| 56 | *  | 
            ||
| 57 | * @return SelectQuery  | 
            ||
| 58 | */  | 
            ||
| 59 | 1 | public function select(Table $from)  | 
            |
| 63 | |||
| 64 | /**  | 
            ||
| 65 | * @param Table $into  | 
            ||
| 66 | * @param mixed[]|mixed[][]|null $record optional record map (or list of record maps) where Column name => value  | 
            ||
| 67 | *  | 
            ||
| 68 | * @return InsertQuery  | 
            ||
| 69 | */  | 
            ||
| 70 | 1 | public function insert(Table $into, $record = null)  | 
            |
| 74 | |||
| 75 | /**  | 
            ||
| 76 | * @param Table $table  | 
            ||
| 77 | *  | 
            ||
| 78 | * @return UpdateQuery  | 
            ||
| 79 | */  | 
            ||
| 80 | 1 | public function update(Table $table)  | 
            |
| 84 | |||
| 85 | /**  | 
            ||
| 86 | * @param Table $table  | 
            ||
| 87 | *  | 
            ||
| 88 | * @return DeleteQuery  | 
            ||
| 89 | */  | 
            ||
| 90 | 1 | public function delete(Table $table)  | 
            |
| 94 | |||
| 95 | /**  | 
            ||
| 96 | * @param string $sql  | 
            ||
| 97 | *  | 
            ||
| 98 | * @return SQLQuery  | 
            ||
| 99 | */  | 
            ||
| 100 | 1 | public function sql($sql)  | 
            |
| 104 | }  | 
            ||
| 105 | 
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.