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 |
||
| 29 | class RaService |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * @var LibraryRaService |
||
| 33 | */ |
||
| 34 | private $service; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var ValidatorInterface |
||
| 38 | */ |
||
| 39 | private $validator; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param LibraryRaService $service |
||
| 43 | * @param ValidatorInterface $validator |
||
| 44 | */ |
||
| 45 | public function __construct(LibraryRaService $service, ValidatorInterface $validator) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param string $institution |
||
| 53 | * @return RegistrationAuthorityCredentialsCollection |
||
| 54 | */ |
||
| 55 | public function listRas($institution) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param object $value |
||
| 68 | * @param null|string $message |
||
| 69 | */ |
||
| 70 | View Code Duplication | private function assertIsValid($value, $message = null) |
|
| 80 | } |
||
| 81 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.