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 |
||
13 | abstract class Component implements ComponentInterface |
||
14 | { |
||
15 | use HasEvents, HasPermission; |
||
16 | |||
17 | protected $app; |
||
18 | |||
19 | protected $title; |
||
20 | |||
21 | protected $booted = false; |
||
22 | |||
23 | /** |
||
24 | * @var \Illuminate\Contracts\Events\Dispatcher |
||
25 | */ |
||
26 | protected static $dispatcher; |
||
27 | |||
28 | public function __construct(Application $app) |
||
34 | |||
35 | public function getTitle() |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | View Code Duplication | public function getConfigs() |
|
53 | |||
54 | /** |
||
55 | * @return \KodiComponents\Navigation\Contracts\NavigationInterface |
||
56 | */ |
||
57 | public function getNavigation() |
||
61 | |||
62 | /** |
||
63 | * 添加菜单 |
||
64 | * |
||
65 | * @param int $priority |
||
66 | * @param null $badge |
||
67 | * |
||
68 | * @return \Sco\Admin\Navigation\Page |
||
69 | */ |
||
70 | public function addToNavigation($priority = 100, $badge = null) |
||
76 | |||
77 | /** |
||
78 | * page |
||
79 | * |
||
80 | * @param int $priority |
||
81 | * @param null $badge |
||
82 | * |
||
83 | * @return \Sco\Admin\Navigation\Page |
||
84 | */ |
||
85 | protected function makePage($priority = 100, $badge = null) |
||
98 | |||
99 | protected function bootIfNotBooted() |
||
115 | |||
116 | public function boot() |
||
119 | |||
120 | /** |
||
121 | * Boot all of the bootable traits on the model. |
||
122 | * |
||
123 | * @return void |
||
124 | */ |
||
125 | protected function bootTraits() |
||
135 | } |
||
136 |
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.