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 |
||
| 47 | class OCSAuthAPIController extends OCSController{ |
||
| 48 | |||
| 49 | /** @var ISecureRandom */ |
||
| 50 | private $secureRandom; |
||
| 51 | |||
| 52 | /** @var IJobList */ |
||
| 53 | private $jobList; |
||
| 54 | |||
| 55 | /** @var TrustedServers */ |
||
| 56 | private $trustedServers; |
||
| 57 | |||
| 58 | /** @var DbHandler */ |
||
| 59 | private $dbHandler; |
||
| 60 | |||
| 61 | /** @var ILogger */ |
||
| 62 | private $logger; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * OCSAuthAPI constructor. |
||
| 66 | * |
||
| 67 | * @param string $appName |
||
| 68 | * @param IRequest $request |
||
| 69 | * @param ISecureRandom $secureRandom |
||
| 70 | * @param IJobList $jobList |
||
| 71 | * @param TrustedServers $trustedServers |
||
| 72 | * @param DbHandler $dbHandler |
||
| 73 | * @param ILogger $logger |
||
| 74 | */ |
||
| 75 | public function __construct( |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @NoCSRFRequired |
||
| 95 | * @PublicPage |
||
| 96 | * |
||
| 97 | * request received to ask remote server for a shared secret, for legacy end-points |
||
| 98 | * |
||
| 99 | * @param string $url |
||
| 100 | * @param string $token |
||
| 101 | * @return Http\DataResponse |
||
| 102 | * @throws OCSForbiddenException |
||
| 103 | */ |
||
| 104 | public function requestSharedSecretLegacy($url, $token) { |
||
| 105 | return $this->requestSharedSecret($url, $token); |
||
| 106 | } |
||
| 107 | |||
| 108 | |||
| 109 | /** |
||
| 110 | * @NoCSRFRequired |
||
| 111 | * @PublicPage |
||
| 112 | * |
||
| 113 | * create shared secret and return it, for legacy end-points |
||
| 114 | * |
||
| 115 | * @param string $url |
||
| 116 | * @param string $token |
||
| 117 | * @return Http\DataResponse |
||
| 118 | * @throws OCSForbiddenException |
||
| 119 | */ |
||
| 120 | public function getSharedSecretLegacy($url, $token) { |
||
| 121 | return $this->getSharedSecret($url, $token); |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @NoCSRFRequired |
||
| 126 | * @PublicPage |
||
| 127 | * |
||
| 128 | * request received to ask remote server for a shared secret |
||
| 129 | * |
||
| 130 | * @param string $url |
||
| 131 | * @param string $token |
||
| 132 | * @return Http\DataResponse |
||
| 133 | * @throws OCSForbiddenException |
||
| 134 | */ |
||
| 135 | public function requestSharedSecret($url, $token) { |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @NoCSRFRequired |
||
| 174 | * @PublicPage |
||
| 175 | * |
||
| 176 | * create shared secret and return it |
||
| 177 | * |
||
| 178 | * @param string $url |
||
| 179 | * @param string $token |
||
| 180 | * @return Http\DataResponse |
||
| 181 | * @throws OCSForbiddenException |
||
| 182 | */ |
||
| 183 | public function getSharedSecret($url, $token) { |
||
| 208 | |||
| 209 | protected function isValidToken($url, $token) { |
||
| 213 | |||
| 214 | } |
||
| 215 |