Conditions | 9 |
Paths | 8 |
Total Lines | 80 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | 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 declare(strict_types=1); |
||
86 | public function editable($value, Field $field, HTMLNode $previous): HTMLNode |
||
87 | { |
||
88 | $previous = $this->_editable($value, $field, $previous); |
||
89 | |||
90 | /* |
||
91 | * init variables |
||
92 | */ |
||
93 | $inflector = InflectorFactory::create()->build(); |
||
|
|||
94 | /** |
||
95 | * @var VueFramework $vue |
||
96 | */ |
||
97 | $vue = $this->framework; |
||
98 | $vueCode = $vue->getVueCode(); |
||
99 | $mvar = $vueCode->getFieldModelVariable(); |
||
100 | /** |
||
101 | * @var Datatype_relationship $datatype |
||
102 | */ |
||
103 | $datatype = $field->getDatatype(); |
||
104 | |||
105 | if ($datatype->isMorph()) { |
||
106 | // TODO |
||
107 | return $previous; |
||
108 | } |
||
109 | |||
110 | // @phpstan-ignore-next-line |
||
111 | $targetModel = call_user_func($datatype->getTargetClass() . '::getFormularium'); |
||
112 | if ($targetModel === false) { |
||
113 | throw new ClassNotFoundException("Cannot find model " . $datatype->getTarget()); |
||
114 | } |
||
115 | /** |
||
116 | * @var \Formularium\Model $targetModel |
||
117 | */ |
||
118 | |||
119 | // get the title field |
||
120 | $titleField = $targetModel->firstField( |
||
121 | function (Field $field) { |
||
122 | return $field->getRenderable('title', false); |
||
123 | } |
||
124 | ); |
||
125 | // get the title field |
||
126 | $queryField = $titleField; |
||
127 | |||
128 | // import graphql query |
||
129 | $query = 'relationList' . $targetModel->getName() . 'Query'; |
||
130 | $targetStudly = Str::studly($datatype->getTarget()); |
||
131 | $vueCode->appendImport($query, "raw-loader!../" . $targetStudly . "/queryList.graphql"); |
||
132 | $vueCode->appendExtraData($query, $query); |
||
133 | |||
134 | $relationship = $datatype->getRelationship(); |
||
135 | if ($relationship === RelationshipFactory::RELATIONSHIP_MANY_TO_MANY || |
||
136 | $relationship === RelationshipFactory::MORPH_MANY_TO_MANY |
||
137 | // TODO: inverses 1:n? |
||
138 | ) { |
||
139 | $component = 'RelationshipMultiple'; |
||
140 | } elseif ($field->getRenderable('relationshipSelect', false)) { // TODO: document |
||
141 | $component = 'RelationshipSelect'; |
||
142 | } else { |
||
143 | $component = 'RelationshipAutocomplete'; |
||
144 | } |
||
145 | |||
146 | // replace the <select> with our component |
||
147 | foreach (array_merge($previous->get('select'), $previous->get('input')) as $input) { |
||
148 | $classes = $input->getAttribute('class'); |
||
149 | $input->setTag($component) |
||
150 | ->setAttributes( |
||
151 | [ |
||
152 | 'name' => $field->getName(), |
||
153 | 'htmlClass' => $classes, |
||
154 | 'class' => '', |
||
155 | 'titleField' => ($titleField ? $titleField->getName() : 'id'), |
||
156 | 'queryField' => ($queryField ? $queryField->getName() : 'id'), |
||
157 | ':query' => $query, |
||
158 | 'targetType' => $datatype->getTarget(), |
||
159 | 'targetTypePlural' => $datatype->getTargetPlural(), |
||
160 | 'v-model' => $mvar . $field->getName() |
||
161 | ] |
||
162 | ); |
||
163 | } |
||
164 | |||
165 | return $previous; |
||
166 | } |
||
168 |