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 |
||
27 | class Ldap extends AuthAbstract |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @var |
||
32 | */ |
||
33 | public $ldap_server; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | |||
39 | public $ldap_port = '389'; |
||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | public $ldap_version = '3'; |
||
44 | |||
45 | /** |
||
46 | * @var |
||
47 | */ |
||
48 | public $ldap_base_dn; |
||
49 | |||
50 | /** |
||
51 | * @var |
||
52 | */ |
||
53 | public $ldap_loginname_asdn; |
||
54 | |||
55 | /** |
||
56 | * @var |
||
57 | */ |
||
58 | public $ldap_loginldap_attr; |
||
59 | |||
60 | /** |
||
61 | * @var |
||
62 | */ |
||
63 | public $ldap_mail_attr; |
||
64 | |||
65 | /** |
||
66 | * @var |
||
67 | */ |
||
68 | public $ldap_name_attr; |
||
69 | |||
70 | /** |
||
71 | * @var |
||
72 | */ |
||
73 | public $ldap_surname_attr; |
||
74 | |||
75 | /** |
||
76 | * @var |
||
77 | */ |
||
78 | public $ldap_givenname_attr; |
||
79 | |||
80 | /** |
||
81 | * @var |
||
82 | */ |
||
83 | public $ldap_manager_dn; |
||
84 | |||
85 | /** |
||
86 | * @var |
||
87 | */ |
||
88 | public $ldap_manager_pass; |
||
89 | |||
90 | /** |
||
91 | * @var |
||
92 | */ |
||
93 | public $ds; |
||
94 | |||
95 | /** |
||
96 | * @var |
||
97 | */ |
||
98 | public $ldap_use_TLS; |
||
99 | |||
100 | /** |
||
101 | * @var |
||
102 | */ |
||
103 | public $ldap_domain_name; |
||
104 | |||
105 | /** |
||
106 | * @var |
||
107 | */ |
||
108 | public $ldap_filter_person; |
||
109 | |||
110 | /** |
||
111 | * Authentication Service constructor |
||
112 | * |
||
113 | * @param Connection|null $dao databse |
||
114 | */ |
||
115 | 4 | public function __construct(Connection $dao = null) |
|
130 | |||
131 | /** |
||
132 | * Authenticate user again LDAP directory (Bind) |
||
133 | * 2 options : |
||
134 | * Authenticate directly with uname in the DN |
||
135 | * Authenticate with manager, search the dn |
||
136 | * |
||
137 | * @param string $uname Username |
||
138 | * @param string $pwd Password |
||
139 | * |
||
140 | * @return bool |
||
141 | */ |
||
142 | public function authenticate($uname, $pwd = null) |
||
174 | |||
175 | /** |
||
176 | * Compose the user DN with the configuration. |
||
177 | * |
||
178 | * @param string $uname username |
||
179 | * |
||
180 | * @return bool|string userDN or false |
||
181 | */ |
||
182 | public function getUserDN($uname) |
||
214 | |||
215 | /** |
||
216 | * Load user from XOOPS Database |
||
217 | * |
||
218 | * @param string $uname username |
||
219 | * |
||
220 | * @return mixed|string |
||
221 | */ |
||
222 | public function getFilter($uname) |
||
232 | |||
233 | /** |
||
234 | * loadXoopsUser |
||
235 | * |
||
236 | * @param string $userdn base DN for the directory |
||
237 | * @param string $uname username |
||
238 | * @param string $pwd pasword |
||
239 | * |
||
240 | * @return bool|XoopsUser |
||
241 | */ |
||
242 | public function loadXoopsUser($userdn, $uname, $pwd = null) |
||
256 | } |
||
257 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.