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