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 Jqadm |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * Returns the HTML code for a copy of a resource object |
||
| 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 | public static function copyAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
||
| 40 | |||
| 41 | |||
| 42 | /** |
||
| 43 | * Returns the HTML code for a new resource object |
||
| 44 | * |
||
| 45 | * @param ContainerInterface $container Dependency injection container |
||
| 46 | * @param ServerRequestInterface $request Request object |
||
| 47 | * @param ResponseInterface $response Response object |
||
| 48 | * @param array $args Associative list of route parameters |
||
| 49 | * @return ResponseInterface $response Modified response object with generated output |
||
| 50 | */ |
||
| 51 | public static function createAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
||
| 56 | |||
| 57 | |||
| 58 | /** |
||
| 59 | * Deletes the resource object or a list of resource objects |
||
| 60 | * |
||
| 61 | * @param ContainerInterface $container Dependency injection container |
||
| 62 | * @param ServerRequestInterface $request Request object |
||
| 63 | * @param ResponseInterface $response Response object |
||
| 64 | * @param array $args Associative list of route parameters |
||
| 65 | * @return ResponseInterface $response Modified response object with generated output |
||
| 66 | */ |
||
| 67 | public static function deleteAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
||
| 72 | |||
| 73 | |||
| 74 | /** |
||
| 75 | * Returns the HTML code for the requested resource object |
||
| 76 | * |
||
| 77 | * @param ContainerInterface $container Dependency injection container |
||
| 78 | * @param ServerRequestInterface $request Request object |
||
| 79 | * @param ResponseInterface $response Response object |
||
| 80 | * @param array $args Associative list of route parameters |
||
| 81 | * @return ResponseInterface $response Modified response object with generated output |
||
| 82 | */ |
||
| 83 | public static function getAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
||
| 88 | |||
| 89 | |||
| 90 | /** |
||
| 91 | * Saves a new resource object |
||
| 92 | * |
||
| 93 | * @param ContainerInterface $container Dependency injection container |
||
| 94 | * @param ServerRequestInterface $request Request object |
||
| 95 | * @param ResponseInterface $response Response object |
||
| 96 | * @param array $args Associative list of route parameters |
||
| 97 | * @return ResponseInterface $response Modified response object with generated output |
||
| 98 | */ |
||
| 99 | public static function saveAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
||
| 104 | |||
| 105 | |||
| 106 | /** |
||
| 107 | * Returns the HTML code for a list of resource objects |
||
| 108 | * |
||
| 109 | * @param ContainerInterface $container Dependency injection container |
||
| 110 | * @param ServerRequestInterface $request Request object |
||
| 111 | * @param ResponseInterface $response Response object |
||
| 112 | * @param array $args Associative list of route parameters |
||
| 113 | * @return ResponseInterface $response Modified response object with generated output |
||
| 114 | */ |
||
| 115 | public static function searchAction( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
||
| 120 | |||
| 121 | |||
| 122 | /** |
||
| 123 | * Returns the resource controller |
||
| 124 | * |
||
| 125 | * @param ContainerInterface $container Dependency injection container |
||
| 126 | * @param ServerRequestInterface $request Request object |
||
| 127 | * @param ResponseInterface $response Response object |
||
| 128 | * @param array $args Associative list of route parameters |
||
| 129 | * @return \Aimeos\Admin\JQAdm\Iface JQAdm client |
||
| 130 | */ |
||
| 131 | View Code Duplication | protected static function createClient( ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response, array $args ) |
|
| 147 | |||
| 148 | |||
| 149 | /** |
||
| 150 | * Returns the generated HTML code |
||
| 151 | * |
||
| 152 | * @param ContainerInterface $container Dependency injection container |
||
| 153 | * @param ResponseInterface $response Response object |
||
| 154 | * @param string $content Content from admin client |
||
| 155 | * @return \Illuminate\Contracts\View\View View for rendering the output |
||
| 156 | */ |
||
| 157 | protected static function getHtml( ContainerInterface $container, ResponseInterface $response, $content ) |
||
| 164 | |||
| 165 | |||
| 166 | /** |
||
| 167 | * Sets the locale item in the given context |
||
| 168 | * |
||
| 169 | * @param \Aimeos\Slim\Base\I18n $i18n Aimeos translation object builder |
||
| 170 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
| 171 | * @param string $site Unique site code |
||
| 172 | * @param string $lang ISO language code, e.g. "en" or "en_GB" |
||
| 173 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
| 174 | */ |
||
| 175 | View Code Duplication | protected static function setLocale( \Aimeos\Slim\Base\I18n $i18n, \Aimeos\MShop\Context\Item\Iface $context, $site, $lang ) |
|
| 195 | } |
||
| 196 |
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.