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  | 
            ||
| 27 | class AdminExtension extends Twig_Extension  | 
            ||
| 28 | { | 
            ||
| 29 | use TranslationKeyTrait;  | 
            ||
| 30 | |||
| 31 | /**  | 
            ||
| 32 | * @var ApplicationConfiguration  | 
            ||
| 33 | */  | 
            ||
| 34 | protected $configuration;  | 
            ||
| 35 | |||
| 36 | /**  | 
            ||
| 37 | * @var RouterInterface  | 
            ||
| 38 | */  | 
            ||
| 39 | protected $router;  | 
            ||
| 40 | |||
| 41 | /**  | 
            ||
| 42 | * @var TranslatorInterface  | 
            ||
| 43 | */  | 
            ||
| 44 | protected $translator;  | 
            ||
| 45 | |||
| 46 | /**  | 
            ||
| 47 | * @var Twig_Environment  | 
            ||
| 48 | */  | 
            ||
| 49 | protected $twig;  | 
            ||
| 50 | |||
| 51 | /**  | 
            ||
| 52 | * AdminExtension constructor.  | 
            ||
| 53 | *  | 
            ||
| 54 | * @param RouterInterface $router  | 
            ||
| 55 | * @param TranslatorInterface $translator  | 
            ||
| 56 | * @param ConfigurationFactory $configurationFactory  | 
            ||
| 57 | * @param Twig_Environment $twig  | 
            ||
| 58 | */  | 
            ||
| 59 | View Code Duplication | public function __construct(  | 
            |
| 70 | |||
| 71 | /**  | 
            ||
| 72 | * @return array  | 
            ||
| 73 | */  | 
            ||
| 74 | public function getFunctions()  | 
            ||
| 85 | |||
| 86 | /**  | 
            ||
| 87 | * @return array  | 
            ||
| 88 | */  | 
            ||
| 89 | public function getFilters()  | 
            ||
| 95 | |||
| 96 | /**  | 
            ||
| 97 | * Return sort column url, with existing request parameters, according to field name.  | 
            ||
| 98 | *  | 
            ||
| 99 | * @param Request $request  | 
            ||
| 100 | * @param $fieldName  | 
            ||
| 101 | *  | 
            ||
| 102 | * @return string  | 
            ||
| 103 | */  | 
            ||
| 104 | public function getSortColumnUrl(Request $request, $fieldName)  | 
            ||
| 123 | |||
| 124 | /**  | 
            ||
| 125 | * Return an array of query string parameters, updated with sort field name.  | 
            ||
| 126 | *  | 
            ||
| 127 | * @param ParameterBagInterface $parameters  | 
            ||
| 128 | * @param $fieldName  | 
            ||
| 129 | *  | 
            ||
| 130 | * @return array  | 
            ||
| 131 | */  | 
            ||
| 132 | public function getOrderQueryString(ParameterBagInterface $parameters, $fieldName)  | 
            ||
| 146 | |||
| 147 | /**  | 
            ||
| 148 | * @param null $order  | 
            ||
| 149 | * @param $fieldName  | 
            ||
| 150 | * @param $sort  | 
            ||
| 151 | *  | 
            ||
| 152 | * @return string  | 
            ||
| 153 | */  | 
            ||
| 154 | public function getSortColumnIconClass($order = null, $fieldName, $sort)  | 
            ||
| 169 | |||
| 170 | /**  | 
            ||
| 171 | * Render a field of an entity.  | 
            ||
| 172 | *  | 
            ||
| 173 | * @param FieldInterface $field  | 
            ||
| 174 | * @param $entity  | 
            ||
| 175 | *  | 
            ||
| 176 | * @return string  | 
            ||
| 177 | */  | 
            ||
| 178 | public function field(FieldInterface $field, $entity)  | 
            ||
| 197 | |||
| 198 | /**  | 
            ||
| 199 | * Return a the title of the field, camelized or translated.  | 
            ||
| 200 | *  | 
            ||
| 201 | * @param $fieldName  | 
            ||
| 202 | * @param null $adminName  | 
            ||
| 203 | *  | 
            ||
| 204 | * @return string  | 
            ||
| 205 | */  | 
            ||
| 206 | public function fieldTitle($fieldName, $adminName = null)  | 
            ||
| 218 | |||
| 219 | /**  | 
            ||
| 220 | * @param array $parameters  | 
            ||
| 221 | * @param $entity  | 
            ||
| 222 | *  | 
            ||
| 223 | * @return array  | 
            ||
| 224 | */  | 
            ||
| 225 | public function routeParameters(array $parameters, $entity)  | 
            ||
| 239 | |||
| 240 | /**  | 
            ||
| 241 | * Camelize a string (using Container camelize method)  | 
            ||
| 242 | *  | 
            ||
| 243 | * @param $string  | 
            ||
| 244 | *  | 
            ||
| 245 | * @return string  | 
            ||
| 246 | */  | 
            ||
| 247 | public function camelize($string)  | 
            ||
| 251 | |||
| 252 | /**  | 
            ||
| 253 | * Returns the name of the extension.  | 
            ||
| 254 | *  | 
            ||
| 255 | * @return string The extension name  | 
            ||
| 256 | */  | 
            ||
| 257 | public function getName()  | 
            ||
| 261 | |||
| 262 | /**  | 
            ||
| 263 | * Return true if the method exists in twig.  | 
            ||
| 264 | *  | 
            ||
| 265 | * @param string $functionName  | 
            ||
| 266 | *  | 
            ||
| 267 | * @return bool  | 
            ||
| 268 | */  | 
            ||
| 269 | public function functionExists($functionName)  | 
            ||
| 275 | }  | 
            ||
| 276 | 
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.