| Conditions | 9 | 
| Paths | 73 | 
| Total Lines | 52 | 
| 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  | 
            ||
| 75 | protected function maybeUpdatePivotRow()  | 
            ||
| 76 |     { | 
            ||
| 77 |         if (!$this->relation instanceof ManyToMany) { | 
            ||
| 78 | return;  | 
            ||
| 79 | }  | 
            ||
| 80 | |||
| 81 | $conn = $this->relation->getNativeMapper()->getWriteConnection();  | 
            ||
| 82 | $throughTable = (string)$this->relation->getOption(RelationConfig::THROUGH_TABLE);  | 
            ||
| 83 | |||
| 84 | $throughNativeColumns = (array) $this->relation->getOption(RelationConfig::THROUGH_NATIVE_COLUMN);  | 
            ||
| 85 | $throughForeignColumns = (array) $this->relation->getOption(RelationConfig::THROUGH_FOREIGN_COLUMN);  | 
            ||
| 86 | $nativeKey = (array) $this->nativeMapper->getEntityPk($this->nativeEntity);  | 
            ||
| 87 | $foreignKey = (array) $this->foreignMapper->getEntityPk($this->foreignEntity);  | 
            ||
| 88 | |||
| 89 | $delete = new \Sirius\Sql\Delete($conn);  | 
            ||
| 90 | $delete->from($throughTable);  | 
            ||
| 91 |         foreach ($throughNativeColumns as $k => $col) { | 
            ||
| 92 | $delete->where($col, $nativeKey[$k]);  | 
            ||
| 93 | $delete->where($throughForeignColumns[$k], $foreignKey[$k]);  | 
            ||
| 94 | }  | 
            ||
| 95 |         foreach ((array)$this->relation->getOption(RelationConfig::THROUGH_GUARDS) as $col => $value) { | 
            ||
| 96 |             if (!is_int($col)) { | 
            ||
| 97 | $delete->where($col, $value);  | 
            ||
| 98 |             } else { | 
            ||
| 99 | $delete->where($value);  | 
            ||
| 100 | }  | 
            ||
| 101 | }  | 
            ||
| 102 | $delete->perform();  | 
            ||
| 103 | |||
| 104 | $insertColumns = [];  | 
            ||
| 105 |         foreach ($throughNativeColumns as $k => $col) { | 
            ||
| 106 | $insertColumns[$col] = $nativeKey[$k];  | 
            ||
| 107 | $insertColumns[$throughForeignColumns[$k]] = $foreignKey[$k];  | 
            ||
| 108 | }  | 
            ||
| 109 | |||
| 110 | $throughColumnPrefix = $this->relation->getOption(RelationConfig::THROUGH_COLUMNS_PREFIX);  | 
            ||
| 111 |         foreach ((array)$this->relation->getOption(RelationConfig::THROUGH_COLUMNS) as $col) { | 
            ||
| 112 | $insertColumns[$col] = $this->relation  | 
            ||
| 113 | ->getForeignMapper()  | 
            ||
| 114 |                 ->getEntityAttribute($this->foreignEntity, "{$throughColumnPrefix}{$col}"); | 
            ||
| 115 | }  | 
            ||
| 116 | |||
| 117 |         foreach ((array)$this->relation->getOption(RelationConfig::THROUGH_GUARDS) as $col => $value) { | 
            ||
| 118 |             if (!is_int($col)) { | 
            ||
| 119 | $insertColumns[$col] = $value;  | 
            ||
| 120 | }  | 
            ||
| 121 | }  | 
            ||
| 122 | |||
| 123 | $insert = new \Sirius\Sql\Insert($conn);  | 
            ||
| 124 | $insert->into($throughTable)  | 
            ||
| 125 | ->columns($insertColumns)  | 
            ||
| 126 | ->perform();  | 
            ||
| 127 | }  | 
            ||
| 129 |