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 |
||
24 | View Code Duplication | class Blobs extends AbstractPackage |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * Get a Blob. |
||
28 | * |
||
29 | * @param string $owner Repository owner. |
||
30 | * @param string $repo Repository name. |
||
31 | * @param string $sha The commit SHA. |
||
32 | * |
||
33 | * @return object |
||
34 | * |
||
35 | * @since 1.0 |
||
36 | */ |
||
37 | public function get($owner, $repo, $sha) |
||
46 | |||
47 | /** |
||
48 | * Create a Blob. |
||
49 | * |
||
50 | * @param string $owner Repository owner. |
||
51 | * @param string $repo Repository name. |
||
52 | * @param string $content The content of the blob. |
||
53 | * @param string $encoding The encoding to use. |
||
54 | * |
||
55 | * @return object |
||
56 | * |
||
57 | * @since 1.0 |
||
58 | */ |
||
59 | public function create($owner, $repo, $content, $encoding = 'utf-8') |
||
74 | } |
||
75 |
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.