Conditions | 12 |
Paths | 33 |
Total Lines | 38 |
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 |
||
103 | public function getOptions() |
||
104 | { |
||
105 | if ($this->connect) { |
||
106 | if (! $this->options) { |
||
107 | $this->options = collect(); |
||
108 | } else { |
||
109 | $this->options = collect($this->options); |
||
110 | } |
||
111 | $model = new $this->connect->model; |
||
112 | $get_options_query = $model; |
||
113 | if (isset($this->connect->where_key) && $this->connect->where_key) { |
||
114 | $get_options_query = $get_options_query->where($this->connect->where_key, '=', $this->connect->where_value); |
||
115 | } |
||
116 | |||
117 | if (isset($this->connect->group_by) && $this->connect->group_by) { |
||
118 | $get_options_query = $get_options_query->whereNotNull($this->connect->group_by)->groupBy([$this->connect->group_by]); |
||
119 | } |
||
120 | |||
121 | if ($get_options = $get_options_query->get()) { |
||
122 | foreach ($get_options as $get_options_value) { |
||
123 | if ($get_options_value !== null) { |
||
124 | if ($this->option_key) { |
||
125 | $this->options->put($get_options_value->{$this->option_key}, $get_options_value->{$this->option_title}); |
||
126 | } else { |
||
127 | $this->options->push($get_options_value); |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | |||
133 | if (!$this->option_key) { |
||
134 | $this->options = $this->options->pluck($this->name); |
||
135 | } |
||
136 | } else { |
||
137 | $this->options = collect($this->options); |
||
138 | } |
||
139 | |||
140 | return $this->options->unique(); |
||
141 | } |
||
166 |