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 Ads extends Ldap |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Authentication Service constructor |
||
| 31 | * |
||
| 32 | * @param Connection|null $dao database |
||
| 33 | * |
||
| 34 | * @return void |
||
|
|
|||
| 35 | */ |
||
| 36 | 2 | public function __construct(Connection $dao = null) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * Authenticate user again LDAP directory (Bind) |
||
| 43 | * 2 options : |
||
| 44 | * Authenticate directly with uname in the DN |
||
| 45 | * Authenticate with manager, search the dn |
||
| 46 | * |
||
| 47 | * @param string $uname Username |
||
| 48 | * @param string $pwd Password |
||
| 49 | * |
||
| 50 | * @return bool |
||
| 51 | */ |
||
| 52 | public function authenticate($uname, $pwd = null) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Return the UPN = userPrincipalName (Active Directory) |
||
| 99 | * userPrincipalName = [email protected] Often abbreviated to UPN, and |
||
| 100 | * looks like an email address. Very useful for logging on especially in |
||
| 101 | * a large Forest. Note UPN must be unique in the forest. |
||
| 102 | * |
||
| 103 | * @param string $uname username |
||
| 104 | * |
||
| 105 | * @return string userDN |
||
| 106 | */ |
||
| 107 | public function getUPN($uname) |
||
| 112 | } |
||
| 113 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.