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 |
||
| 6 | View Code Duplication | class xKerman_Restricted_ArrayHandler implements xKerman_Restricted_HandlerInterface |
|
| 7 | { |
||
| 8 | /** @var ParserInterface $expressionParser parser for unserialize expression */ |
||
| 9 | private $expressionParser; |
||
| 10 | /** @var integer */ |
||
| 11 | const CLOSE_BRACE_LENGTH = 1; |
||
| 12 | /** |
||
| 13 | * constructor |
||
| 14 | * |
||
| 15 | * @param ParserInterface $expressionParser parser for unserialize expression |
||
| 16 | */ |
||
| 17 | public function __construct(xKerman_Restricted_ParserInterface $expressionParser) |
||
| 21 | /** |
||
| 22 | * parse given `$source` as PHP serialized array |
||
| 23 | * |
||
| 24 | * @param Source $source parser input |
||
| 25 | * @param string $args array length |
||
| 26 | * @return array |
||
| 27 | * @throws UnserializeFailedException |
||
| 28 | */ |
||
| 29 | public function handle(xKerman_Restricted_Source $source, $args) |
||
| 41 | /** |
||
| 42 | * parse given `$source` as array key (s.t. integer|string) |
||
| 43 | * |
||
| 44 | * @param Source $source input |
||
| 45 | * @return array |
||
| 46 | * @throws UnserializeFailedException |
||
| 47 | */ |
||
| 48 | private function parseKey($source) |
||
| 56 | } |
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.