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 |
||
| 17 | abstract class AbstractHandler |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface |
||
| 21 | */ |
||
| 22 | protected $cache; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var \eZ\Publish\SPI\Persistence\Handler |
||
| 26 | */ |
||
| 27 | protected $persistenceHandler; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var \eZ\Publish\Core\Persistence\Cache\PersistenceLogger |
||
| 31 | */ |
||
| 32 | protected $logger; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Setups current handler with everything needed. |
||
| 36 | * |
||
| 37 | * @param \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface $cache |
||
| 38 | * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler |
||
| 39 | * @param \eZ\Publish\Core\Persistence\Cache\PersistenceLogger $logger |
||
| 40 | */ |
||
| 41 | public function __construct( |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Helper for getting multiple cache items in one call and do the id extraction for you. |
||
| 53 | * |
||
| 54 | * Cache items must be stored with a key in the following format "${keyPrefix}${id}", like "ez-content-info-${id}", |
||
| 55 | * in order for this method to be able to prefix key on id's and also extract key prefix afterwards. |
||
| 56 | * |
||
| 57 | * It also optionally supports a key suffixs, for use on a variable argument that affects all lookups, |
||
| 58 | * like translations, i.e. "ez-content-${id}-${translationKey}" where $keySuffixes = [$id => "-${translationKey}"]. |
||
| 59 | * |
||
| 60 | * @param array $ids |
||
| 61 | * @param string $keyPrefix E.g "ez-content-" |
||
| 62 | * @param callable $missingLoader Function for loading missing objects, gets array with missing id's as argument, |
||
| 63 | * expects return value to be array with id as key. Missing items should be missing. |
||
| 64 | * @param callable $loadedTagger Function for tagging loaded object, gets object as argument, return array of tags. |
||
| 65 | * @param array $keySuffixes Optional, key is id as provided in $ids, and value is a key suffix e.g. "-eng-Gb" |
||
| 66 | * |
||
| 67 | * @return array |
||
| 68 | */ |
||
| 69 | final protected function getMultipleCacheItems( |
||
| 124 | |||
| 125 | View Code Duplication | final protected function escapeForCacheKey(string $identifier) |
|
| 133 | } |
||
| 134 |