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 |
||
| 24 | class Jsonadm |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * Deletes the resource object or a list of resource objects |
||
| 28 | * |
||
| 29 | * @param ContainerInterface $container Dependency injection container |
||
| 30 | * @param ServerRequestInterface $request Request object |
||
| 31 | * @param ResponseInterface $response Response object |
||
| 32 | * @param array $args Associative list of route parameters |
||
| 33 | * @return ResponseInterface $response Modified response object with generated output |
||
| 34 | */ |
||
| 35 | View Code Duplication | public static function deleteAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
|
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * Returns the requested resource object or list of resource objects |
||
| 49 | * |
||
| 50 | * @param ContainerInterface $container Dependency injection container |
||
| 51 | * @param ServerRequestInterface $request Request object |
||
| 52 | * @param ResponseInterface $response Response object |
||
| 53 | * @param array $args Associative list of route parameters |
||
| 54 | * @return ResponseInterface $response Modified response object with generated output |
||
| 55 | */ |
||
| 56 | View Code Duplication | public static function getAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
|
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * Updates a resource object or a list of resource objects |
||
| 70 | * |
||
| 71 | * @param ContainerInterface $container Dependency injection container |
||
| 72 | * @param ServerRequestInterface $request Request object |
||
| 73 | * @param ResponseInterface $response Response object |
||
| 74 | * @param array $args Associative list of route parameters |
||
| 75 | * @return ResponseInterface $response Modified response object with generated output |
||
| 76 | */ |
||
| 77 | View Code Duplication | public static function patchAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
|
| 87 | |||
| 88 | |||
| 89 | /** |
||
| 90 | * Creates a new resource object or a list of resource objects |
||
| 91 | * |
||
| 92 | * @param ContainerInterface $container Dependency injection container |
||
| 93 | * @param ServerRequestInterface $request Request object |
||
| 94 | * @param ResponseInterface $response Response object |
||
| 95 | * @param array $args Associative list of route parameters |
||
| 96 | * @return ResponseInterface $response Modified response object with generated output |
||
| 97 | */ |
||
| 98 | View Code Duplication | public static function postAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
|
| 108 | |||
| 109 | |||
| 110 | /** |
||
| 111 | * Creates or updates a single resource object |
||
| 112 | * |
||
| 113 | * @param ContainerInterface $container Dependency injection container |
||
| 114 | * @param ServerRequestInterface $request Request object |
||
| 115 | * @param ResponseInterface $response Response object |
||
| 116 | * @param array $args Associative list of route parameters |
||
| 117 | * @return ResponseInterface $response Modified response object with generated output |
||
| 118 | */ |
||
| 119 | View Code Duplication | public static function putAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
|
| 129 | |||
| 130 | |||
| 131 | /** |
||
| 132 | * Returns the available HTTP verbs and the resource URLs |
||
| 133 | * |
||
| 134 | * @param ContainerInterface $container Dependency injection container |
||
| 135 | * @param ServerRequestInterface $request Request object |
||
| 136 | * @param ResponseInterface $response Response object |
||
| 137 | * @param array $args Associative list of route parameters |
||
| 138 | * @return ResponseInterface $response Modified response object with generated output |
||
| 139 | */ |
||
| 140 | View Code Duplication | public static function optionsAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
|
| 150 | |||
| 151 | |||
| 152 | /** |
||
| 153 | * Returns the resource controller |
||
| 154 | * |
||
| 155 | * @param ContainerInterface $container Dependency injection container |
||
| 156 | * @param ServerRequestInterface $request Request object |
||
| 157 | * @param ResponseInterface $response Response object |
||
| 158 | * @param array $args Associative list of route parameters |
||
| 159 | * @return \Aimeos\Controller\JsonAdm\Iface JSON admin controller |
||
| 160 | */ |
||
| 161 | View Code Duplication | protected static function createController( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
|
| 177 | |||
| 178 | |||
| 179 | /** |
||
| 180 | * Populates the response object |
||
| 181 | * |
||
| 182 | * @param ResponseInterface $response Response object |
||
| 183 | * @param string $content Body of the HTTP response |
||
| 184 | * @param integer $status HTTP status |
||
| 185 | * @param array $header List of HTTP headers |
||
| 186 | * @return ResponseInterface $response Populated response object |
||
| 187 | */ |
||
| 188 | protected static function withResponse( ResponseInterface $response, $content, $status, array $header ) |
||
| 199 | |||
| 200 | |||
| 201 | /** |
||
| 202 | * Sets the locale item in the given context |
||
| 203 | * |
||
| 204 | * @param \Aimeos\Slim\Base\I18n $i18n Aimeos translation object builder |
||
| 205 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
| 206 | * @param string $sitecode Unique site code |
||
| 207 | * @param string $lang ISO language code, e.g. "en" or "en_GB" |
||
| 208 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
| 209 | */ |
||
| 210 | View Code Duplication | protected static function setLocale( \Aimeos\Slim\Base\I18n $i18n, \Aimeos\MShop\Context\Item\Iface $context, $sitecode, $lang ) |
|
| 230 | } |
||
| 231 |
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.