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 |
||
| 7 | class Sync_User_Hooks extends Abstract_Sync_Hooks { |
||
| 8 | /** |
||
| 9 | * @var \Wordlift_Log_Service |
||
| 10 | */ |
||
| 11 | private $log; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var Sync_Service |
||
| 15 | */ |
||
| 16 | private $sync_service; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Sync_User_Hooks constructor. |
||
| 20 | * |
||
| 21 | * @param Sync_Service $sync_service |
||
| 22 | */ |
||
| 23 | View Code Duplication | function __construct( Sync_Service $sync_service ) { |
|
| 33 | |||
| 34 | private function register_hooks() { |
||
| 46 | |||
| 47 | public function changed_user( $user_id ) { |
||
| 52 | |||
| 53 | public function changed_user_meta( $meta_id, $user_id, $meta_key ) { |
||
| 75 | |||
| 76 | private function sync( $user_id ) { |
||
| 79 | |||
| 80 | View Code Duplication | public function do_sync( $user_id ) { |
|
| 89 | |||
| 90 | public function delete_user( $user_id ) { |
||
| 93 | |||
| 94 | View Code Duplication | public function do_delete( $user_id ) { |
|
| 102 | |||
| 103 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.