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 |
||
| 29 | class Feed extends Controller { |
||
| 30 | const DEFAULT_PAGE_SIZE = 30; |
||
| 31 | |||
| 32 | /** @var \OCA\Activity\Data */ |
||
| 33 | protected $data; |
||
| 34 | |||
| 35 | /** @var \OCA\Activity\GroupHelper */ |
||
| 36 | protected $helper; |
||
| 37 | |||
| 38 | /** @var \OCA\Activity\UserSettings */ |
||
| 39 | protected $settings; |
||
| 40 | |||
| 41 | /** @var IURLGenerator */ |
||
| 42 | protected $urlGenerator; |
||
| 43 | |||
| 44 | /** @var IManager */ |
||
| 45 | protected $activityManager; |
||
| 46 | |||
| 47 | /** @var IConfig */ |
||
| 48 | protected $config; |
||
| 49 | |||
| 50 | /** @var IFactory */ |
||
| 51 | protected $l10nFactory; |
||
| 52 | |||
| 53 | /** @var IL10N */ |
||
| 54 | protected $l; |
||
| 55 | |||
| 56 | /** @var string */ |
||
| 57 | protected $user; |
||
| 58 | |||
| 59 | /** @var string */ |
||
| 60 | protected $tokenUser; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * constructor of the controller |
||
| 64 | * |
||
| 65 | * @param string $appName |
||
| 66 | * @param IRequest $request |
||
| 67 | * @param Data $data |
||
| 68 | * @param GroupHelper $helper |
||
| 69 | * @param UserSettings $settings |
||
| 70 | * @param IURLGenerator $urlGenerator |
||
| 71 | * @param IManager $activityManager |
||
| 72 | * @param IFactory $l10nFactory |
||
| 73 | * @param IConfig $config |
||
| 74 | * @param string $user |
||
| 75 | */ |
||
| 76 | 5 | View Code Duplication | public function __construct($appName, |
|
|
|||
| 77 | IRequest $request, |
||
| 78 | Data $data, |
||
| 79 | GroupHelper $helper, |
||
| 80 | UserSettings $settings, |
||
| 81 | IURLGenerator $urlGenerator, |
||
| 82 | IManager $activityManager, |
||
| 83 | IFactory $l10nFactory, |
||
| 84 | 4 | IConfig $config, |
|
| 85 | $user) { |
||
| 86 | 5 | parent::__construct($appName, $request); |
|
| 87 | 5 | $this->data = $data; |
|
| 88 | 5 | $this->helper = $helper; |
|
| 89 | 5 | $this->settings = $settings; |
|
| 90 | 5 | $this->urlGenerator = $urlGenerator; |
|
| 91 | 5 | $this->activityManager = $activityManager; |
|
| 92 | 5 | $this->l10nFactory = $l10nFactory; |
|
| 93 | 5 | $this->config = $config; |
|
| 94 | 5 | $this->user = $user; |
|
| 95 | 5 | } |
|
| 96 | |||
| 97 | /** |
||
| 98 | * @PublicPage |
||
| 99 | * @NoCSRFRequired |
||
| 100 | * |
||
| 101 | * @return TemplateResponse |
||
| 102 | */ |
||
| 103 | 4 | public function show() { |
|
| 156 | } |
||
| 157 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.