| Conditions | 17 |
| Paths | 78 |
| Total Lines | 74 |
| Code Lines | 42 |
| 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 |
||
| 10 | public static function join(QueryInterface $select, $other_table, $select_also = [], $relation_type = null): string |
||
| 11 | { |
||
| 12 | $other_table_alias = null; |
||
| 13 | |||
| 14 | if (is_array($other_table)) { |
||
| 15 | list($other_table, $other_table_alias) = $other_table; |
||
| 16 | } else { |
||
| 17 | $other_table_alias = $other_table->name(); |
||
| 18 | } |
||
| 19 | |||
| 20 | $other_table_name = $other_table->name(); |
||
| 21 | |||
| 22 | $joins = []; |
||
| 23 | |||
| 24 | // 1. ? this->table.other_table_id -> $other_table.id |
||
| 25 | // 2. ? this_table.id -> $other_table.this_table_id) |
||
| 26 | // if(count($bonding_column = $this->table()->foreignKeysByTable()[$other_table_name] ?? []) === 1) |
||
| 27 | if (!is_null($bonding_column = $select->table()->singleForeignKeyTo($other_table))) { |
||
| 28 | $relation_type = ($relation_type ?? $bonding_column->isNullable()) !== '' && ($relation_type ?? $bonding_column->isNullable()) !== '0' ? 'LEFT OUTER' : 'INNER'; |
||
| 29 | // $joins []= [$bonding_column->tableName(), $bonding_column->name(), $other_table_alias ?? $bonding_column->foreignTableAlias(), $bonding_column->foreignColumnName()]; |
||
| 30 | $joins [] = [$select->tableAlias(), $bonding_column->name(), $other_table_alias ?? $bonding_column->foreignTableAlias(), $bonding_column->foreignColumnName()]; |
||
| 31 | } elseif (!is_null($bonding_column = $other_table->singleForeignKeyTo($select->table()))) { |
||
| 32 | $relation_type ??= 'LEFT OUTER'; |
||
| 33 | $joins [] = [$select->tableLabel(), $bonding_column->foreignColumnName(), $other_table_alias ?? $other_table->name(), $bonding_column->name()]; |
||
|
|
|||
| 34 | } else { |
||
| 35 | $bondable_tables = self::joinableTables($select); |
||
| 36 | if (isset($bondable_tables[$other_table_name])) { |
||
| 37 | $bonding_columns = $bondable_tables[$other_table_name]; |
||
| 38 | if (count($bonding_columns) === 1) { |
||
| 39 | $bonding_column = current($bonding_columns); |
||
| 40 | $other_table_alias ??= $bonding_column->foreignTableAlias(); |
||
| 41 | |||
| 42 | $bonding_table_label = array_search($bonding_column->tableName(), $select->joinedTables(), true); |
||
| 43 | if ($bonding_table_label === false) { |
||
| 44 | $bonding_table_label = $bonding_column->tableName(); |
||
| 45 | } |
||
| 46 | |||
| 47 | $joins = [[$bonding_table_label, $bonding_column->name(), $other_table_alias, $bonding_column->foreignColumnName()]]; |
||
| 48 | $relation_type ??= ($bonding_column->isNullable()) ? 'LEFT OUTER' : 'INNER'; |
||
| 49 | } |
||
| 50 | } elseif (($intersections = array_intersect_key($other_table->foreignKeysByTable(), $bondable_tables)) !== []) { |
||
| 51 | $other_table_alias ??= $other_table->name(); |
||
| 52 | foreach ($intersections as $table_name => $bonding_column) { |
||
| 53 | if (count($bonding_column) !== 1 || count($other_table->foreignKeysByTable()[$table_name]) !== 1) { |
||
| 54 | break; |
||
| 55 | } |
||
| 56 | |||
| 57 | |||
| 58 | $joins = []; |
||
| 59 | |||
| 60 | $bonding_column = current($bonding_column); |
||
| 61 | $joins [] = [$other_table_alias, $bonding_column->name(), $bonding_column->foreignTableAlias(), $bonding_column->foreignColumnName()]; |
||
| 62 | |||
| 63 | $bonding_column = current($bondable_tables[$table_name]); |
||
| 64 | $joins [] = [$bonding_column->tableName(), $bonding_column->name(), $bonding_column->foreignTableAlias(), $bonding_column->foreignColumnName()]; |
||
| 65 | |||
| 66 | // $relation_type = $relation_type ?? (($parent_column->isNullable() || $bonding_column->isNullable()) ? 'LEFT OUTER' : 'INNER'); |
||
| 67 | $relation_type ??= ($bonding_column->isNullable()) ? 'LEFT OUTER' : 'INNER'; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | if (!empty($joins)) { |
||
| 73 | |||
| 74 | $select->join([$other_table_name, $other_table_alias], $joins, $relation_type); |
||
| 75 | $select->addJoinedTable($other_table_name, $other_table_alias); |
||
| 76 | |||
| 77 | |||
| 78 | if (!empty($select_also)) { |
||
| 79 | $select->selectAlso($select_also); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | return $other_table_alias; |
||
| 84 | } |
||
| 145 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.