| Conditions | 8 |
| Paths | 5 |
| Total Lines | 55 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 2 | 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; |
||
| 19 | public function input() |
||
| 20 | { |
||
| 21 | if (!$this->relation->getRelatedModel()) { |
||
| 22 | throw new \Exception('missing relation in config for the current model.'); |
||
| 23 | } |
||
| 24 | |||
| 25 | $this->fields = array_get(\View::getShared(), 'fields'); |
||
| 26 | $id = $this->fields['id']->value; |
||
| 27 | |||
| 28 | $modelName = $this->relation->getRelatedModel(); |
||
| 29 | $model = $this->modelObject->schema->models[$modelName]; |
||
| 30 | $model['class'] = $this->modelObject->schema->getClass($modelName); |
||
| 31 | $this->model = $model; |
||
| 32 | |||
| 33 | if ((Route::currentRouteName() == 'admin.model.create' || Route::currentRouteName() == 'admin.model.field') |
||
| 34 | && Session::has('_set_relation_on_create_' . $this->modelObject->name) |
||
| 35 | ) { |
||
| 36 | $relateds = Session::get('_set_relation_on_create_' . $this->modelObject->name); |
||
| 37 | |||
| 38 | $related_ids = array(); |
||
| 39 | foreach ($relateds as $related) { |
||
| 40 | $related_ids[] = $related['id']; |
||
| 41 | } |
||
| 42 | |||
| 43 | $data = $relateds[0]['modelClass']::whereIn('id', $related_ids)->get()->toArray(); |
||
| 44 | } else { |
||
| 45 | $data = $model['class']::where($this->relation->getForeignKey(), '=', $id)->get(array( |
||
| 46 | 'id', |
||
| 47 | $this->relation->getShow() |
||
| 48 | ))->toArray(); |
||
| 49 | } |
||
| 50 | |||
| 51 | $this->showItems($data); |
||
| 52 | |||
| 53 | $this->createURL = $this->createURL($this->model['route']) . "?" . http_build_query(array( |
||
| 54 | $this->relation->getForeignKey() => $id, |
||
| 55 | '_standalone' => 'true' |
||
| 56 | )); |
||
| 57 | |||
| 58 | if (!Request::ajax() || $this->showFullField) { |
||
| 59 | $this->relationModal($this->model['route'], $id); |
||
| 60 | |||
| 61 | ?> |
||
| 62 | <div class="text-right"> |
||
| 63 | <div class="btn-group"> |
||
| 64 | <button class="btn btn-default" data-toggle="modal" |
||
| 65 | data-url="<?= $this->createURL ?>" |
||
| 66 | data-target="#form-modal-<?= $this->model['route'] ?>"> |
||
| 67 | <i class="fa fa-plus"></i> |
||
| 68 | </button> |
||
| 69 | </div> |
||
| 70 | </div> |
||
| 71 | <?php |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 155 | } |