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 |
||
| 18 | class KeyPic |
||
| 19 | { |
||
| 20 | |||
| 21 | /*@var RequestInterface $request */ |
||
| 22 | private $request; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * keypic API version number |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $version; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * keypic API user agent text |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | private $UserAgent; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * keypic webservice host |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | private $host; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * keypic formID, unique for each client |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | private $FormID; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * keypic publisher ID |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | private $PublisherID; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Token generated from keypic API |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | private $Token; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * debug flag |
||
| 62 | * @var boolean |
||
| 63 | */ |
||
| 64 | private $Debug; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * name of token field hidden input |
||
| 68 | * @var string |
||
| 69 | */ |
||
| 70 | private $TokenInputName; |
||
| 71 | |||
| 72 | |||
| 73 | /** |
||
| 74 | * constructor with injecting psr-7 request in the object |
||
| 75 | * @param ServerRequestInterface $request |
||
| 76 | */ |
||
| 77 | public function __construct(ServerRequestInterface $request, $vesion = '2.1') |
||
| 84 | |||
| 85 | /** |
||
| 86 | * set API host value |
||
| 87 | * @param string $host |
||
| 88 | * @return \Zrashwani\KeyPic\KeyPic |
||
| 89 | */ |
||
| 90 | public function setHost($host) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * set keypic api version |
||
| 99 | * @param string $version |
||
| 100 | * @return \Zrashwani\KeyPic\KeyPic |
||
| 101 | */ |
||
| 102 | public function setVersion($version) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * set user agent |
||
| 111 | * @param string $UserAgent |
||
| 112 | * @return \Zrashwani\KeyPic\KeyPic |
||
| 113 | */ |
||
| 114 | public function setUserAgent($UserAgent) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * set keypic formId value |
||
| 123 | * @param string $FormID |
||
| 124 | * @return \Zrashwani\KeyPic\KeyPic |
||
| 125 | */ |
||
| 126 | public function setFormID($FormID) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * set publisher Id value |
||
| 135 | * @param string $PublisherID |
||
| 136 | * @return \Zrashwani\KeyPic\KeyPic |
||
| 137 | */ |
||
| 138 | public function setPublisherID($PublisherID) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * set Debug value |
||
| 147 | * @param boolean $Debug |
||
| 148 | * @return \Zrashwani\KeyPic\KeyPic |
||
| 149 | */ |
||
| 150 | public function setDebug($Debug) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * get token hidden input name |
||
| 159 | * @return string |
||
| 160 | */ |
||
| 161 | public function getTokenInputName() |
||
| 165 | |||
| 166 | /** |
||
| 167 | * set token input hidden field name |
||
| 168 | * @param string $tokenInputName |
||
| 169 | * @return \Zrashwani\KeyPic\KeyPic |
||
| 170 | */ |
||
| 171 | public function setTokenInputName($tokenInputName) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * check keypic formID if valid |
||
| 180 | * @param String $FormID |
||
| 181 | * @return boolean |
||
| 182 | */ |
||
| 183 | public function checkFormID($FormID) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * requesting new token or getting its value if it is already generated |
||
| 199 | * @param String $Token |
||
| 200 | * @param String $ClientEmailAddress |
||
| 201 | * @param String $ClientUsername |
||
| 202 | * @param String $ClientMessage |
||
| 203 | * @param String $ClientFingerprint |
||
| 204 | * @param int $Quantity |
||
| 205 | * @return boolean |
||
| 206 | */ |
||
| 207 | public function getToken( |
||
| 240 | |||
| 241 | /** |
||
| 242 | * get keypic token hidden field text |
||
| 243 | * @return boolean|string |
||
| 244 | */ |
||
| 245 | public function getTokenInput() |
||
| 252 | |||
| 253 | /** |
||
| 254 | * print keypic token into form as pixel image or script |
||
| 255 | * @param string $RequestType |
||
| 256 | * @param string $WidthHeight |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | public function getIt($RequestType = 'getScript', $WidthHeight = '336x280') |
||
| 289 | |||
| 290 | /** |
||
| 291 | * render necessary keypic input and script to use in html form |
||
| 292 | * @param string $RequestType |
||
| 293 | * @param string $WidthHeight |
||
| 294 | * @return String |
||
| 295 | */ |
||
| 296 | public function renderHtml($RequestType = 'getScript', $WidthHeight = '336x280') |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Detect if entry is Spam? from 0% to 100% |
||
| 303 | * @param string $ClientEmailAddress |
||
| 304 | * @param string $ClientUsername |
||
| 305 | * @param string $ClientMessage |
||
| 306 | * @param string $ClientFingerprint |
||
| 307 | * @throw \Exception |
||
| 308 | * @return array |
||
| 309 | * |
||
| 310 | */ |
||
| 311 | public function isSpam( |
||
| 340 | |||
| 341 | /** |
||
| 342 | * sending reportSpam method to keypic webservice |
||
| 343 | * @return boolean|array |
||
| 344 | */ |
||
| 345 | public function reportSpam() |
||
| 367 | |||
| 368 | /** |
||
| 369 | * sending spam detection request to keypic servers |
||
| 370 | * @param array $fields |
||
| 371 | * @return boolean|array |
||
| 372 | */ |
||
| 373 | private function sendRequest(array $fields) |
||
| 393 | |||
| 394 | /** |
||
| 395 | * getting fields used in webservice for requesting and validating keypic token |
||
| 396 | * @param String $RequestType |
||
| 397 | * @param String $ClientUsername |
||
| 398 | * @param String $ClientEmailAddress |
||
| 399 | * @param String $ClientMessage |
||
| 400 | * @param String $ClientFingerprint |
||
| 401 | * @param int $Quantity |
||
| 402 | * @return array |
||
| 403 | */ |
||
| 404 | protected function getWebServiceFields( |
||
| 435 | } |
||
| 436 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..