Conditions | 6 |
Paths | 32 |
Total Lines | 57 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
30 | public function run() |
||
|
|||
31 | { |
||
32 | $id = 'input_tree__' . $this->getId(); |
||
33 | $this->options['id'] = $id; |
||
34 | |||
35 | |||
36 | if ($this->hasModel()) { |
||
37 | $input = Html::activeHiddenInput($this->model, $this->attribute, $this->options); |
||
38 | $value = Html::getAttributeValue($this->model, $this->attribute); |
||
39 | } else { |
||
40 | $input = Html::hiddenInput($this->name, $this->value, $this->options); |
||
41 | $value = $this->value; |
||
42 | } |
||
43 | if (is_array($value)) { |
||
44 | $value = implode(',', $value); |
||
45 | } |
||
46 | $this->treeConfig['selectedNodes'] = $value; |
||
47 | |||
48 | $this->treeConfig['id'] = $id . '__tree'; |
||
49 | $oldOptions = isset($this->treeConfig['options']) ? $this->treeConfig['options'] : []; |
||
50 | $this->treeConfig['options'] = ArrayHelper::merge($oldOptions, [ |
||
51 | 'core' => [ |
||
52 | 'multiple' => $this->multiple, |
||
53 | 'dblclick_toggle' => false, |
||
54 | ], |
||
55 | ]); |
||
56 | $this->treeConfig['plugins'] = [ |
||
57 | 'wholerow', |
||
58 | 'contextmenu', |
||
59 | 'dnd', |
||
60 | 'types', |
||
61 | ]; |
||
62 | |||
63 | if ($this->multiple) { |
||
64 | $this->treeConfig['plugins'][] = 'checkbox'; |
||
65 | } |
||
66 | if ($this->search) { |
||
67 | $this->treeConfig['plugins'][] = 'search'; |
||
68 | $this->treeConfig['options']['search'] = [ |
||
69 | 'show_only_matches' => true, |
||
70 | ]; |
||
71 | } |
||
72 | |||
73 | return $this->render( |
||
74 | 'tree-input', |
||
75 | [ |
||
76 | 'id' => $id, |
||
77 | 'treeConfig' => $this->treeConfig, |
||
78 | 'multiple' => $this->multiple, |
||
79 | 'selectIcon' => $this->selectIcon, |
||
80 | 'selectText' => $this->selectText, |
||
81 | 'input' => $input, |
||
82 | 'clickToOpen' => $this->clickToOpen, |
||
83 | 'search' => $this->search, |
||
84 | ] |
||
85 | ); |
||
86 | } |
||
87 | } |
||
88 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.