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 |
||
21 | View Code Duplication | class ValidatorChain |
|
22 | { |
||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private $validators; |
||
27 | |||
28 | /** |
||
29 | * Constructor |
||
30 | */ |
||
31 | public function __construct() |
||
35 | |||
36 | /** |
||
37 | * Add a validator |
||
38 | * |
||
39 | * @param \Jb\Bundle\FileUploaderBundle\Service\Validator\AbstractValidator $validator |
||
40 | */ |
||
41 | public function addValidator(AbstractValidator $validator, $alias) |
||
45 | |||
46 | /** |
||
47 | * Get a validator by its alias |
||
48 | * |
||
49 | * @param string $alias |
||
50 | * |
||
51 | * @return \Jb\Bundle\FileUploaderBundle\Service\Validator\AbstractValidator |
||
52 | * |
||
53 | * @throws \Jb\Bundle\FileUploaderBundle\Exception\JbFileUploaderException |
||
54 | */ |
||
55 | public function getValidator($alias) |
||
63 | } |
||
64 |