Total Complexity | 13 |
Total Lines | 64 |
Duplicated Lines | 21.88 % |
Coverage | 96.3% |
Changes | 0 |
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 | final class StashWrapper implements Pool { |
||
18 | |||
19 | /** @var Stash\Pool */ |
||
20 | private $stash; |
||
21 | |||
22 | /** |
||
23 | * Constructor |
||
24 | * |
||
25 | * @param Stash\Pool $stash The Stash instance to be decorated. |
||
26 | */ |
||
27 | 16 | public function __construct(Stash\Pool $stash) { |
|
28 | 16 | $this->stash = $stash; |
|
29 | 16 | } |
|
30 | |||
31 | /** @inheritDoc */ |
||
32 | 8 | public function get($key, callable $callback = null, $default = null) { |
|
54 | } |
||
55 | |||
56 | /** @inheritDoc */ |
||
57 | 6 | View Code Duplication | public function invalidate($key) { |
|
|||
58 | 6 | if (!is_string($key) && !is_int($key)) { |
|
59 | 4 | throw new InvalidArgumentException('key must be string or integer'); |
|
60 | } |
||
61 | |||
62 | 2 | $this->stash->getItem((string) $key)->clear(); |
|
63 | 2 | } |
|
64 | |||
65 | /** @inheritDoc */ |
||
66 | 5 | View Code Duplication | public function put($key, $value) { |
67 | 5 | if (!is_string($key) && !is_int($key)) { |
|
68 | 4 | throw new InvalidArgumentException('key must be string or integer'); |
|
69 | } |
||
70 | |||
71 | 1 | $this->stash->getItem((string) $key)->set($value); |
|
72 | 1 | } |
|
73 | |||
74 | /** |
||
75 | * Create an in-memory implementation of the pool. |
||
76 | * |
||
77 | * @return StashWrapper |
||
78 | */ |
||
79 | 16 | public static function createEphemeral() { |
|
81 | } |
||
82 | } |
||
83 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.