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 AdminExtension extends Twig_Extension |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var ApplicationConfiguration |
||
| 28 | */ |
||
| 29 | protected $configuration; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var RouterInterface |
||
| 33 | */ |
||
| 34 | protected $router; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var TranslatorInterface |
||
| 38 | */ |
||
| 39 | protected $translator; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * AdminExtension constructor. |
||
| 43 | * |
||
| 44 | * @param RouterInterface $router |
||
| 45 | * @param TranslatorInterface $translator |
||
| 46 | * @param ApplicationConfiguration $configuration |
||
| 47 | */ |
||
| 48 | public function __construct(RouterInterface $router, TranslatorInterface $translator, ApplicationConfiguration $configuration) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | public function getFunctions() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return array |
||
| 71 | */ |
||
| 72 | public function getFilters() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Return sort column url, with existing request parameters, according to field name. |
||
| 81 | * |
||
| 82 | * @param Request $request |
||
| 83 | * @param $fieldName |
||
| 84 | * |
||
| 85 | * @return string |
||
| 86 | * TODO rename function |
||
| 87 | */ |
||
| 88 | public function getSortColumnUrl(Request $request, $fieldName) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Return an array of query string parameters, updated with sort field name. |
||
| 110 | * |
||
| 111 | * @param ParameterBagInterface $parameters |
||
| 112 | * @param $fieldName |
||
| 113 | * @return array |
||
| 114 | */ |
||
| 115 | public function getOrderQueryString(ParameterBagInterface $parameters, $fieldName) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @param null $order |
||
| 132 | * @param $fieldName |
||
| 133 | * @param $sort |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | public function getSortColumnIconClass($order = null, $fieldName, $sort) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Render a field of an entity. |
||
| 154 | * |
||
| 155 | * @param FieldInterface $field |
||
| 156 | * @param $entity |
||
| 157 | * |
||
| 158 | * @return mixed |
||
| 159 | */ |
||
| 160 | public function field(FieldInterface $field, $entity) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param $fieldName |
||
| 181 | * @param null $adminName |
||
| 182 | * @return string |
||
| 183 | */ |
||
| 184 | public function fieldTitle($fieldName, $adminName = null) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @param array $parameters |
||
| 199 | * @param $entity |
||
| 200 | * @return array |
||
| 201 | */ |
||
| 202 | public function routeParameters(array $parameters, $entity) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Camelize a string (using Container camelize method) |
||
| 219 | * |
||
| 220 | * @param $string |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | public function camelize($string) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Returns the name of the extension. |
||
| 230 | * |
||
| 231 | * @return string The extension name |
||
| 232 | */ |
||
| 233 | public function getName() |
||
| 237 | } |
||
| 238 |