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 |
||
11 | class SyncData extends Command |
||
12 | { |
||
13 | use Traits\SyncTrait; |
||
14 | |||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | */ |
||
18 | protected $signature = 'contentful:sync-data {--preview}'; |
||
19 | |||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | protected $description = 'Synchronize Contentful entries and assets'; |
||
24 | |||
25 | /** |
||
26 | * Contentful Sync API implementation. |
||
27 | * |
||
28 | * @var \Distilleries\Contentful\Api\SyncApi |
||
29 | */ |
||
30 | protected $api; |
||
31 | |||
32 | /** |
||
33 | * SyncData command constructor. |
||
34 | * |
||
35 | * @param \Distilleries\Contentful\Api\SyncApi $api |
||
36 | * @return void |
||
|
|||
37 | */ |
||
38 | public function __construct(SyncApi $api) |
||
44 | |||
45 | /** |
||
46 | * Execute the console command. |
||
47 | * |
||
48 | * @return void |
||
49 | */ |
||
50 | public function handle(Release $release) |
||
66 | |||
67 | |||
68 | protected function setNewRelease(Release $release) |
||
75 | |||
76 | /** |
||
77 | * Synchronize assets via Sync API and store into DB for further use. |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | View Code Duplication | protected function syncAssets() |
|
93 | |||
94 | /** |
||
95 | * Save given Contentful assets. |
||
96 | * |
||
97 | * @param array $assets |
||
98 | * @return void |
||
99 | */ |
||
100 | protected function saveAssets(array $assets) |
||
112 | |||
113 | /** |
||
114 | * Synchronize entries via Sync API and store into DB for further use. |
||
115 | * |
||
116 | * @return void |
||
117 | */ |
||
118 | View Code Duplication | protected function syncEntries() |
|
130 | |||
131 | /** |
||
132 | * Save given Contentful entries. |
||
133 | * |
||
134 | * @param array $entries |
||
135 | * @return void |
||
136 | */ |
||
137 | protected function saveEntries(array $entries) |
||
149 | } |
||
150 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.