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 |
||
| 25 | abstract class AuthAbstract |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var use Xoops\Core\Database\Connection|null |
||
| 29 | */ |
||
| 30 | protected $dao; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | protected $errors; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $auth_method; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Authentication Service constructor |
||
| 44 | * |
||
| 45 | * @param \Xoops\Core\Database\Connection|null $dao database |
||
| 46 | */ |
||
| 47 | 12 | public function __construct($dao) |
|
| 51 | |||
| 52 | /** |
||
| 53 | * authenticate a user |
||
| 54 | * |
||
| 55 | * @param string $uname user name |
||
| 56 | * @param string|null $pwd password |
||
| 57 | * |
||
| 58 | * @return bool true if authenticated, otherwise fales |
||
| 59 | */ |
||
| 60 | abstract public function authenticate($uname, $pwd = null); |
||
| 61 | |||
| 62 | /** |
||
| 63 | * setErrors |
||
| 64 | * |
||
| 65 | * @param int $err_no error number |
||
| 66 | * @param string $err_str error message |
||
| 67 | * |
||
| 68 | * @return void |
||
| 69 | */ |
||
| 70 | 4 | public function setErrors($err_no, $err_str) |
|
| 74 | |||
| 75 | /** |
||
| 76 | * return the errors for this object as an array |
||
| 77 | * |
||
| 78 | * @return array an array of errors |
||
| 79 | */ |
||
| 80 | 1 | public function getErrors() |
|
| 84 | |||
| 85 | /** |
||
| 86 | * return the errors for this object as html |
||
| 87 | * |
||
| 88 | * @return string html listing the errors |
||
| 89 | */ |
||
| 90 | 1 | public function getHtmlErrors() |
|
| 108 | } |
||
| 109 |