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  | 
            ||
| 19 | class HasGuessableExtensionValidator extends ConstraintValidator  | 
            ||
| 20 | { | 
            ||
| 21 | /**  | 
            ||
| 22 | * @var ExtensionGuesserInterface  | 
            ||
| 23 | */  | 
            ||
| 24 | private $extensionGuesser;  | 
            ||
| 25 | |||
| 26 | /**  | 
            ||
| 27 | * @var MimeTypeGuesserInterface  | 
            ||
| 28 | */  | 
            ||
| 29 | private $mimeTypeGuesser;  | 
            ||
| 30 | |||
| 31 | /** @var MimeTypes */  | 
            ||
| 32 | private $mimeTypes;  | 
            ||
| 33 | |||
| 34 | public function __construct($mimeTypes = null)  | 
            ||
| 42 | |||
| 43 | /**  | 
            ||
| 44 | * @param $value  | 
            ||
| 45 | * @param Constraint $constraint  | 
            ||
| 46 | *  | 
            ||
| 47 | * @throws ConstraintDefinitionException  | 
            ||
| 48 | * @throws UnexpectedTypeException  | 
            ||
| 49 | */  | 
            ||
| 50 | public function validate($value, Constraint $constraint)  | 
            ||
| 72 | |||
| 73 | private function guessMimeType($pathName)  | 
            ||
| 81 | |||
| 82 | View Code Duplication | private function getExtension($mimeType)  | 
            |
| 90 | |||
| 91 | /**  | 
            ||
| 92 | * @deprecated This method is deprecated since KunstmaanMediaBundle 5.7 and will be removed in KunstmaanMediaBundle 6.0.  | 
            ||
| 93 | *  | 
            ||
| 94 | * @param ExtensionGuesserFactoryInterface $extensionGuesserFactory  | 
            ||
| 95 | */  | 
            ||
| 96 | public function setExtensionGuesser(ExtensionGuesserFactoryInterface $extensionGuesserFactory)  | 
            ||
| 102 | |||
| 103 | /**  | 
            ||
| 104 | * @deprecated This method is deprecated since KunstmaanMediaBundle 5.7 and will be removed in KunstmaanMediaBundle 6.0.  | 
            ||
| 105 | *  | 
            ||
| 106 | * @param MimeTypeGuesserFactoryInterface $mimeTypeGuesserFactory  | 
            ||
| 107 | */  | 
            ||
| 108 | public function setMimeTypeGuesser(MimeTypeGuesserFactoryInterface $mimeTypeGuesserFactory)  | 
            ||
| 114 | }  | 
            ||
| 115 | 
If you suppress an error, we recommend checking for the error condition explicitly: