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 namespace Limoncello\Crypt; |
||
| 24 | abstract class BaseAsymmetricCrypt extends BaseCrypt |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var resource|null |
||
| 28 | */ |
||
| 29 | private $key = null; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var int|null |
||
| 33 | */ |
||
| 34 | private $keyBytes = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Destructor. |
||
| 38 | */ |
||
| 39 | 3 | public function __destruct() |
|
| 43 | |||
| 44 | /** |
||
| 45 | * @return $this |
||
| 46 | */ |
||
| 47 | 3 | public function closeKey() |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @return resource|null |
||
| 60 | */ |
||
| 61 | 3 | protected function getKey() |
|
| 65 | |||
| 66 | /** |
||
| 67 | * @param resource $key |
||
| 68 | * |
||
| 69 | * @return $this |
||
| 70 | */ |
||
| 71 | 3 | protected function setKey($key) |
|
| 80 | |||
| 81 | /** |
||
| 82 | * @return int|null |
||
|
|
|||
| 83 | */ |
||
| 84 | 3 | protected function getKeyBytes() |
|
| 95 | |||
| 96 | /** |
||
| 97 | * @return int|null |
||
| 98 | */ |
||
| 99 | 3 | View Code Duplication | protected function getEncryptChunkSize() |
| 108 | |||
| 109 | /** |
||
| 110 | * @return int|null |
||
| 111 | */ |
||
| 112 | 3 | View Code Duplication | protected function getDecryptChunkSize() |
| 119 | |||
| 120 | /** |
||
| 121 | * @param string $value |
||
| 122 | * @param int $maxSize |
||
| 123 | * |
||
| 124 | * @return Generator |
||
| 125 | */ |
||
| 126 | 3 | protected function chunkString($value, $maxSize) |
|
| 144 | } |
||
| 145 |
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.