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 |
||
| 20 | class TransactionalInMemoryCacheAdapter implements TransactionAwareAdapterInterface |
||
| 21 | { |
||
| 22 | /** @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface */ |
||
| 23 | protected $sharedPool; |
||
| 24 | |||
| 25 | /** @var \eZ\Publish\Core\Persistence\Cache\inMemory\InMemoryCache[] */ |
||
| 26 | private $inMemoryPools; |
||
| 27 | |||
| 28 | /** @var int */ |
||
| 29 | protected $transactionDepth; |
||
| 30 | |||
| 31 | /** @var array To be unique and simplify lookup hash key is cache tag, value is only true value */ |
||
| 32 | protected $deferredTagsInvalidation; |
||
| 33 | |||
| 34 | /** @var array To be unique and simplify lookup hash key is cache key, value is only true value */ |
||
| 35 | protected $deferredItemsDeletion; |
||
| 36 | |||
| 37 | /** @var \Closure Callback for use by {@see markItemsAsDeferredMissIfNeeded()} when items are misses by deferred action */ |
||
| 38 | protected $setCacheItemAsMiss; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface $sharedPool |
||
| 42 | * @param \eZ\Publish\Core\Persistence\Cache\inMemory\InMemoryCache[] $inMemoryPools |
||
| 43 | * @param int $transactionDepth |
||
| 44 | * @param array $deferredTagsInvalidation |
||
| 45 | * @param array $deferredItemsDeletion |
||
| 46 | */ |
||
| 47 | public function __construct( |
||
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritdoc} |
||
| 72 | */ |
||
| 73 | public function getItem($key) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | public function getItems(array $keys = []) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * {@inheritdoc} |
||
| 92 | */ |
||
| 93 | public function hasItem($key) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * {@inheritdoc} |
||
| 104 | */ |
||
| 105 | View Code Duplication | public function deleteItem($key) |
|
| 119 | |||
| 120 | /** |
||
| 121 | * {@inheritdoc} |
||
| 122 | */ |
||
| 123 | View Code Duplication | public function deleteItems(array $keys) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * {@inheritdoc} |
||
| 140 | */ |
||
| 141 | public function invalidateTags(array $tags) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * {@inheritdoc} |
||
| 157 | */ |
||
| 158 | public function clear() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * {@inheritdoc} |
||
| 172 | */ |
||
| 173 | public function save(CacheItemInterface $item) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * {@inheritdoc} |
||
| 186 | */ |
||
| 187 | public function beginTransaction(): void |
||
| 191 | |||
| 192 | /** |
||
| 193 | * {@inheritdoc} |
||
| 194 | */ |
||
| 195 | public function commitTransaction(): void |
||
| 217 | |||
| 218 | /** |
||
| 219 | * {@inheritdoc} |
||
| 220 | */ |
||
| 221 | public function rollbackTransaction(): void |
||
| 229 | |||
| 230 | /** |
||
| 231 | * {@inheritdoc} |
||
| 232 | * |
||
| 233 | * Symfony cache feature for deferring saves, not used by eZ & not related to transaction handling here. |
||
| 234 | */ |
||
| 235 | public function saveDeferred(CacheItemInterface $item) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * {@inheritdoc} |
||
| 242 | * |
||
| 243 | * Symfony cache feature for committing deferred saves, not used by eZ & not related to transaction handling here. |
||
| 244 | */ |
||
| 245 | public function commit() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * For use by getItem(s) to mark items as a miss if it's going to be cleared on transaction commit. |
||
| 252 | * |
||
| 253 | * @param \Symfony\Component\Cache\CacheItem[] $items |
||
| 254 | * |
||
| 255 | * @return \Symfony\Component\Cache\CacheItem[] |
||
| 256 | */ |
||
| 257 | private function markItemsAsDeferredMissIfNeeded(iterable $items) |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @param \Symfony\Component\Cache\CacheItem $item |
||
| 283 | * |
||
| 284 | * @return bool |
||
| 285 | */ |
||
| 286 | private function itemIsDeferredMiss(CacheItem $item): bool |
||
| 300 | |||
| 301 | private function clearInMemoryPools(): void |
||
| 307 | } |
||
| 308 |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.