| Conditions | 1 |
| Paths | 1 |
| Total Lines | 73 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 111 | public function duplicateRecords(Tree $tree): array |
||
| 112 | { |
||
| 113 | // We can't do any reasonable checks using MySQL. |
||
| 114 | // Will need to wait for a "repositories" table. |
||
| 115 | $repositories = []; |
||
| 116 | |||
| 117 | $sources = DB::table('sources') |
||
| 118 | ->where('s_file', '=', $tree->id()) |
||
| 119 | ->groupBy(['s_name']) |
||
| 120 | ->having(new Expression('COUNT(s_id)'), '>', '1') |
||
| 121 | ->select([new Expression('GROUP_CONCAT(s_id) AS xrefs')]) |
||
| 122 | ->pluck('xrefs') |
||
| 123 | ->map(static function (string $xrefs) use ($tree): array { |
||
| 124 | return array_map(static function (string $xref) use ($tree): Source { |
||
| 125 | return Factory::source()->make($xref, $tree); |
||
| 126 | }, explode(',', $xrefs)); |
||
| 127 | }) |
||
| 128 | ->all(); |
||
| 129 | |||
| 130 | $individuals = DB::table('dates') |
||
| 131 | ->join('name', static function (JoinClause $join): void { |
||
| 132 | $join |
||
| 133 | ->on('d_file', '=', 'n_file') |
||
| 134 | ->on('d_gid', '=', 'n_id'); |
||
| 135 | }) |
||
| 136 | ->where('d_file', '=', $tree->id()) |
||
| 137 | ->whereIn('d_fact', ['BIRT', 'CHR', 'BAPM', 'DEAT', 'BURI']) |
||
| 138 | ->groupBy(['d_year', 'd_month', 'd_day', 'd_type', 'd_fact', 'n_type', 'n_full']) |
||
| 139 | ->having(new Expression('COUNT(DISTINCT d_gid)'), '>', '1') |
||
| 140 | ->select([new Expression('GROUP_CONCAT(DISTINCT d_gid ORDER BY d_gid) AS xrefs')]) |
||
| 141 | ->distinct() |
||
| 142 | ->pluck('xrefs') |
||
| 143 | ->map(static function (string $xrefs) use ($tree): array { |
||
| 144 | return array_map(static function (string $xref) use ($tree): Individual { |
||
| 145 | return Factory::individual()->make($xref, $tree); |
||
| 146 | }, explode(',', $xrefs)); |
||
| 147 | }) |
||
| 148 | ->all(); |
||
| 149 | |||
| 150 | $families = DB::table('families') |
||
| 151 | ->where('f_file', '=', $tree->id()) |
||
| 152 | ->groupBy([new Expression('LEAST(f_husb, f_wife)')]) |
||
| 153 | ->groupBy([new Expression('GREATEST(f_husb, f_wife)')]) |
||
| 154 | ->having(new Expression('COUNT(f_id)'), '>', '1') |
||
| 155 | ->select([new Expression('GROUP_CONCAT(f_id) AS xrefs')]) |
||
| 156 | ->pluck('xrefs') |
||
| 157 | ->map(static function (string $xrefs) use ($tree): array { |
||
| 158 | return array_map(static function (string $xref) use ($tree): Family { |
||
| 159 | return Factory::family()->make($xref, $tree); |
||
| 160 | }, explode(',', $xrefs)); |
||
| 161 | }) |
||
| 162 | ->all(); |
||
| 163 | |||
| 164 | $media = DB::table('media_file') |
||
| 165 | ->where('m_file', '=', $tree->id()) |
||
| 166 | ->where('descriptive_title', '<>', '') |
||
| 167 | ->groupBy(['descriptive_title']) |
||
| 168 | ->having(new Expression('COUNT(m_id)'), '>', '1') |
||
| 169 | ->select([new Expression('GROUP_CONCAT(m_id) AS xrefs')]) |
||
| 170 | ->pluck('xrefs') |
||
| 171 | ->map(static function (string $xrefs) use ($tree): array { |
||
| 172 | return array_map(static function (string $xref) use ($tree): Media { |
||
| 173 | return Factory::media()->make($xref, $tree); |
||
| 174 | }, explode(',', $xrefs)); |
||
| 175 | }) |
||
| 176 | ->all(); |
||
| 177 | |||
| 178 | return [ |
||
| 179 | I18N::translate('Repositories') => $repositories, |
||
| 180 | I18N::translate('Sources') => $sources, |
||
| 181 | I18N::translate('Individuals') => $individuals, |
||
| 182 | I18N::translate('Families') => $families, |
||
| 183 | I18N::translate('Media objects') => $media, |
||
| 184 | ]; |
||
| 278 |