| Conditions | 1 |
| Paths | 1 |
| Total Lines | 82 |
| Code Lines | 66 |
| 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 |
||
| 24 | public static function getMapping(): array |
||
| 25 | { |
||
| 26 | $rating = (new Mapping(ObjectType::ID)) |
||
| 27 | ->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_TRUE) |
||
| 28 | ->setProperties([ |
||
| 29 | 'overall' => new Mapping(FloatType::ID), |
||
| 30 | 'month' => new Mapping(FloatType::ID), |
||
| 31 | 'year' => new Mapping(FloatType::ID) |
||
| 32 | ]); |
||
| 33 | $id = (new Mapping(IntegerType::ID))->setParameter(IndexParameter::ID, false); |
||
| 34 | $title = (new Mapping(TextType::ID))->setParameter(IndexOptionsParameter::ID, IndexOptionsParameter::VALUE_OFFSETS); |
||
| 35 | $name = (new Mapping(TextType::ID))->setParameter(IndexOptionsParameter::ID, IndexOptionsParameter::VALUE_OFFSETS); |
||
| 36 | $department = (new Mapping(NestedType::ID)) |
||
| 37 | ->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_FALSE) |
||
| 38 | ->setProperties([ |
||
| 39 | 'id' => $id, |
||
| 40 | 'title' => $title |
||
| 41 | ]); |
||
| 42 | $employee = (new Mapping(NestedType::ID)) |
||
| 43 | ->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_FALSE) |
||
| 44 | ->setProperties([ |
||
| 45 | 'id' => $id, |
||
| 46 | 'firstName' => $name, |
||
| 47 | 'middleName' => $name, |
||
| 48 | 'lastName' => $name, |
||
| 49 | 'joinedAt' => (new Mapping(DateType::ID)) |
||
| 50 | ]); |
||
| 51 | $manager = Mapping::from($employee) |
||
| 52 | ->removeProperty('joinedAt') |
||
| 53 | ->setProperty( |
||
| 54 | 'capabilities', |
||
| 55 | (new Mapping(KeywordType::ID)) |
||
| 56 | ->setParameter(DocValuesParameter::ID, true) |
||
| 57 | ); |
||
| 58 | $organization = (new Mapping(NestedType::ID)) |
||
| 59 | ->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_FALSE) |
||
| 60 | ->setProperties([ |
||
| 61 | 'id' => $id, |
||
| 62 | 'title' => $title |
||
| 63 | ]); |
||
| 64 | |||
| 65 | return [ |
||
| 66 | 'department' => Mapping::merge( |
||
| 67 | $department, |
||
| 68 | (new Mapping(RootType::ID)) |
||
| 69 | ->setProperties([ |
||
| 70 | 'rating' => $rating, |
||
| 71 | 'organization' => Mapping::merge($organization, new Mapping(ObjectType::ID)) |
||
| 72 | ]) |
||
| 73 | ), |
||
| 74 | 'employee' => Mapping::merge( |
||
| 75 | $employee, |
||
| 76 | (new Mapping(RootType::ID)) |
||
| 77 | ->setProperty( |
||
| 78 | 'department', |
||
| 79 | Mapping::merge( |
||
| 80 | $department, |
||
| 81 | (new Mapping(ObjectType::ID)) |
||
| 82 | ->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_TRUE) |
||
| 83 | ) |
||
| 84 | ) |
||
| 85 | ->setProperty('rating', $rating) |
||
| 86 | ), |
||
| 87 | 'manager' => Mapping::merge( |
||
| 88 | $manager, |
||
| 89 | (new Mapping(RootType::ID)) |
||
| 90 | ->setProperty( |
||
| 91 | 'department', |
||
| 92 | Mapping::merge( |
||
| 93 | $department, |
||
| 94 | (new Mapping(ObjectType::ID)) |
||
| 95 | ->setParameter(DynamicParameter::ID, DynamicParameter::VALUE_TRUE) |
||
| 96 | ) |
||
| 97 | ) |
||
| 98 | ->setProperty('rating', $rating) |
||
| 99 | ), |
||
| 100 | 'organization' => Mapping::merge( |
||
| 101 | $organization, |
||
| 102 | (new Mapping(RootType::ID)) |
||
| 103 | ->setProperties([ |
||
| 104 | 'departments' => Mapping::merge($department, new Mapping(ObjectType::ID)), |
||
| 105 | 'rating' => Mapping::merge($rating, new Mapping(ObjectType::ID)) |
||
| 106 | ]) |
||
| 111 |