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 | class TransactionalCacheAdapterDecorator implements TransactionAwareAdapterInterface |
||
18 | { |
||
19 | /** @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface */ |
||
20 | protected $innerPool; |
||
21 | |||
22 | /** @var int */ |
||
23 | protected $transactionDepth; |
||
24 | |||
25 | /** @var array */ |
||
26 | protected $deferredTagsInvalidation; |
||
27 | |||
28 | /** @var array */ |
||
29 | protected $deferredItemsDeletion; |
||
30 | |||
31 | /** |
||
32 | * @param \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface $innerPool |
||
33 | * @param int $transactionDepth |
||
34 | * @param array $deferredTagsInvalidation |
||
35 | * @param array $deferredItemsDeletion |
||
36 | */ |
||
37 | public function __construct( |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function getItem($key) |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | public function getItems(array $keys = []) |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | public function hasItem($key) |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function deleteItem($key) |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | View Code Duplication | public function deleteItems(array $keys) |
|
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | View Code Duplication | public function invalidateTags(array $tags) |
|
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function clear() |
||
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | public function save(CacheItemInterface $item) |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function saveDeferred(CacheItemInterface $item) |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function commit() |
||
156 | |||
157 | public function startTransaction(): void |
||
163 | |||
164 | public function stopTransaction(): void |
||
180 | |||
181 | protected function invalidateDeferredTags(): void |
||
187 | |||
188 | protected function deleteDeferredItems(): void |
||
194 | } |
||
195 |