| Conditions | 1 |
| Paths | 1 |
| Total Lines | 70 |
| Code Lines | 56 |
| 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 |
||
| 116 | public function duplicateRecords(Tree $tree): array |
||
| 117 | { |
||
| 118 | // We can't do any reasonable checks using MySQL. |
||
| 119 | // Will need to wait for a "repositories" table. |
||
| 120 | $repositories = []; |
||
| 121 | |||
| 122 | $sources = DB::table('sources') |
||
| 123 | ->where('s_file', '=', $tree->id()) |
||
| 124 | ->groupBy(['s_name']) |
||
| 125 | ->having(new Expression('COUNT(s_id)'), '>', '1') |
||
| 126 | ->select([new Expression(DB::groupConcat('s_id') . ' AS xrefs')]) |
||
| 127 | ->orderBy('xrefs') |
||
| 128 | ->pluck('xrefs') |
||
| 129 | ->map(static fn (string $xrefs): array => array_map(static fn (string $xref): Source => Registry::sourceFactory()->make($xref, $tree), explode(',', $xrefs))) |
||
| 130 | ->all(); |
||
| 131 | |||
| 132 | // Database agnostic way to do GROUP_CONCAT(DISTINCT x ORDER BY x) |
||
| 133 | $distinct_order_by = static function (string $xrefs): string { |
||
| 134 | $array = explode(',', $xrefs); |
||
| 135 | sort($array); |
||
| 136 | |||
| 137 | return implode(',', array_unique($array)); |
||
| 138 | }; |
||
| 139 | |||
| 140 | $individuals = DB::table('dates') |
||
| 141 | ->join('name', static function (JoinClause $join): void { |
||
| 142 | $join |
||
| 143 | ->on('d_file', '=', 'n_file') |
||
| 144 | ->on('d_gid', '=', 'n_id'); |
||
| 145 | }) |
||
| 146 | ->where('d_file', '=', $tree->id()) |
||
| 147 | ->whereIn('d_fact', ['BIRT', 'CHR', 'BAPM', 'DEAT', 'BURI']) |
||
| 148 | ->groupBy(['d_year', 'd_month', 'd_day', 'd_type', 'd_fact', 'n_type', 'n_full']) |
||
| 149 | ->having(new Expression('COUNT(DISTINCT d_gid)'), '>', '1') |
||
| 150 | ->select([new Expression(DB::groupConcat('d_gid') . ' AS xrefs')]) |
||
| 151 | ->orderBy('xrefs') |
||
| 152 | ->pluck('xrefs') |
||
| 153 | ->map($distinct_order_by) |
||
| 154 | ->unique() |
||
| 155 | ->map(static fn (string $xrefs): array => array_map(static fn (string $xref): Individual => Registry::individualFactory()->make($xref, $tree), explode(',', $xrefs))) |
||
| 156 | ->all(); |
||
| 157 | |||
| 158 | $families = DB::table('families') |
||
| 159 | ->where('f_file', '=', $tree->id()) |
||
| 160 | ->groupBy([new Expression('LEAST(f_husb, f_wife)')]) |
||
| 161 | ->groupBy([new Expression('GREATEST(f_husb, f_wife)')]) |
||
| 162 | ->having(new Expression('COUNT(f_id)'), '>', '1') |
||
| 163 | ->select([new Expression(DB::groupConcat('f_id') . ' AS xrefs')]) |
||
| 164 | ->orderBy('xrefs') |
||
| 165 | ->pluck('xrefs') |
||
| 166 | ->map(static fn (string $xrefs): array => array_map(static fn (string $xref): Family => Registry::familyFactory()->make($xref, $tree), explode(',', $xrefs))) |
||
| 167 | ->all(); |
||
| 168 | |||
| 169 | $media = DB::table('media_file') |
||
| 170 | ->where('m_file', '=', $tree->id()) |
||
| 171 | ->where('descriptive_title', '<>', '') |
||
| 172 | ->groupBy(['descriptive_title']) |
||
| 173 | ->having(new Expression('COUNT(DISTINCT m_id)'), '>', '1') |
||
| 174 | ->select([new Expression(DB::groupConcat('m_id') . ' AS xrefs')]) |
||
| 175 | ->orderBy('xrefs') |
||
| 176 | ->pluck('xrefs') |
||
| 177 | ->map(static fn (string $xrefs): array => array_map(static fn (string $xref): Media => Registry::mediaFactory()->make($xref, $tree), explode(',', $xrefs))) |
||
| 178 | ->all(); |
||
| 179 | |||
| 180 | return [ |
||
| 181 | I18N::translate('Repositories') => $repositories, |
||
| 182 | I18N::translate('Sources') => $sources, |
||
| 183 | I18N::translate('Individuals') => $individuals, |
||
| 184 | I18N::translate('Families') => $families, |
||
| 185 | I18N::translate('Media objects') => $media, |
||
| 186 | ]; |
||
| 284 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths