Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
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 |
||
153 | public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { |
||
154 | $fields = parent::baseFieldDefinitions($entity_type); |
||
155 | |||
156 | $fields['user_id'] = BaseFieldDefinition::create('entity_reference') |
||
157 | ->setLabel(t('Authored by')) |
||
158 | ->setDescription(t('The user ID of author of the Event template entity.')) |
||
159 | ->setRevisionable(TRUE) |
||
160 | ->setSetting('target_type', 'user') |
||
161 | ->setSetting('handler', 'default') |
||
162 | ->setTranslatable(TRUE) |
||
163 | ->setDisplayOptions('view', array( |
||
164 | 'label' => 'hidden', |
||
165 | 'type' => 'author', |
||
166 | 'weight' => 0, |
||
167 | )) |
||
168 | ->setDisplayOptions('form', array( |
||
169 | 'type' => 'entity_reference_autocomplete', |
||
170 | 'weight' => 5, |
||
171 | 'settings' => array( |
||
172 | 'match_operator' => 'CONTAINS', |
||
173 | 'size' => '60', |
||
174 | 'autocomplete_type' => 'tags', |
||
175 | 'placeholder' => '', |
||
176 | ), |
||
177 | )) |
||
178 | ->setDisplayConfigurable('form', TRUE) |
||
179 | ->setDisplayConfigurable('view', TRUE); |
||
180 | |||
181 | $fields['name'] = BaseFieldDefinition::create('string') |
||
182 | ->setLabel(t('Name')) |
||
183 | ->setDescription(t('The name of the Event template entity.')) |
||
184 | ->setSettings(array( |
||
185 | 'max_length' => 50, |
||
186 | 'text_processing' => 0, |
||
187 | )) |
||
188 | ->setDefaultValue('') |
||
189 | ->setDisplayOptions('view', array( |
||
190 | 'label' => 'above', |
||
191 | 'type' => 'string', |
||
192 | 'weight' => -4, |
||
193 | )) |
||
194 | ->setDisplayOptions('form', array( |
||
195 | 'type' => 'string_textfield', |
||
196 | 'weight' => -4, |
||
197 | )) |
||
198 | ->setDisplayConfigurable('form', TRUE) |
||
199 | ->setDisplayConfigurable('view', TRUE); |
||
200 | |||
201 | $fields['status'] = BaseFieldDefinition::create('boolean') |
||
202 | ->setLabel(t('Publishing status')) |
||
203 | ->setDescription(t('A boolean indicating whether the Event template is published.')) |
||
204 | ->setDefaultValue(TRUE); |
||
205 | |||
206 | $fields['created'] = BaseFieldDefinition::create('created') |
||
207 | ->setLabel(t('Created')) |
||
208 | ->setDescription(t('The time that the entity was created.')); |
||
209 | |||
210 | $fields['changed'] = BaseFieldDefinition::create('changed') |
||
211 | ->setLabel(t('Changed')) |
||
212 | ->setDescription(t('The time that the entity was last edited.')); |
||
213 | |||
214 | return $fields; |
||
215 | } |
||
216 | |||
218 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.