Conditions | 11 |
Paths | 15 |
Total Lines | 48 |
Code Lines | 30 |
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 |
||
59 | public function getTypes($class, $property, array $context = []) |
||
60 | { |
||
61 | if (null === $metadata = $this->getMetadata($class)) { |
||
62 | return null; |
||
63 | } |
||
64 | |||
65 | if ($metadata->hasAssociation($property)) { |
||
66 | $class = $metadata->getAssociationTargetClass($property); |
||
67 | |||
68 | if ($metadata->isSingleValuedAssociation($property)) { |
||
69 | $nullable = $metadata instanceof MongoDbClassMetadata && $metadata->isNullable($property); |
||
70 | |||
71 | return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $class)]; |
||
72 | } |
||
73 | |||
74 | $collectionKeyType = Type::BUILTIN_TYPE_INT; |
||
75 | |||
76 | return [ |
||
77 | new Type( |
||
78 | Type::BUILTIN_TYPE_OBJECT, |
||
79 | false, |
||
80 | Collection::class, |
||
81 | true, |
||
82 | new Type($collectionKeyType), |
||
83 | new Type(Type::BUILTIN_TYPE_OBJECT, false, $class) |
||
84 | ), |
||
85 | ]; |
||
86 | } |
||
87 | |||
88 | if ($metadata->hasField($property)) { |
||
89 | $typeOfField = $metadata->getTypeOfField($property); |
||
90 | $nullable = $metadata instanceof MongoDbClassMetadata && $metadata->isNullable($property); |
||
91 | |||
92 | switch ($typeOfField) { |
||
93 | case MongoDbType::DATE: |
||
94 | return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')]; |
||
95 | case MongoDbType::HASH: |
||
96 | return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)]; |
||
97 | case MongoDbType::COLLECTION: |
||
98 | return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT))]; |
||
99 | default: |
||
100 | $builtinType = $this->getPhpType($typeOfField); |
||
101 | |||
102 | return $builtinType ? [new Type($builtinType, $nullable)] : null; |
||
103 | } |
||
104 | } |
||
105 | |||
106 | return null; |
||
107 | } |
||
175 |