Passed
Push — main ( f9aaf7...4197a4 )
by Jonathan
14:34
created
app/Module/Sosa/Http/RequestHandlers/PedigreeCollapseData.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,10 +67,10 @@
 block discarded – undo
67 67
         $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
68 68
         $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData();
69 69
 
70
-        $response = [ 'cells' => [] ];
70
+        $response = ['cells' => []];
71 71
         $last_pedi_collapse = 0;
72 72
         foreach ($pedi_collapse_data as $gen => $rec) {
73
-            $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [
73
+            $response['cells'][$gen] = view($this->module->name().'::components/pedigree-collapse-cell', [
74 74
                 'pedi_collapse_roots'   =>  $rec['pedi_collapse_roots'],
75 75
                 'pedi_collapse_xgen'    =>  $rec['pedi_collapse_xgen']
76 76
             ]);
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaConfigAction.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
         $params = $request->getParsedBody();
58 58
         assert(is_array($params));
59 59
 
60
-        $user_id = (int) $params['sosa-userid'];
60
+        $user_id = (int)$params['sosa-userid'];
61 61
         $root_id = $params['sosa-rootid'] ?? '';
62 62
         $max_gen = $params['sosa-maxgen'] ?? '';
63 63
 
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaConfig.php 1 patch
Spacing   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -86,16 +86,15 @@
 block discarded – undo
86 86
         $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations();
87 87
         foreach ($users_root as $key => $user_root) {
88 88
             $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ?
89
-                (int) $user_root['max_gen'] :
90
-                $max_gen_system;
89
+                (int)$user_root['max_gen'] : $max_gen_system;
91 90
         };
92 91
 
93
-        return $this->viewResponse($this->module->name() . '::config-page', [
92
+        return $this->viewResponse($this->module->name().'::config-page', [
94 93
             'module_name'       =>  $this->module->name(),
95 94
             'title'             =>  I18N::translate('Sosa Configuration'),
96 95
             'tree'              =>  $tree,
97 96
             'user_id'           =>  $request->getAttribute('user'),
98
-            'selected_user_id'  =>  (int) ($request->getQueryParams()['user_id'] ?? 0),
97
+            'selected_user_id'  =>  (int)($request->getQueryParams()['user_id'] ?? 0),
99 98
             'immediate_compute' =>  ($request->getQueryParams()['compute'] ?? '') == 'yes',
100 99
             'users_root'        =>  $users_root
101 100
         ]);
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaComputeModal.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
         $tree = $request->getAttribute('tree');
61 61
         assert($tree instanceof Tree);
62 62
 
63
-        return response(view($this->module->name() . '::modals/sosa-compute', [
63
+        return response(view($this->module->name().'::modals/sosa-compute', [
64 64
             'tree'          => $tree,
65 65
             'xref'          =>  $request->getAttribute('xref')
66 66
         ]));
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaComputeAction.php 1 patch
Spacing   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
         $params = $request->getParsedBody();
59 59
         assert(is_array($params));
60 60
 
61
-        $user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0);
61
+        $user_id = (int)($params['user_id'] ?? Auth::id() ?? 0);
62 62
         $partial_from = $params['partial_from'] ?? null;
63 63
 
64 64
         if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) {
65 65
             $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
66 66
 
67 67
             /** @var SosaCalculatorService $sosa_calc_service */
68
-            $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]);
68
+            $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, ['tree' => $tree, 'user' => $user]);
69 69
 
70 70
             if (
71 71
                 $partial_from !== null &&
@@ -77,8 +77,7 @@  discard block
 block discarded – undo
77 77
             }
78 78
 
79 79
             return $res ?
80
-                response('', 200) :
81
-                response(
80
+                response('', 200) : response(
82 81
                     I18N::translate('An error occurred while computing Sosa ancestors.'),
83 82
                     StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR
84 83
                 );
Please login to merge, or discard this patch.
app/Module/Sosa/Schema/Migration2.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
         // Clean up previous sosa table if it exists
35 35
         DB::schema()->dropIfExists('maj_sosa');
36 36
 
37
-        DB::schema()->create('maj_sosa', static function (Blueprint $table): void {
37
+        DB::schema()->create('maj_sosa', static function(Blueprint $table): void {
38 38
 
39 39
             $table->integer('majs_gedcom_id');
40 40
             $table->integer('majs_user_id')->default(-1);
Please login to merge, or discard this patch.
app/Module/Sosa/Services/SosaCalculatorService.php 1 patch
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -74,8 +74,7 @@
 block discarded – undo
74 74
         $this->tmp_sosa_table = array();
75 75
         $max_gen_setting = $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN');
76 76
         $this->max_generations = is_numeric($max_gen_setting) ?
77
-            (int) $max_gen_setting :
78
-            $this->sosa_records_service->maxSystemGenerations();
77
+            (int)$max_gen_setting : $this->sosa_records_service->maxSystemGenerations();
79 78
     }
80 79
 
81 80
     /**
Please login to merge, or discard this patch.
app/Module/Sosa/Services/SosaRecordsService.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
     public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection
89 89
     {
90 90
         return Registry::cache()->array()->remember(
91
-            'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(),
92
-            function () use ($tree, $user, $indi): Collection {
91
+            'sosanumbers-'.$indi->xref().'@'.$tree->id().'-'.$user->id(),
92
+            function() use ($tree, $user, $indi): Collection {
93 93
                 return DB::table('maj_sosa')
94 94
                     ->select(['majs_sosa', 'majs_gen'])
95 95
                     ->where('majs_gedcom_id', '=', $tree->id())
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
     {
150 150
         $table_prefix = DB::connection()->getTablePrefix();
151 151
         return DB::table('families')
152
-            ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void {
152
+            ->join('maj_sosa AS sosa_husb', function(JoinClause $join) use ($tree, $user): void {
153 153
                 // Link to family husband
154 154
                 $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id')
155 155
                     ->on('families.f_husb', '=', 'sosa_husb.majs_i_id')
156 156
                     ->where('sosa_husb.majs_gedcom_id', '=', $tree->id())
157 157
                     ->where('sosa_husb.majs_user_id', '=', $user->id());
158 158
             })
159
-            ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void {
159
+            ->join('maj_sosa AS sosa_wife', function(JoinClause $join) use ($tree, $user): void {
160 160
                 // Link to family husband
161 161
                 $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id')
162 162
                 ->on('families.f_wife', '=', 'sosa_wife.majs_i_id')
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
             })
166 166
             ->select(['sosa_husb.majs_sosa', 'families.f_id'])
167 167
             ->where('sosa_husb.majs_gen', '=', $gen)
168
-            ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa')
168
+            ->whereRaw($table_prefix.'sosa_husb.majs_sosa + 1 = '.$table_prefix.'sosa_wife.majs_sosa')
169 169
             ->orderBy('sosa_husb.majs_sosa')
170 170
             ->get();
171 171
     }
@@ -188,28 +188,28 @@  discard block
 block discarded – undo
188 188
         $table_prefix = DB::connection()->getTablePrefix();
189 189
         return DB::table('maj_sosa AS sosa')
190 190
             ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id'])
191
-            ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa')
192
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void {
191
+            ->selectRaw('MIN('.$table_prefix.'sosa.majs_sosa) AS majs_sosa')
192
+            ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($tree, $user, $table_prefix): void {
193 193
                 // Link to sosa's father
194
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
194
+                $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa')
195 195
                     ->where('sosa_fat.majs_gedcom_id', '=', $tree->id())
196 196
                     ->where('sosa_fat.majs_user_id', '=', $user->id());
197 197
             })
198
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void {
198
+            ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($tree, $user, $table_prefix): void {
199 199
                 // Link to sosa's mother
200
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
200
+                $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1')
201 201
                     ->where('sosa_mot.majs_gedcom_id', '=', $tree->id())
202 202
                     ->where('sosa_mot.majs_user_id', '=', $user->id());
203 203
             })
204 204
             ->where('sosa.majs_gedcom_id', '=', $tree->id())
205 205
             ->where('sosa.majs_user_id', '=', $user->id())
206 206
             ->where('sosa.majs_gen', '=', $gen - 1)
207
-            ->where(function (Builder $query): void {
207
+            ->where(function(Builder $query): void {
208 208
                 $query->whereNull('sosa_fat.majs_i_id')
209 209
                     ->orWhereNull('sosa_mot.majs_i_id');
210 210
             })
211 211
             ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id')
212
-            ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)')
212
+            ->orderByRaw('MIN('.$table_prefix.'sosa.majs_sosa)')
213 213
             ->get();
214 214
     }
215 215
 
@@ -261,29 +261,29 @@  discard block
 block discarded – undo
261 261
         $has_records = false;
262 262
         foreach ($sosa_records as $i => $row) {
263 263
             $gen = $this->generation($row['sosa']);
264
-            if ($gen <=  $this->maxSystemGenerations()) {
264
+            if ($gen <= $this->maxSystemGenerations()) {
265 265
                 $has_records = true;
266 266
                 if ($mass_update) {
267
-                    $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' .
268
-                        ' :indi_id' . $i . ', :gen' . $i . ',' .
269
-                        ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')';
267
+                    $bindings_placeholders[] = '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.','.
268
+                        ' :indi_id'.$i.', :gen'.$i.','.
269
+                        ' :byear'.$i.', :byearest'.$i.', :dyear'.$i.', :dyearest'.$i.')';
270 270
                     $bindings_values = array_merge(
271 271
                         $bindings_values,
272 272
                         [
273
-                            'tree_id' . $i => $tree->id(),
274
-                            'user_id' . $i => $user->id(),
275
-                            'sosa' . $i => $row['sosa'],
276
-                            'indi_id' . $i => $row['indi'],
277
-                            'gen' . $i => $gen,
278
-                            'byear' . $i => $row['birth_year'],
279
-                            'byearest' . $i => $row['birth_year_est'],
280
-                            'dyear' . $i => $row['death_year'],
281
-                            'dyearest' . $i => $row['death_year_est']
273
+                            'tree_id'.$i => $tree->id(),
274
+                            'user_id'.$i => $user->id(),
275
+                            'sosa'.$i => $row['sosa'],
276
+                            'indi_id'.$i => $row['indi'],
277
+                            'gen'.$i => $gen,
278
+                            'byear'.$i => $row['birth_year'],
279
+                            'byearest'.$i => $row['birth_year_est'],
280
+                            'dyear'.$i => $row['death_year'],
281
+                            'dyearest'.$i => $row['death_year_est']
282 282
                         ]
283 283
                     );
284 284
                 } else {
285 285
                     DB::table('maj_sosa')->updateOrInsert(
286
-                        [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']],
286
+                        ['majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']],
287 287
                         [
288 288
                             'majs_i_id' => $row['indi'],
289 289
                             'majs_gen' => $gen,
@@ -299,12 +299,12 @@  discard block
 block discarded – undo
299 299
 
300 300
         if ($has_records && $mass_update) {
301 301
             DB::connection()->statement(
302
-                'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' .
303
-                ' (majs_gedcom_id, majs_user_id, majs_sosa,' .
304
-                '   majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' .
305
-                ' VALUES ' . implode(',', $bindings_placeholders) .
306
-                ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' .
307
-                '   majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' .
302
+                'INSERT INTO `'.DB::connection()->getTablePrefix().'maj_sosa`'.
303
+                ' (majs_gedcom_id, majs_user_id, majs_sosa,'.
304
+                '   majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)'.
305
+                ' VALUES '.implode(',', $bindings_placeholders).
306
+                ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),'.
307
+                '   majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),'.
308 308
                 '   majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)',
309 309
                 $bindings_values
310 310
             );
Please login to merge, or discard this patch.
app/Module/Sosa/Services/SosaStatisticsService.php 1 patch
Spacing   +58 added lines, -59 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function maxGeneration(): int
74 74
     {
75
-        return (int) DB::table('maj_sosa')
75
+        return (int)DB::table('maj_sosa')
76 76
             ->where('majs_gedcom_id', '=', $this->tree->id())
77 77
             ->where('majs_user_id', '=', $this->user->id())
78 78
             ->max('majs_gen');
@@ -149,8 +149,7 @@  discard block
 block discarded – undo
149 149
             ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2')
150 150
             ->get()->first();
151 151
 
152
-        return $row->n == 0 ? 0 :
153
-            -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2));
152
+        return $row->n == 0 ? 0 : -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2));
154 153
     }
155 154
 
156 155
     /**
@@ -174,10 +173,10 @@  discard block
 block discarded – undo
174 173
 
175 174
         $statistics_by_gen = [];
176 175
         foreach ($stats_by_gen as $gen => $stats_gen) {
177
-            $statistics_by_gen[(int) $stats_gen->gen] = array(
178
-                'sosaCount'             =>  (int) $stats_gen->total_sosa,
179
-                'sosaTotalCount'        =>  (int) $cumul_stats_by_gen[$gen]->total_cumul,
180
-                'diffSosaTotalCount'    =>  (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul,
176
+            $statistics_by_gen[(int)$stats_gen->gen] = array(
177
+                'sosaCount'             =>  (int)$stats_gen->total_sosa,
178
+                'sosaTotalCount'        =>  (int)$cumul_stats_by_gen[$gen]->total_cumul,
179
+                'diffSosaTotalCount'    =>  (int)$cumul_stats_by_gen[$gen]->total_distinct_cumul,
181 180
                 'firstBirth'            =>  $stats_gen->first_year,
182 181
                 'firstEstimatedBirth'   =>  $stats_gen->first_est_year,
183 182
                 'lastBirth'             =>  $stats_gen->last_year,
@@ -221,7 +220,7 @@  discard block
 block discarded – undo
221 220
             ->where('majs_user_id', '=', $this->user->id());
222 221
 
223 222
         return DB::table('maj_sosa')
224
-            ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
223
+            ->joinSub($list_gen, 'list_gen', function(JoinClause $join): void {
225 224
                 $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen')
226 225
                 ->where('majs_gedcom_id', '=', $this->tree->id())
227 226
                 ->where('majs_user_id', '=', $this->user->id());
@@ -258,37 +257,37 @@  discard block
 block discarded – undo
258 257
             ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
259 258
             ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
260 259
             ->selectRaw(
261
-                '(CASE ' .
262
-                    ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' .
263
-                    ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' .
264
-                    ' ELSE 0 ' .
265
-                ' END)' .
266
-                ' + (CASE ' .
267
-                    ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' .
268
-                    ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' .
269
-                    ' ELSE 0 ' .
260
+                '(CASE '.
261
+                    ' WHEN '.$table_prefix.'sosa_fat.majs_i_id IS NULL'.
262
+                    ' THEN POWER(2, '.$table_prefix.'list_gen.majs_gen - '.$table_prefix.'sosa.majs_gen - 1)'.
263
+                    ' ELSE 0 '.
264
+                ' END)'.
265
+                ' + (CASE '.
266
+                    ' WHEN '.$table_prefix.'sosa_mot.majs_i_id IS NULL'.
267
+                    ' THEN POWER(2, '.$table_prefix.'list_gen.majs_gen - '.$table_prefix.'sosa.majs_gen - 1)'.
268
+                    ' ELSE 0 '.
270 269
                 ' END) contrib'
271 270
             )
272
-            ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
271
+            ->joinSub($list_gen, 'list_gen', function(JoinClause $join): void {
273 272
                 $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen')
274 273
                     ->where('majs_gedcom_id', '=', $this->tree->id())
275 274
                     ->where('majs_user_id', '=', $this->user->id());
276 275
             })
277
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
276
+            ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void {
278 277
                 // Link to sosa's father
279
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
278
+                $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa')
280 279
                     ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
281 280
                     ->where('sosa_fat.majs_user_id', '=', $this->user->id());
282 281
             })
283
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
282
+            ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void {
284 283
                 // Link to sosa's mother
285
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
284
+                $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1')
286 285
                     ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
287 286
                     ->where('sosa_mot.majs_user_id', '=', $this->user->id());
288 287
             })
289 288
             ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
290 289
             ->where('sosa.majs_user_id', '=', $this->user->id())
291
-            ->where(function (Builder $query): void {
290
+            ->where(function(Builder $query): void {
292 291
                 $query->whereNull('sosa_fat.majs_i_id')
293 292
                 ->orWhereNull('sosa_mot.majs_i_id');
294 293
             });
@@ -298,24 +297,24 @@  discard block
 block discarded – undo
298 297
          */
299 298
         $non_roots_ancestors = DB::table('maj_sosa AS sosa')
300 299
             ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa'])
301
-            ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' .
300
+            ->selectRaw('MAX('.$table_prefix.'sosa_anc.majs_sosa) - MIN('.$table_prefix.'sosa_anc.majs_sosa)'.
302 301
                 ' AS full_ancestors')
303
-            ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void {
302
+            ->join('maj_sosa AS sosa_anc', function(JoinClause $join) use ($table_prefix): void {
304 303
                 $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen')
305
-                    ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' .
306
-                        $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' .
307
-                        $table_prefix . 'sosa.majs_sosa')
304
+                    ->whereRaw('FLOOR('.$table_prefix.'sosa_anc.majs_sosa / POWER(2, '.
305
+                        $table_prefix.'sosa_anc.majs_gen - '.$table_prefix.'sosa.majs_gen)) = '.
306
+                        $table_prefix.'sosa.majs_sosa')
308 307
                     ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id())
309 308
                     ->where('sosa_anc.majs_user_id', '=', $this->user->id());
310 309
             })
311 310
             ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
312 311
             ->where('sosa.majs_user_id', '=', $this->user->id())
313
-            ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void {
312
+            ->whereIn('sosa_anc.majs_i_id', function(Builder $query) use ($table_prefix): void {
314 313
                 $query->from('maj_sosa AS sosa_gen')
315 314
                 ->select('sosa_gen.majs_i_id')->distinct()
316 315
                 ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id())
317 316
                 ->where('sosa_gen.majs_user_id', '=', $this->user->id())
318
-                ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen');
317
+                ->whereRaw($table_prefix.'sosa_gen.majs_gen = '.$table_prefix.'sosa.majs_gen');
319 318
             })
320 319
             ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id',
321 320
                 'sosa.majs_sosa', 'sosa.majs_i_id']);
@@ -328,7 +327,7 @@  discard block
 block discarded – undo
328 327
             ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
329 328
             ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
330 329
             ->selectRaw('1 AS contrib')
331
-            ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void {
330
+            ->leftJoinSub($non_roots_ancestors, 'nonroot', function(JoinClause $join): void {
332 331
                 $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen')
333 332
                     ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa')
334 333
                     ->where('nonroot.full_ancestors', '>', 0)
@@ -346,9 +345,9 @@  discard block
 block discarded – undo
346 345
             ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs')
347 346
             ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id'])
348 347
             ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib'])
349
-            ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' .
350
-                $table_prefix . 'sosa_contribs.contrib AS totalContrib')
351
-            ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void {
348
+            ->selectRaw('COUNT('.$table_prefix.'sosa_contribs.majs_i_id) * '.
349
+                $table_prefix.'sosa_contribs.contrib AS totalContrib')
350
+            ->leftJoin('maj_sosa AS sosa_low', function(JoinClause $join): void {
352 351
                 $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen')
353 352
                     ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id')
354 353
                     ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id())
@@ -369,9 +368,9 @@  discard block
 block discarded – undo
369 368
 
370 369
         $pedi_collapse_by_gen = [];
371 370
         foreach ($pedi_collapse_coll as $collapse_gen) {
372
-            $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array(
373
-                'pedi_collapse_roots'   =>  (float) $collapse_gen->pedi_collapse_roots,
374
-                'pedi_collapse_xgen'   =>  (float) $collapse_gen->pedi_collapse_xgen
371
+            $pedi_collapse_by_gen[(int)$collapse_gen->gen] = array(
372
+                'pedi_collapse_roots'   =>  (float)$collapse_gen->pedi_collapse_roots,
373
+                'pedi_collapse_xgen'   =>  (float)$collapse_gen->pedi_collapse_xgen
375 374
             );
376 375
         }
377 376
         return $pedi_collapse_by_gen;
@@ -399,26 +398,26 @@  discard block
 block discarded – undo
399 398
     {
400 399
         $table_prefix = DB::connection()->getTablePrefix();
401 400
         $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa')
402
-            ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
403
-            ->selectRaw('FLOOR(((' . $table_prefix . 'sosa.majs_sosa / POW(2, ' . $table_prefix . 'sosa.majs_gen -1 )) - 1) * POWER(2, ? - 1)) + POWER(2, ? - 1) AS root_ancestor', [$gen, $gen])   //@phpcs:ignore Generic.Files.LineLength.TooLong
404
-            ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 1 ELSE 0 END) AS full_root_count')  //@phpcs:ignore Generic.Files.LineLength.TooLong
405
-            ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 0 ELSE 1 END) As semi_root_count')  //@phpcs:ignore Generic.Files.LineLength.TooLong
406
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
401
+            ->selectRaw($table_prefix.'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
402
+            ->selectRaw('FLOOR((('.$table_prefix.'sosa.majs_sosa / POW(2, '.$table_prefix.'sosa.majs_gen -1 )) - 1) * POWER(2, ? - 1)) + POWER(2, ? - 1) AS root_ancestor', [$gen, $gen])   //@phpcs:ignore Generic.Files.LineLength.TooLong
403
+            ->selectRaw('SUM(CASE WHEN '.$table_prefix.'sosa_fat.majs_i_id IS NULL AND '.$table_prefix.'sosa_mot.majs_i_id IS NULL THEN 1 ELSE 0 END) AS full_root_count')  //@phpcs:ignore Generic.Files.LineLength.TooLong
404
+            ->selectRaw('SUM(CASE WHEN '.$table_prefix.'sosa_fat.majs_i_id IS NULL AND '.$table_prefix.'sosa_mot.majs_i_id IS NULL THEN 0 ELSE 1 END) As semi_root_count')  //@phpcs:ignore Generic.Files.LineLength.TooLong
405
+            ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void {
407 406
                 // Link to sosa's father
408
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
407
+                $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa')
409 408
                 ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
410 409
                 ->where('sosa_fat.majs_user_id', '=', $this->user->id());
411 410
             })
412
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
411
+            ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void {
413 412
                 // Link to sosa's mother
414
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
413
+                $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1')
415 414
                 ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
416 415
                 ->where('sosa_mot.majs_user_id', '=', $this->user->id());
417 416
             })
418 417
             ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
419 418
             ->where('sosa.majs_user_id', '=', $this->user->id())
420 419
             ->where('sosa.majs_gen', '>=', $gen)
421
-            ->where(function (Builder $query): void {
420
+            ->where(function(Builder $query): void {
422 421
                 $query->whereNull('sosa_fat.majs_i_id')
423 422
                     ->orWhereNull('sosa_mot.majs_i_id');
424 423
             })
@@ -427,11 +426,11 @@  discard block
 block discarded – undo
427 426
         return DB::table('maj_sosa AS sosa_list')
428 427
             ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id'])
429 428
             ->selectRaw('1 + SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) /  (2 * POWER(2, majs_gen_norm))) AS mean_gen_depth')  //@phpcs:ignore Generic.Files.LineLength.TooLong
430
-            ->selectRaw(' SQRT(' .
431
-                '   SUM(POWER(majs_gen_norm, 2) * ( 2 * full_root_count + semi_root_count) /  (2 * POWER(2, majs_gen_norm)))' .     //@phpcs:ignore Generic.Files.LineLength.TooLong
432
-                '   - POWER( SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) /  (2 * POWER(2, majs_gen_norm))), 2)' .       //@phpcs:ignore Generic.Files.LineLength.TooLong
429
+            ->selectRaw(' SQRT('.
430
+                '   SUM(POWER(majs_gen_norm, 2) * ( 2 * full_root_count + semi_root_count) /  (2 * POWER(2, majs_gen_norm)))'.//@phpcs:ignore Generic.Files.LineLength.TooLong
431
+                '   - POWER( SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) /  (2 * POWER(2, majs_gen_norm))), 2)'.//@phpcs:ignore Generic.Files.LineLength.TooLong
433 432
                 ' ) AS stddev_gen_depth')
434
-            ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void {
433
+            ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function(JoinClause $join): void {
435 434
                 $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor')
436 435
                     ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id())
437 436
                     ->where('sosa_list.majs_user_id', '=', $this->user->id());
@@ -460,16 +459,16 @@  discard block
 block discarded – undo
460 459
         $table_prefix = DB::connection()->getTablePrefix();
461 460
         $multiple_ancestors = DB::table('maj_sosa AS sosa')
462 461
             ->select('sosa.majs_i_id AS sosa_i_id')
463
-            ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count')
464
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
462
+            ->selectRaw('COUNT('.$table_prefix.'sosa.majs_sosa) AS sosa_count')
463
+            ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void {
465 464
                 // Link to sosa's father
466
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
465
+                $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa')
467 466
                     ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
468 467
                     ->where('sosa_fat.majs_user_id', '=', $this->user->id());
469 468
             })
470
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
469
+            ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void {
471 470
                 // Link to sosa's mother
472
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
471
+                $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1')
473 472
                 ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
474 473
                 ->where('sosa_mot.majs_user_id', '=', $this->user->id());
475 474
             })
@@ -478,15 +477,15 @@  discard block
 block discarded – undo
478 477
             ->whereNull('sosa_fat.majs_sosa')   // We keep only root individuals, i.e. those with no father or mother
479 478
             ->whereNull('sosa_mot.majs_sosa')
480 479
             ->groupBy('sosa.majs_i_id')
481
-            ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
482
-            ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC')   //@phpcs:ignore Generic.Files.LineLength.TooLong
480
+            ->havingRaw('COUNT('.$table_prefix.'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
481
+            ->orderByRaw('COUNT('.$table_prefix.'sosa.majs_sosa) DESC, MIN('.$table_prefix.'sosa.majs_sosa) ASC')   //@phpcs:ignore Generic.Files.LineLength.TooLong
483 482
             ->limit($limit + 1)     // We want to select one more than required, for ties
484 483
             ->get();
485 484
 
486 485
         if ($multiple_ancestors->count() > $limit) {
487 486
             $last_count = $multiple_ancestors->last()->sosa_count;
488
-            $multiple_ancestors = $multiple_ancestors->reject(function (stdClass $element) use ($last_count): bool {
489
-                return $element->sosa_count ==  $last_count;
487
+            $multiple_ancestors = $multiple_ancestors->reject(function(stdClass $element) use ($last_count): bool {
488
+                return $element->sosa_count == $last_count;
490 489
             });
491 490
         }
492 491
         return $multiple_ancestors;
Please login to merge, or discard this patch.