Conditions | 6 |
Paths | 18 |
Total Lines | 55 |
Code Lines | 23 |
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 |
||
132 | protected function proposedOptions(array $userOptions): array |
||
133 | { |
||
134 | $source = $this->definition->sourceContext(); |
||
135 | |||
136 | $proposed = [ |
||
137 | //Relation name |
||
138 | 'relation:name' => $this->definition->getName(), |
||
139 | |||
140 | //Relation name in plural form |
||
141 | 'relation:plural' => Inflector::pluralize($this->definition->getName()), |
||
142 | |||
143 | //Relation name in singular form |
||
144 | 'relation:singular' => Inflector::singularize($this->definition->getName()), |
||
145 | |||
146 | //Parent record role name |
||
147 | 'source:role' => $source->getRole(), |
||
148 | |||
149 | //Parent record table name |
||
150 | 'source:table' => $source->getTable(), |
||
151 | |||
152 | //Parent record primary key |
||
153 | 'source:primaryKey' => !empty($source->getPrimary()) ? $source->getPrimary()->getName() : '', |
||
154 | ]; |
||
155 | |||
156 | //Some options may use values declared in other definition fields |
||
157 | $aliases = [ |
||
158 | Record::OUTER_KEY => 'outerKey', |
||
159 | Record::INNER_KEY => 'innerKey', |
||
160 | Record::PIVOT_TABLE => 'pivotTable', |
||
161 | ]; |
||
162 | |||
163 | foreach ($aliases as $property => $alias) { |
||
164 | if (isset($userOptions[$property])) { |
||
165 | //Let's create some default options based on user specified values |
||
166 | $proposed['option:' . $alias] = $userOptions[$property]; |
||
167 | } |
||
168 | } |
||
169 | |||
170 | if (!empty($this->definition->targetContext())) { |
||
171 | $target = $this->definition->targetContext(); |
||
172 | |||
173 | $proposed = $proposed + [ |
||
174 | //Outer role name |
||
175 | 'target:role' => $target->getRole(), |
||
176 | |||
177 | //Outer record table |
||
178 | 'target:table' => $target->getTable(), |
||
179 | |||
180 | //Outer record primary key |
||
181 | 'target:primaryKey' => !empty($target->getPrimary()) ? $target->getPrimary()->getName() : '', |
||
182 | ]; |
||
183 | } |
||
184 | |||
185 | return $proposed; |
||
186 | } |
||
187 | } |