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 namespace jlourenco\blog\Repositories; |
||
5 | View Code Duplication | class BlogPostRepository implements BlogPostRepositoryInterface |
|
|
|||
6 | { |
||
7 | use RepositoryTrait; |
||
8 | |||
9 | /** |
||
10 | * The Blog post model name. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $model = 'jlourenco\blog\Models\BlogPost'; |
||
15 | |||
16 | /** |
||
17 | * Create a new blog post repository. |
||
18 | * |
||
19 | * @param string $model |
||
20 | */ |
||
21 | public function __construct($model = null) |
||
26 | |||
27 | /** |
||
28 | * {@inheritDoc} |
||
29 | */ |
||
30 | public function findById($id) |
||
37 | |||
38 | /** |
||
39 | * {@inheritDoc} |
||
40 | */ |
||
41 | public function findByTitle($title) |
||
49 | |||
50 | } |
||
51 |
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.