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 |
||
7 | class ConstraintFactory |
||
8 | { |
||
9 | /** |
||
10 | * Creates a validation constraint. |
||
11 | * |
||
12 | * @param string $name The name of standard constraint or FQCN of a custom constraint |
||
13 | * @param mixed $options The constraint options (as associative array) |
||
14 | * or the value for the default option (any other type) |
||
15 | * |
||
16 | * @return Constraint |
||
17 | * |
||
18 | * @throws \InvalidArgumentException if unknown constraint detected |
||
19 | */ |
||
20 | public function create($name, $options = null) |
||
43 | |||
44 | /** |
||
45 | * Creates validation constraints by a given definition. |
||
46 | * |
||
47 | * @param array $constraints The definition of constraints |
||
48 | * |
||
49 | * @return Constraint[] |
||
50 | * |
||
51 | * @throws \InvalidArgumentException if invalid definition detected |
||
52 | */ |
||
53 | public function parse(array $constraints) |
||
78 | } |
||
79 |