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 |
||
12 | abstract class AbstractSmartIdQuery implements QueryInterface |
||
13 | { |
||
14 | /** @var string user personal code */ |
||
15 | private $code; |
||
16 | |||
17 | /** @var string Country related to personal code. Example EE */ |
||
18 | private $country; |
||
19 | |||
20 | /** |
||
21 | * @param string $code |
||
22 | * @param string $country |
||
23 | * @return self |
||
|
|||
24 | */ |
||
25 | 5 | public function __construct( |
|
32 | |||
33 | /** |
||
34 | * Field and values association used in query |
||
35 | * @return array |
||
36 | */ |
||
37 | 1 | public function getFields() |
|
38 | { |
||
39 | $return = [ |
||
40 | 1 | 'code' => $this->code, |
|
41 | 1 | 'country' => $this->country, |
|
42 | ]; |
||
43 | |||
44 | 1 | return $return; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Validation constraints for request data validation |
||
49 | * @return Assert\Collection |
||
50 | */ |
||
51 | 1 | View Code Duplication | public function getValidationConstraints() |
52 | { |
||
53 | 1 | return new Assert\Collection([ |
|
54 | 1 | 'code' => new Assert\Required([ |
|
55 | 1 | new Assert\NotBlank(), |
|
56 | 1 | new Code() |
|
57 | ]), |
||
58 | 1 | 'country' => new Assert\Required([ |
|
59 | 1 | new Assert\NotBlank(), |
|
60 | ]), |
||
61 | ]); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * HTTP method to use |
||
66 | * @return string |
||
67 | */ |
||
68 | 1 | public function getMethod() |
|
72 | } |
||
73 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.