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  | 
            ||
| 15 | class MaskGenerator  | 
            ||
| 16 | { | 
            ||
| 17 | /**  | 
            ||
| 18 | * Language lookup.  | 
            ||
| 19 | *  | 
            ||
| 20 | * @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler  | 
            ||
| 21 | */  | 
            ||
| 22 | protected $languageHandler;  | 
            ||
| 23 | |||
| 24 | /**  | 
            ||
| 25 | * Creates a new Language MaskGenerator.  | 
            ||
| 26 | *  | 
            ||
| 27 | * @param \eZ\Publish\SPI\Persistence\Content\Language\Handler $languageHandler  | 
            ||
| 28 | */  | 
            ||
| 29 | public function __construct(LanguageHandler $languageHandler)  | 
            ||
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * Generates a language mask from the keys of $languages.  | 
            ||
| 36 | *  | 
            ||
| 37 |      * @deprecated Move towards using {@see generateLanguageMaskFromLanguageCodes()} or the other generate* methods. | 
            ||
| 38 | *  | 
            ||
| 39 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If language(s) in $languageCodes was not be found  | 
            ||
| 40 | *  | 
            ||
| 41 | * @param array $languages  | 
            ||
| 42 | *  | 
            ||
| 43 | * @return int  | 
            ||
| 44 | */  | 
            ||
| 45 | public function generateLanguageMask(array $languages)  | 
            ||
| 65 | |||
| 66 | /**  | 
            ||
| 67 | * Generates a language mask from pre-loaded Language Ids.  | 
            ||
| 68 | *  | 
            ||
| 69 | * @param int[] $languageIds  | 
            ||
| 70 | * @param bool $alwaysAvailable  | 
            ||
| 71 | *  | 
            ||
| 72 | * @return int  | 
            ||
| 73 | */  | 
            ||
| 74 | public function generateLanguageMaskFromLanguageIds(array $languageIds, $alwaysAvailable): int  | 
            ||
| 85 | |||
| 86 | /**  | 
            ||
| 87 | * Generates a language indicator from $languageCode and $alwaysAvailable.  | 
            ||
| 88 | *  | 
            ||
| 89 | * @param string $languageCode  | 
            ||
| 90 | * @param bool $alwaysAvailable  | 
            ||
| 91 | *  | 
            ||
| 92 | * @return int  | 
            ||
| 93 | *  | 
            ||
| 94 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException  | 
            ||
| 95 | */  | 
            ||
| 96 | public function generateLanguageIndicator($languageCode, $alwaysAvailable)  | 
            ||
| 100 | |||
| 101 | /**  | 
            ||
| 102 | * Checks if $language is always available in $languages;.  | 
            ||
| 103 | *  | 
            ||
| 104 | * @param string $language  | 
            ||
| 105 | * @param array $languages  | 
            ||
| 106 | *  | 
            ||
| 107 | * @return bool  | 
            ||
| 108 | */  | 
            ||
| 109 | public function isLanguageAlwaysAvailable($language, array $languages): bool  | 
            ||
| 115 | |||
| 116 | /**  | 
            ||
| 117 | * Checks if $languageMask contains the alwaysAvailable bit field.  | 
            ||
| 118 | *  | 
            ||
| 119 | * @param int $languageMask  | 
            ||
| 120 | *  | 
            ||
| 121 | * @return bool  | 
            ||
| 122 | */  | 
            ||
| 123 | public function isAlwaysAvailable($languageMask): bool  | 
            ||
| 127 | |||
| 128 | /**  | 
            ||
| 129 | * Removes the alwaysAvailable flag from $languageId and returns cleaned up $languageId.  | 
            ||
| 130 | *  | 
            ||
| 131 | * @param int $languageId  | 
            ||
| 132 | *  | 
            ||
| 133 | * @return int  | 
            ||
| 134 | */  | 
            ||
| 135 | public function removeAlwaysAvailableFlag($languageId): int  | 
            ||
| 139 | |||
| 140 | /**  | 
            ||
| 141 | * Extracts every language Ids contained in $languageMask.  | 
            ||
| 142 | *  | 
            ||
| 143 | * @param int $languageMask  | 
            ||
| 144 | *  | 
            ||
| 145 | * @return array Array of language Id  | 
            ||
| 146 | */  | 
            ||
| 147 | public function extractLanguageIdsFromMask($languageMask): array  | 
            ||
| 163 | |||
| 164 | /**  | 
            ||
| 165 | * Extracts Language codes contained in given $languageMask.  | 
            ||
| 166 | *  | 
            ||
| 167 | * @param int $languageMask  | 
            ||
| 168 | *  | 
            ||
| 169 | * @return array  | 
            ||
| 170 | */  | 
            ||
| 171 | public function extractLanguageCodesFromMask($languageMask): array  | 
            ||
| 183 | |||
| 184 | /**  | 
            ||
| 185 | * Checks if given $languageMask consists of multiple languages.  | 
            ||
| 186 | *  | 
            ||
| 187 | * @param int $languageMask  | 
            ||
| 188 | *  | 
            ||
| 189 | * @return bool  | 
            ||
| 190 | */  | 
            ||
| 191 | public function isLanguageMaskComposite($languageMask): bool  | 
            ||
| 204 | |||
| 205 | /**  | 
            ||
| 206 | * Generates a language mask from plain array of language codes and always available flag.  | 
            ||
| 207 | *  | 
            ||
| 208 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If language(s) in $languageCodes was not be found  | 
            ||
| 209 | *  | 
            ||
| 210 | * @param string[] $languageCodes  | 
            ||
| 211 | * @param bool $isAlwaysAvailable  | 
            ||
| 212 | *  | 
            ||
| 213 | * @return int  | 
            ||
| 214 | */  | 
            ||
| 215 | public function generateLanguageMaskFromLanguageCodes(array $languageCodes, bool $isAlwaysAvailable = false): int  | 
            ||
| 230 | |||
| 231 | /**  | 
            ||
| 232 | * Collect all translations of the given Persistence Fields and generate language mask.  | 
            ||
| 233 | *  | 
            ||
| 234 | * @param \eZ\Publish\SPI\Persistence\Content\Field[] $fields  | 
            ||
| 235 | *  | 
            ||
| 236 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException  | 
            ||
| 237 | */  | 
            ||
| 238 | public function generateLanguageMaskForFields(  | 
            ||
| 257 | }  | 
            ||
| 258 | 
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.