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  | 
            ||
| 63 | class CirclesManager { | 
            ||
| 64 | |||
| 65 | |||
| 66 | /** @var IUserSession */  | 
            ||
| 67 | private $userSession;  | 
            ||
| 68 | |||
| 69 | /** @var CirclesQueryHelper */  | 
            ||
| 70 | private $circlesQueryHelper;  | 
            ||
| 71 | |||
| 72 | /** @var FederatedUserService */  | 
            ||
| 73 | private $federatedUserService;  | 
            ||
| 74 | |||
| 75 | /** @var CircleService */  | 
            ||
| 76 | private $circleService;  | 
            ||
| 77 | |||
| 78 | /** @var MemberService */  | 
            ||
| 79 | private $memberService;  | 
            ||
| 80 | |||
| 81 | |||
| 82 | /**  | 
            ||
| 83 | * CirclesManager constructor.  | 
            ||
| 84 | *  | 
            ||
| 85 | * @param IUserSession $userSession  | 
            ||
| 86 | * @param FederatedUserService $federatedUserService  | 
            ||
| 87 | * @param CircleService $circleService  | 
            ||
| 88 | * @param MemberService $memberService  | 
            ||
| 89 | * @param CirclesQueryHelper $circlesQueryHelper  | 
            ||
| 90 | */  | 
            ||
| 91 | View Code Duplication | public function __construct(  | 
            |
| 104 | |||
| 105 | |||
| 106 | /**  | 
            ||
| 107 | * WIP  | 
            ||
| 108 | *  | 
            ||
| 109 | * @return Circle  | 
            ||
| 110 | */  | 
            ||
| 111 | //	public function create(): Circle { | 
            ||
| 112 | // }  | 
            ||
| 113 | |||
| 114 | |||
| 115 | /**  | 
            ||
| 116 | * WIP  | 
            ||
| 117 | *  | 
            ||
| 118 | * returns Circles available to Current User  | 
            ||
| 119 | *  | 
            ||
| 120 | * @return Circle[]  | 
            ||
| 121 | * @throws InitiatorNotFoundException  | 
            ||
| 122 | * @throws FederatedUserException  | 
            ||
| 123 | * @throws FederatedUserNotFoundException  | 
            ||
| 124 | * @throws InvalidIdException  | 
            ||
| 125 | * @throws RequestBuilderException  | 
            ||
| 126 | * @throws SingleCircleNotFoundException  | 
            ||
| 127 | */  | 
            ||
| 128 | //	public function getCircles(bool $asMember = false): array { | 
            ||
| 129 | // $this->federatedUserService->initCurrentUser();  | 
            ||
| 130 | // $this->circleService->getCircles();  | 
            ||
| 131 | // }  | 
            ||
| 132 | |||
| 133 | |||
| 134 | /**  | 
            ||
| 135 | * WIP  | 
            ||
| 136 | *  | 
            ||
| 137 | * @return Circle[]  | 
            ||
| 138 | * @throws InitiatorNotFoundException  | 
            ||
| 139 | * @throws RequestBuilderException  | 
            ||
| 140 | */  | 
            ||
| 141 | //	public function getAllCircles(): array { | 
            ||
| 142 | // $this->federatedUserService->bypassCurrentUserCondition(true);  | 
            ||
| 143 | // $this->circleService->getCircles();  | 
            ||
| 144 | // }  | 
            ||
| 145 | |||
| 146 | |||
| 147 | /**  | 
            ||
| 148 | * WIP  | 
            ||
| 149 | *  | 
            ||
| 150 | * @param string $singleId  | 
            ||
| 151 | *  | 
            ||
| 152 | * @return Circle  | 
            ||
| 153 | */  | 
            ||
| 154 | //	public function getCircle(string $singleId): Circle { | 
            ||
| 155 | //  | 
            ||
| 156 | // }  | 
            ||
| 157 | |||
| 158 | |||
| 159 | /**  | 
            ||
| 160 | * WIP  | 
            ||
| 161 | *  | 
            ||
| 162 | * @param string $circleId  | 
            ||
| 163 | * @param string $singleId  | 
            ||
| 164 | *  | 
            ||
| 165 | * @return Member  | 
            ||
| 166 | * @throws InitiatorNotFoundException  | 
            ||
| 167 | * @throws MemberNotFoundException  | 
            ||
| 168 | * @throws RequestBuilderException  | 
            ||
| 169 | */  | 
            ||
| 170 | //	public function getMember(string $circleId, string $singleId): Member { | 
            ||
| 171 | // $this->federatedUserService->bypassCurrentUserCondition(true);  | 
            ||
| 172 | // $this->memberService->getMemberById($circleId, $singleId);  | 
            ||
| 173 | // }  | 
            ||
| 174 | |||
| 175 | |||
| 176 | /**  | 
            ||
| 177 | * WIP  | 
            ||
| 178 | *  | 
            ||
| 179 | * @param string $memberId  | 
            ||
| 180 | *  | 
            ||
| 181 | * @return Member  | 
            ||
| 182 | */  | 
            ||
| 183 | //	public function getMemberById(string $memberId): Member { | 
            ||
| 184 | // }  | 
            ||
| 185 | |||
| 186 | |||
| 187 | /**  | 
            ||
| 188 | * @return IFederatedUser  | 
            ||
| 189 | * @throws FederatedUserException  | 
            ||
| 190 | * @throws FederatedUserNotFoundException  | 
            ||
| 191 | * @throws InvalidIdException  | 
            ||
| 192 | * @throws RequestBuilderException  | 
            ||
| 193 | * @throws SingleCircleNotFoundException  | 
            ||
| 194 | */  | 
            ||
| 195 | 	public function getCurrentFederatedUser(): IFederatedUser { | 
            ||
| 203 | |||
| 204 | |||
| 205 | /**  | 
            ||
| 206 | * @param string $federatedId  | 
            ||
| 207 | * @param int $type  | 
            ||
| 208 | *  | 
            ||
| 209 | * @return IFederatedUser  | 
            ||
| 210 | * @throws CircleNotFoundException  | 
            ||
| 211 | * @throws FederatedItemException  | 
            ||
| 212 | * @throws FederatedUserException  | 
            ||
| 213 | * @throws FederatedUserNotFoundException  | 
            ||
| 214 | * @throws InvalidIdException  | 
            ||
| 215 | * @throws MemberNotFoundException  | 
            ||
| 216 | * @throws OwnerNotFoundException  | 
            ||
| 217 | * @throws RemoteInstanceException  | 
            ||
| 218 | * @throws RemoteNotFoundException  | 
            ||
| 219 | * @throws RemoteResourceNotFoundException  | 
            ||
| 220 | * @throws RequestBuilderException  | 
            ||
| 221 | * @throws SingleCircleNotFoundException  | 
            ||
| 222 | * @throws UnknownRemoteException  | 
            ||
| 223 | * @throws UserTypeNotFoundException  | 
            ||
| 224 | */  | 
            ||
| 225 | 	public function getFederatedUser(string $federatedId, int $type = Member::TYPE_SINGLE): IFederatedUser { | 
            ||
| 228 | |||
| 229 | |||
| 230 | /**  | 
            ||
| 231 | * @return CirclesQueryHelper  | 
            ||
| 232 | */  | 
            ||
| 233 | 	public function getQueryHelper(): CirclesQueryHelper { | 
            ||
| 236 | |||
| 237 | |||
| 238 | /**  | 
            ||
| 239 | * @param array $data  | 
            ||
| 240 | * @param string $prefix  | 
            ||
| 241 | *  | 
            ||
| 242 | * @return Circle  | 
            ||
| 243 | * @throws CircleNotFoundException  | 
            ||
| 244 | */  | 
            ||
| 245 | 	public function extractCircle(array $data, string $prefix = ''): Circle { | 
            ||
| 251 | |||
| 252 | }  | 
            ||
| 253 | |||
| 254 | 
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.