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