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 |
||
34 | class Update { |
||
35 | |||
36 | /** @var \OC\Files\View */ |
||
37 | protected $view; |
||
38 | |||
39 | /** @var \OC\Encryption\Util */ |
||
40 | protected $util; |
||
41 | |||
42 | /** @var \OC\Files\Mount\Manager */ |
||
43 | protected $mountManager; |
||
44 | |||
45 | /** @var \OC\Encryption\Manager */ |
||
46 | protected $encryptionManager; |
||
47 | |||
48 | /** @var string */ |
||
49 | protected $uid; |
||
50 | |||
51 | /** @var \OC\Encryption\File */ |
||
52 | protected $file; |
||
53 | |||
54 | /** |
||
55 | * |
||
56 | * @param \OC\Files\View $view |
||
57 | * @param \OC\Encryption\Util $util |
||
58 | * @param \OC\Files\Mount\Manager $mountManager |
||
59 | * @param \OC\Encryption\Manager $encryptionManager |
||
60 | * @param \OC\Encryption\File $file |
||
61 | * @param string $uid |
||
62 | */ |
||
63 | public function __construct( |
||
79 | |||
80 | /** |
||
81 | * hook after file was shared |
||
82 | * |
||
83 | * @param array $params |
||
84 | */ |
||
85 | View Code Duplication | public function postShared($params) { |
|
95 | |||
96 | /** |
||
97 | * hook after file was unshared |
||
98 | * |
||
99 | * @param array $params |
||
100 | */ |
||
101 | View Code Duplication | public function postUnshared($params) { |
|
111 | |||
112 | /** |
||
113 | * inform encryption module that a file was restored from the trash bin, |
||
114 | * e.g. to update the encryption keys |
||
115 | * |
||
116 | * @param array $params |
||
117 | */ |
||
118 | public function postRestore($params) { |
||
124 | |||
125 | /** |
||
126 | * inform encryption module that a file was renamed, |
||
127 | * e.g. to update the encryption keys |
||
128 | * |
||
129 | * @param array $params |
||
130 | */ |
||
131 | public function postRename($params) { |
||
143 | |||
144 | /** |
||
145 | * get owner and path relative to data/<owner>/files |
||
146 | * |
||
147 | * @param string $path path to file for current user |
||
148 | * @return array ['owner' => $owner, 'path' => $path] |
||
149 | * @throw \InvalidArgumentException |
||
150 | */ |
||
151 | protected function getOwnerPath($path) { |
||
162 | |||
163 | /** |
||
164 | * notify encryption module about added/removed users from a file/folder |
||
165 | * |
||
166 | * @param string $path relative to data/ |
||
167 | * @throws Exceptions\ModuleDoesNotExistsException |
||
168 | */ |
||
169 | public function update($path) { |
||
193 | |||
194 | } |
||
195 |
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.