| Conditions | 1 |
| Paths | 1 |
| Total Lines | 116 |
| Code Lines | 87 |
| 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 |
||
| 202 | public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { |
||
| 203 | $fields = []; |
||
| 204 | |||
| 205 | $fields['cid'] = BaseFieldDefinition::create('integer') |
||
| 206 | ->setLabel(t('Crop ID')) |
||
| 207 | ->setDescription(t('The crop ID.')) |
||
| 208 | ->setReadOnly(TRUE) |
||
| 209 | ->setSetting('unsigned', TRUE); |
||
| 210 | |||
| 211 | $fields['uuid'] = BaseFieldDefinition::create('uuid') |
||
| 212 | ->setLabel(t('UUID')) |
||
| 213 | ->setDescription(t('The crop UUID.')) |
||
| 214 | ->setReadOnly(TRUE); |
||
| 215 | |||
| 216 | $fields['vid'] = BaseFieldDefinition::create('integer') |
||
| 217 | ->setLabel(t('Revision ID')) |
||
| 218 | ->setDescription(t('The crop revision ID.')) |
||
| 219 | ->setReadOnly(TRUE) |
||
| 220 | ->setSetting('unsigned', TRUE); |
||
| 221 | |||
| 222 | $fields['type'] = BaseFieldDefinition::create('entity_reference') |
||
| 223 | ->setLabel(t('Type')) |
||
| 224 | ->setDescription(t('The crop type.')) |
||
| 225 | ->setSetting('target_type', 'crop_type') |
||
| 226 | ->setReadOnly(TRUE); |
||
| 227 | |||
| 228 | $fields['langcode'] = BaseFieldDefinition::create('language') |
||
| 229 | ->setLabel(t('Language code')) |
||
| 230 | ->setDescription(t('The node language code.')) |
||
| 231 | ->setRevisionable(TRUE); |
||
| 232 | |||
| 233 | $fields['entity_id'] = BaseFieldDefinition::create('integer') |
||
| 234 | ->setLabel(t('Entity ID')) |
||
| 235 | ->setDescription(t('ID of entity crop belongs to.')) |
||
| 236 | ->setSetting('unsigned', TRUE) |
||
| 237 | ->setRevisionable(TRUE) |
||
| 238 | ->setReadOnly(TRUE); |
||
| 239 | |||
| 240 | $fields['entity_type'] = BaseFieldDefinition::create('string') |
||
| 241 | ->setLabel(t('Entity type')) |
||
| 242 | ->setDescription(t('The type of entity crop belongs to.')) |
||
| 243 | ->setRevisionable(TRUE) |
||
| 244 | ->setReadOnly(TRUE); |
||
| 245 | |||
| 246 | // Denormalized information, which is calculated in storage plugin for a |
||
| 247 | // given entity type. Saved here for performance reasons in image effects. |
||
| 248 | // --- |
||
| 249 | // TODO - we are not enforcing uniqueness on this as we want to support more |
||
| 250 | // crops per same image/image_style combination. However, image effect |
||
| 251 | // operates with image URI only, which means we have no mechanism to |
||
| 252 | // distinguish between multiple crops in there. If we really want to |
||
| 253 | // support multiple crops we'll need to override core at least, |
||
| 254 | // in \Drupal\Core\Image\ImageFactory and \Drupal\Core\Image\Image. |
||
| 255 | // Let's leave this for now and simply load based on URI only. |
||
| 256 | // We can use some semi-smart approach in case there are multiple crops |
||
| 257 | // with same URI for now (first created, last created, ...). |
||
| 258 | $fields['uri'] = BaseFieldDefinition::create('uri') |
||
| 259 | ->setLabel(t('URI')) |
||
| 260 | ->setDescription(t('The URI of the image crop belongs to.')) |
||
| 261 | ->setRevisionable(TRUE) |
||
| 262 | ->setTranslatable(TRUE) |
||
| 263 | ->setSetting('max_length', 255); |
||
| 264 | |||
| 265 | $fields['height'] = BaseFieldDefinition::create('integer') |
||
| 266 | ->setLabel(t('Height')) |
||
| 267 | ->setDescription(t('The crop height.')) |
||
| 268 | ->setRevisionable(TRUE) |
||
| 269 | ->setTranslatable(TRUE) |
||
| 270 | ->setReadOnly(TRUE) |
||
| 271 | ->setSetting('unsigned', TRUE); |
||
| 272 | |||
| 273 | $fields['width'] = BaseFieldDefinition::create('integer') |
||
| 274 | ->setLabel(t('Width')) |
||
| 275 | ->setDescription(t('The crop width.')) |
||
| 276 | ->setRevisionable(TRUE) |
||
| 277 | ->setTranslatable(TRUE) |
||
| 278 | ->setReadOnly(TRUE) |
||
| 279 | ->setSetting('unsigned', TRUE); |
||
| 280 | |||
| 281 | $fields['x'] = BaseFieldDefinition::create('integer') |
||
| 282 | ->setLabel(t('X coordinate')) |
||
| 283 | ->setDescription(t("The crop's X coordinate.")) |
||
| 284 | ->setRevisionable(TRUE) |
||
| 285 | ->setTranslatable(TRUE) |
||
| 286 | ->setReadOnly(TRUE) |
||
| 287 | ->setSetting('unsigned', TRUE); |
||
| 288 | |||
| 289 | $fields['y'] = BaseFieldDefinition::create('integer') |
||
| 290 | ->setLabel(t('Y coordinate')) |
||
| 291 | ->setDescription(t("The crop's Y coordinate.")) |
||
| 292 | ->setRevisionable(TRUE) |
||
| 293 | ->setTranslatable(TRUE) |
||
| 294 | ->setReadOnly(TRUE) |
||
| 295 | ->setSetting('unsigned', TRUE); |
||
| 296 | |||
| 297 | $fields['revision_timestamp'] = BaseFieldDefinition::create('created') |
||
| 298 | ->setLabel(t('Revision timestamp')) |
||
| 299 | ->setDescription(t('The time that the current revision was created.')) |
||
| 300 | ->setQueryable(FALSE) |
||
| 301 | ->setRevisionable(TRUE); |
||
| 302 | |||
| 303 | $fields['revision_uid'] = BaseFieldDefinition::create('entity_reference') |
||
| 304 | ->setLabel(t('Revision author ID')) |
||
| 305 | ->setDescription(t('The user ID of the author of the current revision.')) |
||
| 306 | ->setSetting('target_type', 'user') |
||
| 307 | ->setQueryable(FALSE) |
||
| 308 | ->setRevisionable(TRUE); |
||
| 309 | |||
| 310 | $fields['revision_log'] = BaseFieldDefinition::create('string_long') |
||
| 311 | ->setLabel(t('Revision Log')) |
||
| 312 | ->setDescription(t('The log entry explaining the changes in this revision.')) |
||
| 313 | ->setRevisionable(TRUE) |
||
| 314 | ->setTranslatable(TRUE); |
||
| 315 | |||
| 316 | return $fields; |
||
| 317 | } |
||
| 318 | |||
| 320 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: