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 namespace Comodojo\Cookies; |
||
23 | class Cookie extends AbstractCookie { |
||
24 | |||
25 | /** |
||
26 | * Set cookie content |
||
27 | * |
||
28 | * @param mixed $value Cookie content |
||
29 | * @param bool $serialize If true (default) cookie will be serialized first |
||
30 | * |
||
31 | * @return \Comodojo\Cookies\Cookie |
||
32 | * |
||
33 | * @throws \Comodojo\Exception\CookieException |
||
34 | */ |
||
35 | 15 | public function setValue($value, $serialize = true) { |
|
48 | |||
49 | /** |
||
50 | * Get cookie content |
||
51 | * |
||
52 | * @param bool $unserialize If true (default) cookie will be unserialized first |
||
53 | * |
||
54 | * @return mixed |
||
55 | */ |
||
56 | 12 | public function getValue($unserialize = true) { |
|
61 | |||
62 | /** |
||
63 | * Static method to create a cookie quickly |
||
64 | * |
||
65 | * @param string $name The cookie name |
||
66 | * |
||
67 | * @param array $properties Array of properties cookie should have |
||
68 | * |
||
69 | * @return \Comodojo\Cookies\Cookie |
||
70 | * |
||
71 | * @throws \Comodojo\Exception\CookieException |
||
72 | */ |
||
73 | 3 | public static function create($name, $properties = [], $serialize = true) { |
|
92 | |||
93 | /** |
||
94 | * Static method to get a cookie quickly |
||
95 | * |
||
96 | * @param string $name The cookie name |
||
97 | * |
||
98 | * @return \Comodojo\Cookies\Cookie |
||
99 | * |
||
100 | * @throws \Comodojo\Exception\CookieException |
||
101 | */ |
||
102 | 3 | View Code Duplication | public static function retrieve($name) { |
121 | |||
122 | } |
||
123 |
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.