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 | class YandexDisk implements Sync\Simulator |
||
25 | { |
||
26 | use Cleanable; |
||
27 | /** |
||
28 | * API access token |
||
29 | * Goto https://oauth.yandex.ru/client/new |
||
30 | * create your app |
||
31 | * - Check all Disks permissions |
||
32 | * - generate access token: |
||
33 | * 1) Goto https://oauth.yandex.ru/authorize?response_type=token&client_id=APP_ID (replace APP_ID with ID giving to you) |
||
34 | * 2) Then you should get token parameter from GET-parameters of opened page |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $token; |
||
39 | |||
40 | /** |
||
41 | * Remote path |
||
42 | * |
||
43 | * @var \phpbu\App\Backup\Path |
||
44 | */ |
||
45 | protected $path; |
||
46 | |||
47 | /** |
||
48 | * @var Disk |
||
49 | */ |
||
50 | protected $disk; |
||
51 | |||
52 | /** |
||
53 | * Unix timestamp of generating path from placeholder. |
||
54 | * |
||
55 | * @var int |
||
56 | */ |
||
57 | protected $time; |
||
58 | |||
59 | /** |
||
60 | * (non-PHPDoc) |
||
61 | * |
||
62 | * @param array $config |
||
63 | * @throws Exception |
||
64 | * @throws \phpbu\App\Exception |
||
65 | * @see \phpbu\App\Backup\Sync::setup() |
||
66 | */ |
||
67 | 8 | public function setup(array $config): void |
|
83 | |||
84 | /** |
||
85 | * (non-PHPDoc) |
||
86 | * |
||
87 | * @param Target $target |
||
88 | * @param Result $result |
||
89 | * @throws Exception |
||
90 | * @see \phpbu\App\Backup\Sync::sync() |
||
91 | */ |
||
92 | 3 | public function sync(Target $target, Result $result): void |
|
117 | |||
118 | 3 | private function createFolders(): void |
|
134 | |||
135 | /** |
||
136 | * Simulate the sync execution. |
||
137 | * |
||
138 | * @param Target $target |
||
139 | * @param Result $result |
||
140 | */ |
||
141 | 2 | View Code Duplication | public function simulate(Target $target, Result $result): void |
148 | |||
149 | /** |
||
150 | * Creates the YandexDisk collector. |
||
151 | * |
||
152 | * @param Target $target |
||
153 | * @return Collector |
||
154 | */ |
||
155 | 1 | protected function createCollector(Target $target): Collector |
|
162 | |||
163 | /** |
||
164 | * Create a YandexDisk api client. |
||
165 | * |
||
166 | * @return Disk |
||
167 | */ |
||
168 | protected function createDisk(): Disk |
||
175 | } |
||
176 |