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 |
||
| 40 | class GroupsController extends Controller { |
||
| 41 | /** @var IGroupManager */ |
||
| 42 | private $groupManager; |
||
| 43 | /** @var IL10N */ |
||
| 44 | private $l10n; |
||
| 45 | /** @var IUserSession */ |
||
| 46 | private $userSession; |
||
| 47 | /** @var bool */ |
||
| 48 | private $isAdmin; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $appName |
||
| 52 | * @param IRequest $request |
||
| 53 | * @param IGroupManager $groupManager |
||
| 54 | * @param IUserSession $userSession |
||
| 55 | * @param bool $isAdmin |
||
| 56 | * @param IL10N $l10n |
||
| 57 | */ |
||
| 58 | View Code Duplication | public function __construct($appName, |
|
| 59 | IRequest $request, |
||
| 60 | IGroupManager $groupManager, |
||
| 61 | IUserSession $userSession, |
||
| 62 | $isAdmin, |
||
| 63 | IL10N $l10n) { |
||
| 64 | parent::__construct($appName, $request); |
||
| 65 | $this->groupManager = $groupManager; |
||
| 66 | $this->userSession = $userSession; |
||
| 67 | $this->isAdmin = $isAdmin; |
||
| 68 | $this->l10n = $l10n; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @NoAdminRequired |
||
| 73 | * |
||
| 74 | * @param string $pattern |
||
| 75 | * @param bool $filterGroups |
||
| 76 | * @param int $sortGroups |
||
| 77 | * @return DataResponse |
||
| 78 | */ |
||
| 79 | public function index($pattern = '', $filterGroups = false, $sortGroups = MetaData::SORT_USERCOUNT) { |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @PasswordConfirmationRequired |
||
| 100 | * @param string $id |
||
| 101 | * @return DataResponse |
||
| 102 | */ |
||
| 103 | public function create($id) { |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @PasswordConfirmationRequired |
||
| 130 | * @param string $id |
||
| 131 | * @return DataResponse |
||
| 132 | */ |
||
| 133 | public function destroy($id) { |
||
| 156 | |||
| 157 | } |
||
| 158 |