| 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 |
||
| 96 | private function registerSpecialAssets() |
||
| 97 | { |
||
| 98 | // Fix validation styles |
||
| 99 | $this->view->registerCss(" |
||
| 100 | .form-group.has-error .select2-selection { border-color: #dd4b39; box-shadow: none; } |
||
| 101 | .form-group.has-success .select2-selection { border-color: #00a65a; box-shadow: none; } |
||
| 102 | select.object-selector-select:not([data-select2-id]) { display: none; } |
||
| 103 | "); |
||
| 104 | $this->view->registerJs(<<<'JS' |
||
| 105 | (function( $ ){ |
||
| 106 | |||
| 107 | var originalDynamicForm = $.fn.yiiDynamicForm; |
||
| 108 | |||
| 109 | var methods = { |
||
| 110 | addItem : function(widgetOptions, e, elem) { |
||
| 111 | originalDynamicForm('addItem', widgetOptions, e, elem); |
||
| 112 | var count = elem.closest('.' + widgetOptions.widgetContainer).find(widgetOptions.widgetItem).length; |
||
| 113 | |||
| 114 | // Reinit ObjectSelectorChanger after added new item |
||
| 115 | if (count < widgetOptions.limit) { |
||
| 116 | var objectSelectorInputs = $($newclone).find('[data-object-selector-field]'); |
||
| 117 | objectSelectorInputs.each(function() { |
||
| 118 | var objectInputId = $(this).attr('id'); |
||
| 119 | var changerInputId = $(this).prev('select').attr('id'); |
||
| 120 | initObjectSelectorChanger(changerInputId, objectInputId); |
||
| 121 | }); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | }; |
||
| 125 | |||
| 126 | $.fn.yiiDynamicForm = function(method) { |
||
| 127 | if (method === 'addItem') { |
||
| 128 | return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); |
||
| 129 | } else { |
||
| 130 | originalDynamicForm.apply(this, arguments); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | })(window.jQuery); |
||
| 135 | JS |
||
| 136 | ); |
||
| 137 | $this->view->registerJs(<<<JS |
||
| 138 | function initObjectSelectorChanger(changerInputId, objectInputId) { |
||
| 139 | $('#' + changerInputId).change(function(e) { |
||
| 140 | var regexID = /^(.+?)([-\d-]{1,})(.+)$/i; |
||
| 141 | var matches = objectInputId.match(regexID); |
||
| 142 | var combo = $('#' + objectInputId).closest('form').combo(); |
||
| 143 | if (combo) { |
||
| 144 | combo.register('#' + objectInputId, window[matches[1] + '_object_id_' + e.target.value]); |
||
| 145 | $('#' + objectInputId).val(null).trigger('change'); |
||
| 146 | } |
||
| 147 | }); |
||
| 148 | } |
||
| 149 | JS |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | } |
||
| 153 |