| Total Complexity | 44 |
| Total Lines | 97 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| Bugs | 1 | Features | 1 |
Complex classes like VisitTypeReferences often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use VisitTypeReferences, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | trait VisitTypeReferences |
||
| 20 | { |
||
| 21 | public function visitTypeReference(ITypeReference $reference): void |
||
| 22 | { |
||
| 23 | /** @var EdmModelVisitor $this */ |
||
| 24 | if (null === $reference->getDefinition()) { |
||
| 25 | throw new InvalidOperationException(StringConst::UnknownEnumVal_TypeKind('null')); |
||
| 26 | } |
||
| 27 | |||
| 28 | switch ($reference->getDefinition()->getTypeKind()) { |
||
| 29 | case TypeKind::Collection(): |
||
| 30 | $this->processCollectionTypeReference($reference->asCollection()); |
||
| 31 | break; |
||
| 32 | case TypeKind::Complex(): |
||
| 33 | $this->processComplexTypeReference($reference->asComplex()); |
||
| 34 | break; |
||
| 35 | case TypeKind::Entity(): |
||
| 36 | $this->processEntityTypeReference($reference->asEntity()); |
||
| 37 | break; |
||
| 38 | case TypeKind::EntityReference(): |
||
| 39 | $this->processEntityReferenceTypeReference($reference->asEntityReference()); |
||
| 40 | break; |
||
| 41 | case TypeKind::Enum(): |
||
| 42 | $this->processEnumTypeReference($reference->asEnum()); |
||
| 43 | break; |
||
| 44 | case TypeKind::Primitive(): |
||
| 45 | $this->visitPrimitiveTypeReference($reference->asPrimitive()); |
||
| 46 | break; |
||
| 47 | case TypeKind::Row(): |
||
| 48 | $this->processRowTypeReference($reference->asRow()); |
||
| 49 | break; |
||
| 50 | case TypeKind::None(): |
||
| 51 | $this->processTypeReference($reference); |
||
| 52 | break; |
||
| 53 | default: |
||
| 54 | throw new InvalidOperationException( |
||
| 55 | StringConst::UnknownEnumVal_TypeKind( |
||
| 56 | $reference->getDefinition()->getTypeKind()->getKey() |
||
| 57 | ) |
||
| 58 | ); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | |||
| 63 | public function visitPrimitiveTypeReference(IPrimitiveTypeReference $reference): void |
||
| 116 | ) |
||
| 117 | ); |
||
| 121 |