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 |
||
| 17 | class MultiAction extends Column |
||
| 18 | { |
||
| 19 | use Traits\TButtonTryAddIcon; |
||
| 20 | use Traits\TButtonIcon; |
||
| 21 | use Traits\TButtonClass; |
||
| 22 | use Traits\TButtonTitle; |
||
| 23 | use Traits\TButtonText; |
||
| 24 | use Traits\TButtonCaret; |
||
| 25 | use Traits\TLink; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var DataGrid |
||
| 29 | */ |
||
| 30 | protected $grid; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $name; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | protected $actions = []; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var callable[] |
||
| 44 | */ |
||
| 45 | private $rowConditions = []; |
||
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * @param DataGrid $grid |
||
| 50 | */ |
||
| 51 | public function __construct(DataGrid $grid, $name) |
||
| 58 | |||
| 59 | |||
| 60 | /** |
||
| 61 | * @return Html |
||
| 62 | */ |
||
| 63 | public function renderButton() |
||
| 92 | |||
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $key |
||
| 96 | * @param string $name |
||
| 97 | * @param string $href |
||
| 98 | * @param array|null $params |
||
| 99 | * @return static |
||
| 100 | */ |
||
| 101 | public function addAction($key, $name, $href = null, array $params = null) |
||
| 123 | |||
| 124 | |||
| 125 | /** |
||
| 126 | * @return Action[] |
||
| 127 | */ |
||
| 128 | public function getActions() |
||
| 132 | |||
| 133 | |||
| 134 | /** |
||
| 135 | * @param string $key |
||
| 136 | * @return Action |
||
| 137 | */ |
||
| 138 | View Code Duplication | public function getAction($key) |
|
| 148 | |||
| 149 | |||
| 150 | /** |
||
| 151 | * Column can have variables that will be passed to custom template scope |
||
| 152 | * @return array |
||
| 153 | */ |
||
| 154 | public function getTemplateVariables() |
||
| 160 | |||
| 161 | |||
| 162 | /** |
||
| 163 | * @param string $actionKey |
||
| 164 | * @param callable $rowCondition |
||
| 165 | * @return void |
||
| 166 | */ |
||
| 167 | public function setRowCondition($actionKey, callable $rowCondition) |
||
| 171 | |||
| 172 | |||
| 173 | /** |
||
| 174 | * @param string $actionKey |
||
| 175 | * @param Row $row |
||
| 176 | * @return bool |
||
| 177 | */ |
||
| 178 | public function testRowCondition($actionKey, Row $row) |
||
| 186 | } |
||
| 187 |