Conditions | 7 |
Paths | 12 |
Total Lines | 58 |
Code Lines | 35 |
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 |
||
45 | public function join(String $relation, $logicOperator = self::AND_OPERATOR_LOGIC) |
||
46 | { |
||
47 | $relation = explode('|', $relation)[0]; |
||
48 | $relations = [$relation]; |
||
49 | |||
50 | if (strstr($relation, '_embedded.')) { |
||
51 | $embeddedFields = explode('.', $relation); |
||
52 | $this->parser->camelize($embeddedFields[1]); |
||
53 | |||
54 | // elimino l'ultimo elemento che dovrebbe essere il nome del campo |
||
55 | unset($embeddedFields[count($embeddedFields) - 1]); |
||
56 | |||
57 | // elimino il primo elemento _embedded |
||
58 | unset($embeddedFields[0]); |
||
59 | |||
60 | $relations = $embeddedFields; |
||
61 | } |
||
62 | |||
63 | $entityName = $this->entityName; |
||
64 | $entityAlias = $this->entityAlias; |
||
65 | |||
66 | foreach ($relations as $relation) { |
||
67 | $relation = $this->parser->camelize($relation); |
||
68 | $relationEntityAlias = 'table_' . $relation; |
||
69 | |||
70 | $metadata = $this->manager->getClassMetadata($entityName); |
||
71 | |||
72 | if ($metadata->hasAssociation($relation)) { |
||
73 | $association = $metadata->getAssociationMapping($relation); |
||
74 | |||
75 | $fieldName = $this->parser->camelize($association['fieldName']); |
||
76 | |||
77 | if ($this->noExistsJoin($relationEntityAlias, $relation)) { |
||
78 | if ($logicOperator === self::AND_OPERATOR_LOGIC) { |
||
79 | $param = []; |
||
80 | $param['field'] = $entityAlias . "." . $fieldName; |
||
81 | $param['relation'] = $relationEntityAlias; |
||
82 | $this->innerJoin[] = $param; |
||
83 | } elseif ($logicOperator === self::OR_OPERATOR_LOGIC) { |
||
84 | $param = []; |
||
85 | $param['field'] = $entityAlias . "." . $fieldName; |
||
86 | $param['relation'] = $relationEntityAlias; |
||
87 | $this->leftJoin[] = $param; |
||
88 | } else { |
||
89 | throw new \Exception('Missing Logic operator'); |
||
90 | } |
||
91 | |||
92 | $this->storeJoin($relationEntityAlias, $relation); |
||
93 | } |
||
94 | |||
95 | $entityName = $association['targetEntity']; |
||
96 | $entityAlias = $relationEntityAlias; |
||
97 | } |
||
98 | |||
99 | $this->setRelationEntityAlias($relationEntityAlias); |
||
100 | } |
||
101 | |||
102 | return $this; |
||
103 | } |
||
141 | } |