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 |
||
14 | class JsonSchemaRule extends StandardRule |
||
15 | { |
||
16 | private $jsonSchemaFiles; |
||
17 | |||
18 | protected $contentTypes = array('json'); |
||
19 | |||
20 | private $json_errors = array( |
||
21 | JSON_ERROR_NONE => 'No Error', |
||
22 | JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', |
||
23 | JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', |
||
24 | JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', |
||
25 | JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', |
||
26 | JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', |
||
27 | ); |
||
28 | |||
29 | public function init($jsonSchemaFiles) |
||
33 | |||
34 | protected function doValidation(ResponseInterface $response) |
||
66 | } |
||
67 |
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.