| Conditions | 2 |
| Paths | 2 |
| Total Lines | 116 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 1 | Features | 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 namespace Mascame\Artificer\Fields\Types\Relations; |
||
| 53 | public function relationModal($relatedModelRouteName, $id = 0) |
||
| 54 | { |
||
| 55 | ?> |
||
| 56 | <!-- Modal --> |
||
| 57 | <div class="modal fade standalone" id="form-modal-<?= $relatedModelRouteName ?>" tabindex="-1" role="dialog" |
||
| 58 | aria-labelledby="myModalLabel" aria-hidden="true"> |
||
| 59 | <div class="modal-dialog modal-lg"> |
||
| 60 | <div class="modal-content"> |
||
| 61 | |||
| 62 | <div class="modal-header"> |
||
| 63 | <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span |
||
| 64 | class="sr-only">Close</span></button> |
||
| 65 | <h4 class="modal-title">Loading Form</h4> |
||
| 66 | </div> |
||
| 67 | |||
| 68 | <div id="modal-body-<?= $relatedModelRouteName ?>" class="modal-body"> |
||
| 69 | <div class="alert alert-info" role="alert"><i class="fa fa-circle-o-notch fa-spin"></i> Loading |
||
| 70 | </div> |
||
| 71 | </div> |
||
| 72 | |||
| 73 | <div class="hidden default-modal-body"> |
||
| 74 | <div class="alert alert-info" role="alert"><i class="fa fa-circle-o-notch fa-spin"></i> Loading |
||
| 75 | </div> |
||
| 76 | </div> |
||
| 77 | </div> |
||
| 78 | </div> |
||
| 79 | </div> |
||
| 80 | |||
| 81 | <script> |
||
| 82 | $(function () { |
||
| 83 | |||
| 84 | var $modal_<?=$relatedModelRouteName?> = $('#form-modal-<?=$relatedModelRouteName?>'); |
||
| 85 | var $modal_body_<?=$relatedModelRouteName?> = $("#modal-body-<?=$relatedModelRouteName?>"); |
||
| 86 | var url = null; |
||
| 87 | var id = '<?=$id?>'; |
||
| 88 | var $field = $('[name="<?=$this->name?>"]'); |
||
| 89 | |||
| 90 | if ($field.is("select")) { |
||
| 91 | $field.on('change', function () { |
||
| 92 | // alert( this.value ); // or $(this).val() |
||
| 93 | |||
| 94 | id = this.value; |
||
| 95 | }); |
||
| 96 | } |
||
| 97 | |||
| 98 | $modal_<?=$relatedModelRouteName?>.on('show.bs.modal', function (e) { |
||
| 99 | url = $(e.relatedTarget).data('url'); |
||
| 100 | url = url.replace(':id:', id); |
||
| 101 | // url += " .right-side"; |
||
| 102 | }); |
||
| 103 | |||
| 104 | $modal_<?=$relatedModelRouteName?>.on('shown.bs.modal', function () { |
||
| 105 | $modal_body_<?=$relatedModelRouteName?>.load(url, function () { |
||
| 106 | var title = $modal_body_<?=$relatedModelRouteName?>.find('h1').html(); |
||
| 107 | |||
| 108 | $('.modal-title').html(title); |
||
| 109 | |||
| 110 | var $form = $modal_body_<?=$relatedModelRouteName?>.find('form'); |
||
| 111 | // $form.attr('action', url); |
||
| 112 | // $form.attr('method', 'POST'); |
||
| 113 | $form.prepend('<input type="hidden" name="_standalone" value="<?=$relatedModelRouteName?>">'); |
||
| 114 | $form.prepend('<input type="hidden" name="_standalone_origin" value="<?=$this->modelObject->getRouteName(Model::$current)?>">'); |
||
| 115 | $form.prepend('<input type="hidden" name="_standalone_origin_id" value="<?=$id?>">'); |
||
| 116 | |||
| 117 | <?php if (Route::currentRouteName() == 'admin.model.create') { ?> |
||
| 118 | $form.prepend('<input type="hidden" name="_set_relation_on_create" value="<?=Model::getCurrent()?>">'); |
||
| 119 | $form.prepend('<input type="hidden" name="_set_relation_on_create_foreign" value="<?=$this->relation->getForeignKey()?>">'); |
||
|
|
|||
| 120 | <?php } ?> |
||
| 121 | |||
| 122 | var action = $form.attr('action'); |
||
| 123 | |||
| 124 | $form.submit(function (e) { |
||
| 125 | e.preventDefault(); |
||
| 126 | $.post(action, $form.serialize(), function (data) { |
||
| 127 | |||
| 128 | if (typeof data === 'string') { |
||
| 129 | // validation errors |
||
| 130 | $modal_body_<?=$relatedModelRouteName?>.html(data); |
||
| 131 | } else if (typeof data === 'object') { |
||
| 132 | refreshRelation(data, '<?=$this->name?>'); |
||
| 133 | $modal_<?=$relatedModelRouteName?>.modal('hide'); |
||
| 134 | } else { |
||
| 135 | alert('Something is wrong.'); |
||
| 136 | } |
||
| 137 | }); |
||
| 138 | }); |
||
| 139 | }); |
||
| 140 | }); |
||
| 141 | |||
| 142 | $modal_<?=$relatedModelRouteName?>.on('hidden.bs.modal', function (e) { |
||
| 143 | $modal_body_<?=$relatedModelRouteName?>.empty(); |
||
| 144 | $modal_body_<?=$relatedModelRouteName?>.html($('.default-modal-body').html()) |
||
| 145 | }); |
||
| 146 | |||
| 147 | function refreshRelation(data, name) { |
||
| 148 | var $relation = $('[name="' + name + '"]'); |
||
| 149 | var url = data.refresh; |
||
| 150 | |||
| 151 | url = url.replace(':fieldName:', name); |
||
| 152 | |||
| 153 | // After this call this whole modal will disappear |
||
| 154 | $relation.parent('.form-group').load(url, function (responseText, textStatus, req) { |
||
| 155 | if (textStatus == "error") { |
||
| 156 | return "oh noes!!!!"; |
||
| 157 | } else { |
||
| 158 | $("body").trigger("relationRefresh", { |
||
| 159 | name: name, |
||
| 160 | id: id |
||
| 161 | }); |
||
| 162 | } |
||
| 163 | }); |
||
| 164 | } |
||
| 165 | }); |
||
| 166 | </script> |
||
| 167 | <?php |
||
| 168 | } |
||
| 169 | } |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.