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 | abstract class Validator implements ValidatorInterface{ |
||
| 7 | protected $modifiedMessage; |
||
| 8 | protected $message; |
||
| 9 | protected $member; |
||
| 10 | protected $value; |
||
| 11 | protected $severity; |
||
| 12 | |||
| 13 | |||
| 14 | /** |
||
| 15 | * @param mixed $value |
||
| 16 | * @return \Ubiquity\contents\validation\validators\ConstraintViolation|boolean |
||
| 17 | */ |
||
| 18 | public function validate_($value){ |
||
| 25 | |||
| 26 | public function setValidationParameters($member,$params,$severity='warning',$message=null){ |
||
| 31 | |||
| 32 | protected function setParams(array $params){ |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function getMember() { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param mixed $member |
||
| 47 | */ |
||
| 48 | public function setMember($member) { |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritDoc} |
||
| 54 | * @see \Ubiquity\contents\validation\validators\ValidatorInterface::getParameters() |
||
| 55 | */ |
||
| 56 | public function getParameters(): array { |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return array|string |
||
| 63 | */ |
||
| 64 | protected function mergeMessages(){ |
||
| 71 | |||
| 72 | protected function _getMessage(){ |
||
| 80 | |||
| 81 | } |
||
| 82 | |||
| 83 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.