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 |
||
11 | public static function join(SelectInterface $select, $other_table, $select_also = [], $relation_type = null): string |
||
12 | { |
||
13 | $other_table_alias = null; |
||
14 | |||
15 | if (is_array($other_table)) { |
||
16 | list($other_table, $other_table_alias) = $other_table; |
||
17 | } else { |
||
18 | $other_table_alias = $other_table->name(); |
||
19 | } |
||
20 | |||
21 | $other_table_name = $other_table->name(); |
||
22 | |||
23 | $joins = []; |
||
24 | |||
25 | // 1. ? this->table.other_table_id -> $other_table.id |
||
26 | // 2. ? this_table.id -> $other_table.this_table_id) |
||
27 | // if(count($bonding_column = $this->table()->foreignKeysByTable()[$other_table_name] ?? []) === 1) |
||
28 | if (!is_null($bonding_column = $select->table()->singleForeignKeyTo($other_table))) { |
||
29 | $relation_type = ($relation_type ?? $bonding_column->isNullable()) !== '' && ($relation_type ?? $bonding_column->isNullable()) !== '0' ? 'LEFT OUTER' : 'INNER'; |
||
30 | // $joins []= [$bonding_column->tableName(), $bonding_column->name(), $other_table_alias ?? $bonding_column->foreignTableAlias(), $bonding_column->foreignColumnName()]; |
||
31 | $joins [] = [$select->tableAlias(), $bonding_column->name(), $other_table_alias ?? $bonding_column->foreignTableAlias(), $bonding_column->foreignColumnName()]; |
||
32 | } elseif (!is_null($bonding_column = $other_table->singleForeignKeyTo($select->table()))) { |
||
33 | $relation_type ??= 'LEFT OUTER'; |
||
34 | $joins [] = [$select->tableLabel(), $bonding_column->foreignColumnName(), $other_table_alias ?? $other_table->name(), $bonding_column->name()]; |
||
35 | } else { |
||
36 | $bondable_tables = self::joinableTables($select); |
||
37 | if (isset($bondable_tables[$other_table_name])) { |
||
38 | $bonding_columns = $bondable_tables[$other_table_name]; |
||
39 | if (count($bonding_columns) === 1) { |
||
40 | $bonding_column = current($bonding_columns); |
||
41 | $other_table_alias ??= $bonding_column->foreignTableAlias(); |
||
42 | |||
43 | $bonding_table_label = array_search($bonding_column->tableName(), $select->joinedTables(), true); |
||
44 | if ($bonding_table_label === false) { |
||
45 | $bonding_table_label = $bonding_column->tableName(); |
||
46 | } |
||
47 | |||
48 | $joins = [[$bonding_table_label, $bonding_column->name(), $other_table_alias, $bonding_column->foreignColumnName()]]; |
||
49 | $relation_type ??= ($bonding_column->isNullable()) ? 'LEFT OUTER' : 'INNER'; |
||
50 | } |
||
51 | } elseif (($intersections = array_intersect_key($other_table->foreignKeysByTable(), $bondable_tables)) !== []) { |
||
52 | $other_table_alias ??= $other_table->name(); |
||
53 | foreach ($intersections as $table_name => $bonding_column) { |
||
54 | if (count($bonding_column) !== 1 || count($other_table->foreignKeysByTable()[$table_name]) !== 1) { |
||
55 | break; |
||
56 | } |
||
57 | |||
58 | |||
59 | $joins = []; |
||
60 | |||
61 | $bonding_column = current($bonding_column); |
||
62 | $joins [] = [$other_table_alias, $bonding_column->name(), $bonding_column->foreignTableAlias(), $bonding_column->foreignColumnName()]; |
||
63 | |||
64 | $bonding_column = current($bondable_tables[$table_name]); |
||
65 | $joins [] = [$bonding_column->tableName(), $bonding_column->name(), $bonding_column->foreignTableAlias(), $bonding_column->foreignColumnName()]; |
||
66 | |||
67 | // $relation_type = $relation_type ?? (($parent_column->isNullable() || $bonding_column->isNullable()) ? 'LEFT OUTER' : 'INNER'); |
||
68 | $relation_type ??= ($bonding_column->isNullable()) ? 'LEFT OUTER' : 'INNER'; |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | |||
73 | if (!empty($joins)) { |
||
74 | |||
75 | $select->join([$other_table_name, $other_table_alias], $joins, $relation_type); |
||
76 | $select->addJoinedTable($other_table_name, $other_table_alias); |
||
|
|||
77 | |||
78 | |||
79 | if (!empty($select_also)) { |
||
80 | $select->selectAlso($select_also); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | return $other_table_alias; |
||
85 | } |
||
146 |
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.