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 |
||
12 | trait SessionRequestTrait { |
||
13 | protected $aSessionVars = []; |
||
14 | |||
15 | 17 | protected function initSession() { |
|
20 | |||
21 | /** |
||
22 | * @return bool |
||
23 | */ |
||
24 | 18 | public static function hasSession() { |
|
27 | |||
28 | /** |
||
29 | * @return array |
||
30 | */ |
||
31 | 1 | public function getSessionVars() { |
|
34 | |||
35 | /** |
||
36 | * @param string $sVarName |
||
37 | * @return bool |
||
38 | */ |
||
39 | 1 | public function hasSessionVar($sVarName) { |
|
44 | |||
45 | /** |
||
46 | * @return string |
||
47 | */ |
||
48 | 1 | public static function getSessionName() { |
|
51 | |||
52 | /** |
||
53 | * @param string $sSessionName |
||
|
|||
54 | * @throws ExceptionRequest |
||
55 | */ |
||
56 | 1 | public static function startSession($sSessionName = null) { |
|
76 | |||
77 | /** |
||
78 | * return void |
||
79 | */ |
||
80 | 1 | public static function destroySession() { |
|
88 | |||
89 | /** |
||
90 | * |
||
91 | * @param string $sVarName |
||
92 | * @return mixed |
||
93 | */ |
||
94 | 2 | View Code Duplication | public function getSessionVar($sVarName) { |
101 | |||
102 | /** |
||
103 | * @param string $sVarName |
||
104 | * @param string $sVarValue |
||
105 | * @return bool |
||
106 | */ |
||
107 | 1 | public function setSessionVar($sVarName, $sVarValue) { |
|
112 | |||
113 | } |
||
114 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.