Passed
Branch feature/2.1-geodispersion-dev (38d49e)
by Jonathan
04:17
created
src/Webtrees/Module/AdminTasks/Tasks/HealthCheckEmailTask.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(Carbon::now());
137 137
         //@phpcs:ignore Generic.Files.LineLength.TooLong
138 138
         $interval = $interval_lastrun->greaterThan($task_schedule->frequency()) ? $interval_lastrun : $task_schedule->frequency();
139
-        $nb_days = (int) $interval->ceilDay()->totalDays;
139
+        $nb_days = (int)$interval->ceilDay()->totalDays;
140 140
 
141 141
         $view_params_site = [
142 142
             'nb_days'               =>  $nb_days,
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
                 continue;
156 156
             }
157 157
 
158
-            $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID'));
158
+            $webmaster = $this->user_service->find((int)$tree->getPreference('WEBMASTER_USER_ID'));
159 159
             if ($webmaster === null) {
160 160
                 continue;
161 161
             }
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
                 new TreeUser($tree),
177 177
                 $webmaster,
178 178
                 new NoReplyUser(),
179
-                I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()),
180
-                view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params),
181
-                view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params)
179
+                I18N::translate('Health Check Report').' - '.I18N::translate('Tree %s', $tree->name()),
180
+                view($this->module->name().'::tasks/healthcheck/email-healthcheck-text', $view_params),
181
+                view($this->module->name().'::tasks/healthcheck/email-healthcheck-html', $view_params)
182 182
             );
183 183
         }
184 184
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      */
192 192
     public function configView(ServerRequestInterface $request): string
193 193
     {
194
-        return $this->module === null ? '' : view($this->module->name() . '::tasks/healthcheck/config', [
194
+        return $this->module === null ? '' : view($this->module->name().'::tasks/healthcheck/config', [
195 195
             'all_trees'     =>  $this->tree_service->all()
196 196
         ]);
197 197
     }
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
     public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool
204 204
     {
205 205
         try {
206
-            $params = (array) $request->getParsedBody();
206
+            $params = (array)$request->getParsedBody();
207 207
 
208 208
             foreach ($this->tree_service->all() as $tree) {
209 209
                 if (Auth::isManager($tree)) {
210
-                    $tree_enabled = (bool) ($params['HEALTHCHECK_ENABLED_' . $tree->id()] ?? false);
210
+                    $tree_enabled = (bool)($params['HEALTHCHECK_ENABLED_'.$tree->id()] ?? false);
211 211
                     $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0');
212 212
                 }
213 213
             }
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Services/TaskScheduleService.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
         $query = DB::table('maj_admintasks')
198 198
             ->select()
199 199
             ->where('majat_status', '=', 'enabled')
200
-            ->where(function (Builder $query): void {
200
+            ->where(function(Builder $query): void {
201 201
 
202 202
                 $query->where('majat_running', '=', 0)
203 203
                 ->orWhere('majat_last_run', '<=', Carbon::now()->subSeconds(self::TASK_TIME_OUT));
204 204
             });
205 205
 
206 206
         if (!$force) {
207
-            $query->where(function (Builder $query): void {
207
+            $query->where(function(Builder $query): void {
208 208
 
209 209
                 $query->where('majat_running', '=', 0)
210 210
                     ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()');
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
                     $task_schedule->setLastResult($task->run($task_schedule));
254 254
                 } catch (Throwable $ex) {
255 255
                     if ($first_error) { // Only record the first error, as this could fill the log.
256
-                        Log::addErrorLog(I18N::translate('Error while running task %s:', $task->name()) . ' ' .
257
-                            '[' . get_class($ex) . '] ' . $ex->getMessage() . ' ' . $ex->getFile() . ':'
258
-                            . $ex->getLine() . PHP_EOL . $ex->getTraceAsString());
256
+                        Log::addErrorLog(I18N::translate('Error while running task %s:', $task->name()).' '.
257
+                            '['.get_class($ex).'] '.$ex->getMessage().' '.$ex->getFile().':'
258
+                            . $ex->getLine().PHP_EOL.$ex->getTraceAsString());
259 259
                     }
260 260
                 }
261 261
 
@@ -276,17 +276,17 @@  discard block
 block discarded – undo
276 276
      */
277 277
     public static function rowMapper(): Closure
278 278
     {
279
-        return static function (stdClass $row): TaskSchedule {
279
+        return static function(stdClass $row): TaskSchedule {
280 280
 
281 281
             return new TaskSchedule(
282
-                (int) $row->majat_id,
282
+                (int)$row->majat_id,
283 283
                 $row->majat_task_id,
284 284
                 $row->majat_status === 'enabled',
285 285
                 Carbon::parse($row->majat_last_run),
286
-                (bool) $row->majat_last_result,
286
+                (bool)$row->majat_last_result,
287 287
                 CarbonInterval::minutes($row->majat_frequency),
288
-                (int) $row->majat_nb_occur,
289
-                (bool) $row->majat_running
288
+                (int)$row->majat_nb_occur,
289
+                (bool)$row->majat_running
290 290
             );
291 291
         };
292 292
     }
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/AncestorsList.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,9 +77,9 @@
 block discarded – undo
77 77
         /** @var SosaStatisticsService $sosa_stats_service */
78 78
         $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
79 79
 
80
-        $current_gen = (int) ($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0);
80
+        $current_gen = (int)($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0);
81 81
 
82
-        return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
82
+        return $this->viewResponse($this->module->name().'::list-ancestors-page', [
83 83
             'module_name'       =>  $this->module->name(),
84 84
             'title'             =>  I18N::translate('Sosa Ancestors'),
85 85
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/AncestorsListIndividual.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
         $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80 80
 
81
-        $current_gen = (int) ($request->getAttribute('gen') ?? 0);
81
+        $current_gen = (int)($request->getAttribute('gen') ?? 0);
82 82
 
83 83
         if ($current_gen <= 0) {
84 84
             return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
@@ -88,14 +88,14 @@  discard block
 block discarded – undo
88 88
         $nb_ancestors_all = $list_ancestors->count();
89 89
 
90 90
         /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
91
-        $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array {
91
+        $list_ancestors = $list_ancestors->mapWithKeys(function(stdClass $value) use ($tree): ?array {
92 92
                 $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
93
-                return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null;
93
+                return ($indi !== null && $indi->canShowName()) ? [(int)$value->majs_sosa => $indi] : null;
94 94
         })->filter();
95 95
 
96 96
         $nb_ancestors_shown = $list_ancestors->count();
97 97
 
98
-        return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
98
+        return $this->viewResponse($this->module->name().'::list-ancestors-indi-tab', [
99 99
             'module_name'       =>  $this->module->name(),
100 100
             'title'             =>  I18N::translate('Sosa Ancestors'),
101 101
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/AncestorsListFamily.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
         $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80 80
 
81
-        $current_gen = (int) ($request->getAttribute('gen') ?? 0);
81
+        $current_gen = (int)($request->getAttribute('gen') ?? 0);
82 82
 
83 83
         if ($current_gen <= 0) {
84 84
             return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
@@ -88,14 +88,14 @@  discard block
 block discarded – undo
88 88
         $nb_families_all = $list_families->count();
89 89
 
90 90
         /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */
91
-        $list_families = $list_families->mapWithKeys(function (stdClass $value) use ($tree): ?array {
91
+        $list_families = $list_families->mapWithKeys(function(stdClass $value) use ($tree): ?array {
92 92
                 $fam = Registry::familyFactory()->make($value->f_id, $tree);
93
-                return ($fam !== null && $fam->canShow()) ? [(int) $value->majs_sosa => $fam] : null;
93
+                return ($fam !== null && $fam->canShow()) ? [(int)$value->majs_sosa => $fam] : null;
94 94
         })->filter();
95 95
 
96 96
         $nb_families_shown = $list_families->count();
97 97
 
98
-        return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [
98
+        return $this->viewResponse($this->module->name().'::list-ancestors-fam-tab', [
99 99
             'module_name'       =>  $this->module->name(),
100 100
             'title'             =>  I18N::translate('Sosa Ancestors'),
101 101
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/MissingAncestorsList.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -80,19 +80,19 @@  discard block
 block discarded – undo
80 80
         /** @var SosaStatisticsService $sosa_stats_service */
81 81
         $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
82 82
 
83
-        $current_gen = (int) ($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0);
83
+        $current_gen = (int)($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0);
84 84
 
85 85
         $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
86
-        $nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
86
+        $nb_missing_diff = $list_missing->sum(function(stdClass $value): int {
87 87
             return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
88 88
         });
89 89
 
90
-        $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
90
+        $list_missing = $list_missing->map(function(stdClass $value) use ($tree): ?MissingAncestor {
91 91
             $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
92 92
             if ($indi !== null && $indi->canShowName()) {
93 93
                 return new MissingAncestor(
94 94
                     $indi,
95
-                    (int) $value->majs_sosa,
95
+                    (int)$value->majs_sosa,
96 96
                     $value->majs_fat_id === null,
97 97
                     $value->majs_mot_id === null
98 98
                 );
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
             return null;
101 101
         })->filter();
102 102
 
103
-        $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
103
+        $nb_missing_shown = $list_missing->sum(function(MissingAncestor $value): int {
104 104
             return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
105 105
         });
106 106
 
107
-        return $this->viewResponse($this->module->name() . '::list-missing-page', [
107
+        return $this->viewResponse($this->module->name().'::list-missing-page', [
108 108
             'module_name'       =>  $this->module->name(),
109 109
             'title'             =>  I18N::translate('Missing Ancestors'),
110 110
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/GeoAnalyses/SosaByGenerationGeoAnalysis.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
             if ($ancestor === null || !$ancestor->canShow()) {
79 79
                 continue;
80 80
             }
81
-            $generation = $this->records_service->generation((int) $item->majs_sosa);
81
+            $generation = $this->records_service->generation((int)$item->majs_sosa);
82 82
             $significantplace = new GeoAnalysisPlace($tree, null, $depth);
83 83
             foreach ($this->significantPlaces($ancestor) as $place) {
84 84
                 $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true);
Please login to merge, or discard this patch.
src/Webtrees/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.
src/Webtrees/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.