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 |
||
| 17 | abstract class AbstractRuleListener |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var array List of arrays with RequestMatcherInterface, settings array |
||
| 21 | */ |
||
| 22 | private $rulesMap = []; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Add a rule matcher with a list of header directives to apply if the |
||
| 26 | * request and response are matched. |
||
| 27 | * |
||
| 28 | * @param RequestMatcherInterface $requestMatcher The headers apply to responses matched by this matcher |
||
| 29 | * @param array $settings An array of header configuration |
||
| 30 | */ |
||
| 31 | 35 | public function addRule( |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Return the settings for the current request if any rule matches. |
||
| 40 | * |
||
| 41 | * @return array|false Settings to apply or false if no rule matched |
||
| 42 | */ |
||
| 43 | View Code Duplication | protected function matchRule(Request $request) |
|
| 53 | } |
||
| 54 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.