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