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 StoreManager |
||
| 25 | { |
||
| 26 | const AUDIT_HEADER_KEY = 'x-header-audit-thread'; |
||
| 27 | |||
| 28 | /** @var ActivityManager */ |
||
| 29 | private $activityManager; |
||
| 30 | |||
| 31 | /** @var DocumentManager */ |
||
| 32 | private $documentManager; |
||
| 33 | |||
| 34 | /** @var SecurityUser */ |
||
| 35 | private $securityUser; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * StoreManager constructor. |
||
| 39 | * @param ActivityManager $activityManager Main activity manager |
||
| 40 | * @param ManagerRegistry $doctrine Doctrine document mapper |
||
| 41 | * @param TokenStorage $tokenStorage Sf Auth token storage |
||
| 42 | */ |
||
| 43 | public function __construct( |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Save data to DB |
||
| 55 | * onKernelResponse |
||
| 56 | * |
||
| 57 | * @param FilterResponseEvent $event Sf fired kernel event |
||
| 58 | * |
||
| 59 | * @return void |
||
| 60 | */ |
||
| 61 | public function persistEvents(FilterResponseEvent $event) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Save the event to DB |
||
| 89 | * |
||
| 90 | * @param AuditTracking $event Performed by user |
||
| 91 | * @param string $thread The thread ID |
||
| 92 | * @param string $username User connected name |
||
| 93 | * @return void |
||
| 94 | */ |
||
| 95 | private function trackEvent($event, $thread, $username) |
||
| 108 | |||
| 109 | |||
| 110 | |||
| 111 | /** |
||
| 112 | * Generate a unique identifer |
||
| 113 | * |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | private function generateUUID() |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Find current user |
||
| 130 | * |
||
| 131 | * @return string|bool |
||
|
|
|||
| 132 | */ |
||
| 133 | View Code Duplication | private function getSecurityUser() |
|
| 142 | |||
| 143 | /** |
||
| 144 | * Last check before saving the Event into DB |
||
| 145 | * |
||
| 146 | * @return bool|string |
||
| 147 | */ |
||
| 148 | public function getSecurityUsername() |
||
| 164 | } |
||
| 165 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.