| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| 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 |
||
| 115 | private function registerSpecialAssets() |
||
| 116 | { |
||
| 117 | // Fix validation styles |
||
| 118 | $this->view->registerCss(" |
||
| 119 | .form-group.has-error .select2-selection { border-color: #dd4b39; box-shadow: none; } |
||
| 120 | .form-group.has-success .select2-selection { border-color: #00a65a; box-shadow: none; } |
||
| 121 | select.object-selector-select:not([data-select2-id]) { display: none; } |
||
| 122 | "); |
||
| 123 | $this->view->registerJs(<<<'JS' |
||
| 124 | (function( $ ){ |
||
| 125 | |||
| 126 | var originalDynamicForm = $.fn.yiiDynamicForm; |
||
| 127 | |||
| 128 | var methods = { |
||
| 129 | addItem : function(widgetOptions, e, elem) { |
||
| 130 | originalDynamicForm('addItem', widgetOptions, e, elem); |
||
| 131 | var count = elem.closest('.' + widgetOptions.widgetContainer).find(widgetOptions.widgetItem).length; |
||
| 132 | |||
| 133 | // Reinit ObjectSelectorChanger after added new item |
||
| 134 | if (count < widgetOptions.limit) { |
||
| 135 | var objectSelectorInputs = $($newclone).find('[data-object-selector-field]'); |
||
| 136 | objectSelectorInputs.each(function() { |
||
| 137 | var objectInputId = $(this).attr('id'); |
||
| 138 | var changerInputId = $(this).prev('select').attr('id'); |
||
| 139 | initObjectSelectorChanger(changerInputId, objectInputId); |
||
| 140 | $('#' + objectInputId).find('option').remove().end().val(null).trigger('change'); |
||
| 141 | }); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | }; |
||
| 145 | |||
| 146 | $.fn.yiiDynamicForm = function(method) { |
||
| 147 | if (method === 'addItem') { |
||
| 148 | return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); |
||
| 149 | } |
||
| 150 | originalDynamicForm.apply(this, arguments); |
||
| 151 | } |
||
| 152 | |||
| 153 | })(window.jQuery); |
||
| 154 | JS |
||
| 155 | ); |
||
| 156 | $this->view->registerJs(<<<JS |
||
| 157 | function initObjectSelectorChanger(changerInputId, objectInputId) { |
||
| 158 | $('#' + changerInputId).change(function(e) { |
||
| 159 | var regexID = /^(.+?)([-\d-]{1,})(.+)$/i; |
||
| 160 | var matches = objectInputId.match(regexID); |
||
| 161 | var combo = $('#' + objectInputId).closest('form').combo(); |
||
| 162 | if (combo) { |
||
| 163 | combo.register('#' + objectInputId, window[matches[1] + '_object_id_' + e.target.value]); |
||
| 164 | $('#' + objectInputId).val(null).trigger('change'); |
||
| 165 | } |
||
| 166 | }); |
||
| 167 | } |
||
| 168 | JS |
||
| 169 | ); |
||
| 170 | } |
||
| 171 | |||
| 185 |