Passed
Branch feature/2.0 (d2af8f)
by Jonathan
13:07
created
src/Webtrees/Module/AdminTasks/Services/TaskScheduleService.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -195,14 +195,14 @@  discard block
 block discarded – undo
195 195
         $query = DB::table('maj_admintasks')
196 196
             ->select()
197 197
             ->where('majat_status', '=', 'enabled')
198
-            ->where(function (Builder $query): void {
198
+            ->where(function(Builder $query): void {
199 199
 
200 200
                 $query->where('majat_running', '=', 0)
201 201
                 ->orWhere('majat_last_run', '<=', Carbon::now()->subSeconds(self::TASK_TIME_OUT));
202 202
             });
203 203
 
204 204
         if (!$force) {
205
-            $query->where(function (Builder $query): void {
205
+            $query->where(function(Builder $query): void {
206 206
 
207 207
                 $query->where('majat_running', '=', 0)
208 208
                     ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()');
@@ -268,17 +268,17 @@  discard block
 block discarded – undo
268 268
      */
269 269
     public static function rowMapper(): Closure
270 270
     {
271
-        return static function (stdClass $row): TaskSchedule {
271
+        return static function(stdClass $row): TaskSchedule {
272 272
 
273 273
             return new TaskSchedule(
274
-                (int) $row->majat_id,
274
+                (int)$row->majat_id,
275 275
                 $row->majat_task_id,
276 276
                 $row->majat_status === 'enabled',
277 277
                 Carbon::parse($row->majat_last_run),
278
-                (bool) $row->majat_last_result,
278
+                (bool)$row->majat_last_result,
279 279
                 CarbonInterval::minutes($row->majat_frequency),
280
-                (int) $row->majat_nb_occur,
281
-                (bool) $row->majat_running
280
+                (int)$row->majat_nb_occur,
281
+                (bool)$row->majat_running
282 282
             );
283 283
         };
284 284
     }
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Services/HealthCheckService.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     public function changesByRecordType(Tree $tree, int $nb_days): Collection
80 80
     {
81 81
         return DB::table('change')
82
-            ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void {
82
+            ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function(JoinClause $join) use ($tree): void {
83 83
 
84 84
                 $join->on('change.xref', '=', 'gedrecords.ged_id')
85 85
                     ->where('change.gedcom_id', '=', $tree->id());
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 new Expression('MAX(log_time) AS lastoccurred')
116 116
             )
117 117
             ->where('log_type', '=', 'error')
118
-            ->where(function (Builder $query) use ($tree): void {
118
+            ->where(function(Builder $query) use ($tree): void {
119 119
                 $query->where('gedcom_id', '=', $tree->id())
120 120
                     ->orWhereNull('gedcom_id');
121 121
             })
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/SosaConfigAction.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -58,12 +58,12 @@
 block discarded – undo
58 58
         assert($tree instanceof Tree);
59 59
         
60 60
         $params = $request->getParsedBody();
61
-        $user_id = (int) $params['sosa-userid'];
61
+        $user_id = (int)$params['sosa-userid'];
62 62
         $root_id = $params['sosa-rootid'] ?? '';
63 63
         
64
-        if(Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) {
64
+        if (Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) {
65 65
             $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
66
-            if($user !== null && $root_indi = Registry::individualFactory()->make($root_id, $tree)) {
66
+            if ($user !== null && $root_indi = Registry::individualFactory()->make($root_id, $tree)) {
67 67
                 $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref());
68 68
                 FlashMessages::addMessage(I18N::translate('The root individual has been updated.'));
69 69
                 return redirect(route(SosaConfig::class, [
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/SosaStatistics.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
         /** @var SosaStatisticsService $sosa_stats_service */
71 71
         $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
72 72
         
73
-        return $this->viewResponse($this->module->name() . '::statistics-page', [
73
+        return $this->viewResponse($this->module->name().'::statistics-page', [
74 74
             'module_name'       =>  $this->module->name(),
75 75
             'title'             =>  I18N::translate('Sosa Statistics'),
76 76
             'tree'              =>  $tree,
@@ -121,8 +121,8 @@  discard block
 block discarded – undo
121 121
         
122 122
         $generation_stats = array();
123 123
         
124
-        foreach($stats_by_gen as $gen => $stats_gen){
125
-            $gen_diff = $gen > 1 ?$stats_gen['diffSosaTotalCount'] - $stats_by_gen[$gen - 1]['diffSosaTotalCount'] : 1;
124
+        foreach ($stats_by_gen as $gen => $stats_gen) {
125
+            $gen_diff = $gen > 1 ? $stats_gen['diffSosaTotalCount'] - $stats_by_gen[$gen - 1]['diffSosaTotalCount'] : 1;
126 126
             $generation_stats[$gen] = array(
127 127
                 'gen_min_birth' => $stats_gen['firstBirth'] ?? $stats_gen['firstEstimatedBirth'],
128 128
                 'gen_max_birth' => $stats_gen['lastBirth'] ?? $stats_gen['lastEstimatedBirth'],
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
                 'known' => $stats_gen['sosaCount'],
131 131
                 'perc_known' => $this->safeDivision($stats_gen['sosaCount'], pow(2, $gen - 1)),
132 132
                 'missing' => $gen > 1 ? 2 * $stats_by_gen[$gen - 1]['sosaCount'] - $stats_gen['sosaCount'] : 0,
133
-                'perc_missing' => $gen > 1 ? 1 - $this->safeDivision($stats_gen['sosaCount'],  2 * $stats_by_gen[$gen - 1]['sosaCount']) : 0,
133
+                'perc_missing' => $gen > 1 ? 1 - $this->safeDivision($stats_gen['sosaCount'], 2 * $stats_by_gen[$gen - 1]['sosaCount']) : 0,
134 134
                 'total_known' => $stats_gen['sosaTotalCount'],
135 135
                 'perc_total_known' => $this->safeDivision($stats_gen['sosaTotalCount'], pow(2, $gen) - 1),
136 136
                 'different' => $gen_diff,
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/SosaComputeAction.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -56,16 +56,16 @@
 block discarded – undo
56 56
         $tree = $request->getAttribute('tree');
57 57
         assert($tree instanceof Tree);
58 58
         
59
-        $user_id = (int) ($request->getParsedBody()['user_id'] ?? 0);
59
+        $user_id = (int)($request->getParsedBody()['user_id'] ?? 0);
60 60
         $partial_from = $request->getParsedBody()['partial_from'] ?? null;
61 61
         
62
-        if(($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) {
62
+        if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) {
63 63
             $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
64 64
             
65 65
             /** @var SosaCalculatorService $sosa_calc_service */
66
-            $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]);
66
+            $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, ['tree' => $tree, 'user' => $user]);
67 67
             
68
-            if($partial_from !== null && $sosa_from = Registry::individualFactory()->make($partial_from, $tree)) {
68
+            if ($partial_from !== null && $sosa_from = Registry::individualFactory()->make($partial_from, $tree)) {
69 69
                 $res = $sosa_calc_service->computeFromIndividual($sosa_from);
70 70
             } else {
71 71
                 $res = $sosa_calc_service->computeAll();
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/SosaConfig.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,23 +65,23 @@
 block discarded – undo
65 65
         assert($tree instanceof Tree);
66 66
         
67 67
         $users_root = array();
68
-        if(Auth::check()) {
68
+        if (Auth::check()) {
69 69
             /** @var \Fisharebest\Webtrees\User $user */
70 70
             $user = Auth::user();
71 71
             $users_root[] = ['user' => $user, 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID')];
72 72
             
73
-            if(Auth::isManager($tree)) {
73
+            if (Auth::isManager($tree)) {
74 74
                 $default_user = new DefaultUser();
75 75
                 $users_root[] = ['user' => $default_user, 'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID')];
76 76
             }
77 77
         }
78 78
         
79
-        return $this->viewResponse($this->module->name() . '::config-page', [
79
+        return $this->viewResponse($this->module->name().'::config-page', [
80 80
             'module_name'       =>  $this->module->name(),
81 81
             'title'             =>  I18N::translate('Sosa Configuration'),
82 82
             'tree'              =>  $tree,
83 83
             'user_id'           =>  $request->getAttribute('user'),
84
-            'selected_user_id'  =>  (int) ($request->getQueryParams()['user_id'] ?? 0),
84
+            'selected_user_id'  =>  (int)($request->getQueryParams()['user_id'] ?? 0),
85 85
             'immediate_compute' =>  ($request->getQueryParams()['compute'] ?? '') == 'yes',
86 86
             'users_root'        =>  $users_root
87 87
         ]);
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Schema/Migration2.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 	    // Clean up previous sosa table if it exists
34 34
 	    DB::schema()->dropIfExists('maj_sosa');
35 35
 	    
36
-	    DB::schema()->create('maj_sosa', static function (Blueprint $table): void {
36
+	    DB::schema()->create('maj_sosa', static function(Blueprint $table): void {
37 37
 	        
38 38
 	        $table->integer('majs_gedcom_id');
39 39
 	        $table->integer('majs_user_id')->default(-1);
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Services/SosaRecordsService.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function generation(int $sosa) : int
43 43
     {
44
-        return (int) log($sosa, 2) + 1;
44
+        return (int)log($sosa, 2) + 1;
45 45
     }
46 46
     
47 47
     /**
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
         $mass_update = DB::connection()->getDriverName() === 'mysql';
106 106
         
107 107
         $bindings_placeholders = $bindings_values = [];
108
-        foreach($sosa_records as $i => $row) {
108
+        foreach ($sosa_records as $i => $row) {
109 109
             $gen = $this->generation($row['sosa']);
110
-            if($gen <=  self::MAX_DB_GENERATIONS) {
111
-                if($mass_update) {
110
+            if ($gen <= self::MAX_DB_GENERATIONS) {
111
+                if ($mass_update) {
112 112
                     $bindings_placeholders[] = '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.','.
113 113
                         ' :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :byearest'.$i.', :dyear'.$i.', :dyearest'.$i.')';
114 114
                     $bindings_values = array_merge(
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
                         ]);
127 127
                 } else {
128 128
                     DB::table('maj_sosa')->updateOrInsert(
129
-                        [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']],
129
+                        ['majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']],
130 130
                         [
131 131
                             'majs_i_id' => $row['indi'],
132 132
                             'majs_gen' => $gen,
@@ -139,14 +139,14 @@  discard block
 block discarded – undo
139 139
             }
140 140
         }
141 141
         
142
-        if($mass_update) {
142
+        if ($mass_update) {
143 143
             DB::connection()->statement(
144
-                'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' .
145
-                ' (majs_gedcom_id, majs_user_id, majs_sosa,' .
146
-                '   majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' .
147
-                ' VALUES ' . implode(',', $bindings_placeholders) .
148
-                ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' .
149
-                '   majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . 
144
+                'INSERT INTO `'.DB::connection()->getTablePrefix().'maj_sosa`'.
145
+                ' (majs_gedcom_id, majs_user_id, majs_sosa,'.
146
+                '   majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)'.
147
+                ' VALUES '.implode(',', $bindings_placeholders).
148
+                ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),'.
149
+                '   majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),'. 
150 150
                 '   majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)',
151 151
                 $bindings_values);
152 152
         }
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Services/SosaStatisticsService.php 1 patch
Spacing   +19 added lines, -20 removed lines patch added patch discarded remove patch
@@ -122,8 +122,7 @@  discard block
 block discarded – undo
122 122
             ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2')
123 123
             ->get()->first();
124 124
         
125
-        return $row->n == 0 ? 0 :
126
-            -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2));
125
+        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));
127 126
     }
128 127
     
129 128
     /**
@@ -146,11 +145,11 @@  discard block
 block discarded – undo
146 145
         $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData();
147 146
         
148 147
         $statistics_by_gen = [];
149
-        foreach($stats_by_gen as $gen => $stats_gen) {
150
-            $statistics_by_gen[(int) $stats_gen->gen] = array(
151
-                'sosaCount'				=>	(int) $stats_gen->total_sosa,
152
-                'sosaTotalCount'		=>	(int) $cumul_stats_by_gen[$gen]->total_cumul,
153
-                'diffSosaTotalCount'	=>	(int) $cumul_stats_by_gen[$gen]->total_distinct_cumul,
148
+        foreach ($stats_by_gen as $gen => $stats_gen) {
149
+            $statistics_by_gen[(int)$stats_gen->gen] = array(
150
+                'sosaCount'				=>	(int)$stats_gen->total_sosa,
151
+                'sosaTotalCount'		=>	(int)$cumul_stats_by_gen[$gen]->total_cumul,
152
+                'diffSosaTotalCount'	=>	(int)$cumul_stats_by_gen[$gen]->total_distinct_cumul,
154 153
                 'firstBirth'			=>	$stats_gen->first_year,
155 154
                 'firstEstimatedBirth'	=>	$stats_gen->first_est_year,
156 155
                 'lastBirth'				=>	$stats_gen->last_year,
@@ -228,17 +227,17 @@  discard block
 block discarded – undo
228 227
     {
229 228
         $table_prefix = DB::connection()->getTablePrefix();
230 229
         $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa')
231
-            ->selectRaw($table_prefix. 'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
232
-            ->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])
233
-            ->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')
234
-            ->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')
230
+            ->selectRaw($table_prefix.'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
231
+            ->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])
232
+            ->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')
233
+            ->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')
235 234
             ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix) : void {    // Link to sosa's father
236
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
235
+                $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa')
237 236
                 ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
238 237
                 ->where('sosa_fat.majs_user_id', '=', $this->user->id());
239 238
             })
240 239
             ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix) : void {    // Link to sosa's mother
241
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
240
+                $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1')
242 241
                 ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
243 242
                 ->where('sosa_mot.majs_user_id', '=', $this->user->id());
244 243
             })
@@ -287,14 +286,14 @@  discard block
 block discarded – undo
287 286
         $table_prefix = DB::connection()->getTablePrefix();
288 287
         $multiple_ancestors = DB::table('maj_sosa AS sosa')
289 288
             ->select('sosa.majs_i_id AS sosa_i_id')
290
-            ->selectRaw('COUNT('. $table_prefix .'sosa.majs_sosa) AS sosa_count')
289
+            ->selectRaw('COUNT('.$table_prefix.'sosa.majs_sosa) AS sosa_count')
291 290
             ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix) : void {    // Link to sosa's father
292
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
291
+                $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa')
293 292
                     ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
294 293
                     ->where('sosa_fat.majs_user_id', '=', $this->user->id());
295 294
             })
296 295
             ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix) : void {    // Link to sosa's mother
297
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
296
+                $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1')
298 297
                 ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
299 298
                 ->where('sosa_mot.majs_user_id', '=', $this->user->id());
300 299
             })
@@ -303,16 +302,16 @@  discard block
 block discarded – undo
303 302
             ->whereNull('sosa_fat.majs_sosa')   // We keep only root individuals, i.e. those with no father or mother
304 303
             ->whereNull('sosa_mot.majs_sosa')
305 304
             ->groupBy('sosa.majs_i_id')
306
-            ->havingRaw('COUNT('. $table_prefix .'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
307
-            ->orderByRaw('COUNT('. $table_prefix .'sosa.majs_sosa) DESC, MIN('. $table_prefix .'sosa.majs_sosa) ASC')
305
+            ->havingRaw('COUNT('.$table_prefix.'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
306
+            ->orderByRaw('COUNT('.$table_prefix.'sosa.majs_sosa) DESC, MIN('.$table_prefix.'sosa.majs_sosa) ASC')
308 307
             ->limit($limit + 1)     // We want to select one more than required, for ties
309 308
             ->get();
310 309
             
311
-        if($multiple_ancestors->count() > $limit)
310
+        if ($multiple_ancestors->count() > $limit)
312 311
         {
313 312
             $last_count = $multiple_ancestors->last()->sosa_count;
314 313
             $multiple_ancestors = $multiple_ancestors->reject(function($element) use ($last_count) : bool {
315
-                return $element->sosa_count ==  $last_count;
314
+                return $element->sosa_count == $last_count;
316 315
             });
317 316
         }
318 317
         return $multiple_ancestors;
Please login to merge, or discard this patch.