Passed
Branch feature/2.0 (d2af8f)
by Jonathan
13:07
created
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.
src/Webtrees/Module/Sosa/Services/SosaCalculatorService.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     public function computeAll(): bool
78 78
     {
79 79
         $root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
80
-        if($indi = Registry::individualFactory()->make($root_id, $this->tree)) {
80
+        if ($indi = Registry::individualFactory()->make($root_id, $this->tree)) {
81 81
             $this->sosa_records_service->deleteAll($this->tree, $this->user);
82 82
             $this->addNode($indi, 1);
83 83
             $this->flushTmpSosaTable(true);
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     public function computeFromIndividual(Individual $indi) : bool
96 96
     {
97 97
         $current_sosas = $this->sosa_records_service->getSosaNumbers($indi);
98
-        foreach(array_keys($current_sosas) as $sosa) {
98
+        foreach (array_keys($current_sosas) as $sosa) {
99 99
             $this->sosa_records_service->deleteAncestorsFrom($this->tree, $this->user, $sosa);
100 100
             $this->addNode($indi, $sosa);
101 101
         }
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
         
129 129
         $this->flushTmpSosaTable();
130 130
         
131
-        if(($fam = $indi->childFamilies()->first()) !== null) {
131
+        if (($fam = $indi->childFamilies()->first()) !== null) {
132 132
             /** @var \Fisharebest\Webtrees\Family $fam */
133
-            if($husb = $fam->husband()) $this->addNode($husb, 2 * $sosa);
134
-            if($wife = $fam->wife()) $this->addNode($wife, 2 * $sosa + 1);
133
+            if ($husb = $fam->husband()) $this->addNode($husb, 2 * $sosa);
134
+            if ($wife = $fam->wife()) $this->addNode($wife, 2 * $sosa + 1);
135 135
         }
136 136
     }
137 137
     
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
      * @param bool $force Should the flush be forced
142 142
      */
143 143
     private function flushTmpSosaTable($force = false) {
144
-        if( count($this->tmp_sosa_table)> 0 &&
145
-            ($force ||  count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT)){
144
+        if (count($this->tmp_sosa_table) > 0 &&
145
+            ($force || count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT)) {
146 146
                 $this->sosa_records_service->insertOrUpdate($this->tree, $this->user, $this->tmp_sosa_table);
147 147
                 $this->tmp_sosa_table = array();
148 148
         }
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/SosaModule.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     // How to update the database schema for this module
44 44
     private const SCHEMA_TARGET_VERSION   = 3;
45 45
     private const SCHEMA_SETTING_NAME     = 'MAJ_SOSA_SCHEMA_VERSION';
46
-    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
46
+    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__.'\Schema';
47 47
     
48 48
     /**
49 49
      * {@inheritDoc}
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     {
86 86
         $router->attach('', '', static function(Map $router) : void {
87 87
             $router->attach('', '/module-maj/sosa', static function(Map $router) : void {
88
-                $router->attach('', '/list', static function (Map $router) : void {
88
+                $router->attach('', '/list', static function(Map $router) : void {
89 89
                     
90 90
                     $router->get(AncestorsList::class, '/ancestors/{tree}/{/gen}', AncestorsList::class);
91 91
                     $router->get(MissingAncestorsList::class, '/missing/{tree}/{/gen}', MissingAncestorsList::class);
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
                 
94 94
                 $router->get(SosaStatistics::class, '/statistics/{tree}', SosaStatistics::class);
95 95
                 
96
-                $router->attach('', '/config/{tree}', static function (Map $router) : void {
96
+                $router->attach('', '/config/{tree}', static function(Map $router) : void {
97 97
                     
98 98
                     $router->get(SosaConfig::class, '', SosaConfig::class);
99 99
                     $router->post(SosaConfigAction::class, '', SosaConfigAction::class);
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
         
134 134
         $menu->setSubmenus([
135 135
             new Menu(I18N::translate('Sosa Ancestors'), route(AncestorsList::class, ['tree' => $tree->name()]), 'menu-maj-sosa-list', ['rel' => 'nofollow']),
136
-            new Menu(I18N::translate('Missing Ancestors'), route(MissingAncestorsList::class, ['tree' => $tree->name()]),  'menu-maj-sosa-missing', ['rel' => 'nofollow']),
136
+            new Menu(I18N::translate('Missing Ancestors'), route(MissingAncestorsList::class, ['tree' => $tree->name()]), 'menu-maj-sosa-missing', ['rel' => 'nofollow']),
137 137
             new Menu(I18N::translate('Sosa Statistics'), route(SosaStatistics::class, ['tree' => $tree->name()]), 'menu-maj-sosa-stats')
138 138
         ]);
139 139
         
140
-        if(Auth::check()) {
140
+        if (Auth::check()) {
141 141
             $menu->addSubmenu(
142 142
                 new Menu(I18N::translate('Sosa Configuration'), route(SosaConfig::class, ['tree' => $tree->name()]), 'menu-maj-sosa-config')
143 143
             );
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function headContent(): string
154 154
     {
155
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
155
+        return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">';
156 156
     }
157 157
 }
158 158
  
159 159
\ No newline at end of file
Please login to merge, or discard this patch.