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  | 
            ||
| 7 | class SpecPriceRepository extends Repository  | 
            ||
| 8 | { | 
            ||
| 9 | /**  | 
            ||
| 10 | * @return SpecPrice  | 
            ||
| 11 | */  | 
            ||
| 12 | public function getModel()  | 
            ||
| 16 | |||
| 17 | /**  | 
            ||
| 18 | * @param $product_id  | 
            ||
| 19 | * @return static  | 
            ||
| 20 | */  | 
            ||
| 21 | public function createPlain($product_id)  | 
            ||
| 28 | |||
| 29 | /**  | 
            ||
| 30 | * Find model by id/slug.  | 
            ||
| 31 | *  | 
            ||
| 32 | * @param $id  | 
            ||
| 33 | * @return SpecPrice  | 
            ||
| 34 | */  | 
            ||
| 35 | public function find($id)  | 
            ||
| 41 | |||
| 42 | public function findKey($key)  | 
            ||
| 48 | |||
| 49 | /**  | 
            ||
| 50 | * Delete model..  | 
            ||
| 51 | *  | 
            ||
| 52 | * @param SpecPrice $model  | 
            ||
| 53 | */  | 
            ||
| 54 | /* public function delete(SpecPrice $model)  | 
            ||
| 55 |     { | 
            ||
| 56 | $model->delete();  | 
            ||
| 57 | }*/  | 
            ||
| 58 | public function delete($id)  | 
            ||
| 62 | |||
| 63 | /**  | 
            ||
| 64 | * Update suite of improved specs.  | 
            ||
| 65 | *  | 
            ||
| 66 | * @param $spec  | 
            ||
| 67 | * @param array $data  | 
            ||
| 68 | * @return mixed  | 
            ||
| 69 | */  | 
            ||
| 70 | |||
| 71 | public function create(array $data, $product)  | 
            ||
| 83 | |||
| 84 | public function save(array $data, $product)  | 
            ||
| 98 | |||
| 99 | View Code Duplication | public function update($spec, array $data)  | 
            |
| 111 | }  | 
            
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: