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 |
||
13 | class SwaggerSchema extends Schema |
||
14 | { |
||
15 | /** |
||
16 | * Initialize with schema data, which can be a PHP array or encoded as JSON. |
||
17 | * |
||
18 | * @param array|string $data |
||
19 | * @param bool $allowNullValues |
||
20 | */ |
||
21 | View Code Duplication | public function __construct($data, $allowNullValues = false) |
|
34 | |||
35 | public function getHttpSchema() |
||
39 | |||
40 | public function getHost() |
||
44 | |||
45 | public function getBasePath() |
||
49 | |||
50 | public function getServerUrl() |
||
57 | |||
58 | /** |
||
59 | * @param $parameterIn |
||
60 | * @param $parameters |
||
61 | * @param $arguments |
||
62 | * @throws NotMatchedException |
||
63 | */ |
||
64 | protected function validateArguments($parameterIn, $parameters, $arguments) |
||
74 | |||
75 | /** |
||
76 | * @param $name |
||
77 | * @return mixed |
||
78 | * @throws DefinitionNotFoundException |
||
79 | * @throws InvalidDefinitionException |
||
80 | */ |
||
81 | public function getDefinition($name) |
||
95 | |||
96 | /** |
||
97 | * @param $path |
||
98 | * @param $method |
||
99 | * @return SwaggerRequestBody |
||
100 | * @throws DefinitionNotFoundException |
||
101 | * @throws HttpMethodNotFoundException |
||
102 | * @throws InvalidDefinitionException |
||
103 | * @throws NotMatchedException |
||
104 | * @throws PathNotFoundException |
||
105 | */ |
||
106 | public function getRequestParameters($path, $method) |
||
115 | |||
116 | /** |
||
117 | * OpenApi 2.0 doesn't describe null values, so this flag defines, |
||
118 | * if match is ok when one of property |
||
119 | * |
||
120 | * @param $value |
||
121 | */ |
||
122 | public function setAllowNullValues($value) |
||
126 | } |
||
127 |
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.