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 |
||
19 | class DetailView extends \kartik\detail\DetailView |
||
20 | { |
||
21 | use WidgetTrait; |
||
22 | const DEFAULT_BUTTONS_TEMPLATE = '{save} {apply} {cancel}'; |
||
23 | const All_BUTTONS_TEMPLATE = '{check} {save} {apply} {cancel}'; |
||
24 | public $uniqueId = null; |
||
25 | public $action = null; |
||
26 | public $buttonsTemplate = self::DEFAULT_BUTTONS_TEMPLATE; |
||
27 | public $saveButton = '<input type="submit" name="save" value="Отправить" class="btn btn-primary" href="" title="Сохранить и вернуться">'; |
||
28 | public $checkButton = '<input type="submit" name="check" value="Проверить" class="btn btn-info" href="" title="Проверить">'; |
||
29 | public $applyButton = '<input type="submit" name="apply" value="Применить" class="btn btn-primary" href="" title="Сохранить изменения">'; |
||
30 | public $cancelButton = '<a class="btn btn-default" href="{backUrl}">Вернуться к списку</a>'; |
||
31 | public $backUrl = null; |
||
32 | public $alertBlockAddon = null; |
||
33 | |||
34 | public function __construct($config = []) |
||
35 | { |
||
36 | $config = ArrayHelper::merge([ |
||
37 | 'panel'=> false, |
||
38 | // [ |
||
|
|||
39 | // 'heading'=> '', |
||
40 | // 'footer' => ' {buttons}', |
||
41 | //// 'type'=>\kartik\detail\DetailView::TYPE_PRIMARY, |
||
42 | // 'headingOptions' => [ |
||
43 | // 'template' => '' |
||
44 | // ], |
||
45 | // 'footerOptions' => [ |
||
46 | // 'style' => 'height: 31px', |
||
47 | // ], |
||
48 | // ], |
||
49 | 'buttons1' => '', |
||
50 | 'buttonContainer' => [ |
||
51 | 'class' => 'buttons-container', |
||
52 | ], |
||
53 | 'mainTemplate' => $this->renderAlertBlock() . '{detail}{buttons}', |
||
54 | 'bordered' => true, |
||
55 | 'striped' => true, |
||
56 | 'condensed' => true, |
||
57 | 'responsive' => false, |
||
58 | 'hideIfEmpty' => true, |
||
59 | 'hover' => true, |
||
60 | // 'hAlign'=> true, |
||
61 | // 'vAlign'=> true, |
||
62 | // 'fadeDelay'=> 2000, |
||
63 | // 'container' => ['id'=>'kv-demo'], |
||
64 | 'formOptions' => [ |
||
65 | 'enableAjaxValidation' => false, |
||
66 | 'validateOnChange' => false, |
||
67 | 'validateOnSubmit' => false, |
||
68 | 'validateOnBlur' => false, |
||
69 | 'options' => [ |
||
70 | 'enctype'=>'multipart/form-data', |
||
71 | ], |
||
72 | ], |
||
73 | ], $config); |
||
74 | |||
75 | parent::__construct($config); |
||
76 | } |
||
77 | |||
78 | public function run() { |
||
89 | |||
90 | public function init() |
||
105 | |||
106 | protected function getAction() { |
||
116 | |||
117 | public function runWidget() |
||
122 | |||
123 | /** |
||
124 | * Initializes and renders alert container block |
||
125 | */ |
||
126 | View Code Duplication | protected function renderAlertBlock() |
|
156 | |||
157 | /** |
||
158 | * @param $cancelUrl |
||
159 | * @return string |
||
160 | */ |
||
161 | public function renderSubmitButtons() |
||
190 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.