Passed
Branch feature/2.0 (be78a0)
by Jonathan
11:57
created
src/Webtrees/Module/Sosa/Http/RequestHandlers/AncestorsListIndividual.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -35,74 +35,74 @@
 block discarded – undo
35 35
  */
36 36
 class AncestorsListIndividual implements RequestHandlerInterface
37 37
 {
38
-    use ViewResponseTrait;
39
-
40
-    /**
41
-     * @var SosaModule $module
42
-     */
43
-    private $module;
44
-
45
-    /**
46
-     * @var SosaRecordsService $sosa_record_service
47
-     */
48
-    private $sosa_record_service;
49
-
50
-    /**
51
-     * Constructor for AncestorsListIndividual Request Handler
52
-     *
53
-     * @param ModuleService $module_service
54
-     * @param SosaRecordsService $sosa_record_service
55
-     */
56
-    public function __construct(
57
-        ModuleService $module_service,
58
-        SosaRecordsService $sosa_record_service
59
-    ) {
60
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
61
-        $this->sosa_record_service = $sosa_record_service;
62
-    }
63
-
64
-    /**
65
-     * {@inheritDoc}
66
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
-     */
68
-    public function handle(ServerRequestInterface $request): ResponseInterface
69
-    {
70
-        $this->layout = 'layouts/ajax';
71
-
72
-        if ($this->module === null) {
73
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
-        }
75
-
76
-        $tree = $request->getAttribute('tree');
77
-        assert($tree instanceof Tree);
78
-
79
-        $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80
-
81
-        $current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
82
-
83
-        if ($current_gen <= 0) {
84
-            return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
85
-        }
86
-
87
-        $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen);
88
-        $nb_ancestors_all = $list_ancestors->count();
89
-
90
-        /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
91
-        $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array {
92
-                $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
93
-                return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null;
94
-        })->filter();
95
-
96
-        $nb_ancestors_shown = $list_ancestors->count();
97
-
98
-        return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
99
-            'module_name'       =>  $this->module->name(),
100
-            'title'             =>  I18N::translate('Sosa Ancestors'),
101
-            'tree'              =>  $tree,
102
-            'list_ancestors'    =>  $list_ancestors,
103
-            'nb_ancestors_all'  =>  $nb_ancestors_all,
104
-            'nb_ancestors_theor' =>  pow(2, $current_gen - 1),
105
-            'nb_ancestors_shown' =>  $nb_ancestors_shown
106
-        ]);
107
-    }
38
+	use ViewResponseTrait;
39
+
40
+	/**
41
+	 * @var SosaModule $module
42
+	 */
43
+	private $module;
44
+
45
+	/**
46
+	 * @var SosaRecordsService $sosa_record_service
47
+	 */
48
+	private $sosa_record_service;
49
+
50
+	/**
51
+	 * Constructor for AncestorsListIndividual Request Handler
52
+	 *
53
+	 * @param ModuleService $module_service
54
+	 * @param SosaRecordsService $sosa_record_service
55
+	 */
56
+	public function __construct(
57
+		ModuleService $module_service,
58
+		SosaRecordsService $sosa_record_service
59
+	) {
60
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
61
+		$this->sosa_record_service = $sosa_record_service;
62
+	}
63
+
64
+	/**
65
+	 * {@inheritDoc}
66
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
+	 */
68
+	public function handle(ServerRequestInterface $request): ResponseInterface
69
+	{
70
+		$this->layout = 'layouts/ajax';
71
+
72
+		if ($this->module === null) {
73
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
+		}
75
+
76
+		$tree = $request->getAttribute('tree');
77
+		assert($tree instanceof Tree);
78
+
79
+		$user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80
+
81
+		$current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
82
+
83
+		if ($current_gen <= 0) {
84
+			return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
85
+		}
86
+
87
+		$list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen);
88
+		$nb_ancestors_all = $list_ancestors->count();
89
+
90
+		/** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
91
+		$list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array {
92
+				$indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
93
+				return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null;
94
+		})->filter();
95
+
96
+		$nb_ancestors_shown = $list_ancestors->count();
97
+
98
+		return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
99
+			'module_name'       =>  $this->module->name(),
100
+			'title'             =>  I18N::translate('Sosa Ancestors'),
101
+			'tree'              =>  $tree,
102
+			'list_ancestors'    =>  $list_ancestors,
103
+			'nb_ancestors_all'  =>  $nb_ancestors_all,
104
+			'nb_ancestors_theor' =>  pow(2, $current_gen - 1),
105
+			'nb_ancestors_shown' =>  $nb_ancestors_shown
106
+		]);
107
+	}
108 108
 }
Please login to merge, or discard this 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') ?? $request->getQueryParams()['gen'] ?? 0);
81
+        $current_gen = (int)($request->getAttribute('gen') ?? $request->getQueryParams()['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/SosaComputeModal.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,40 +29,40 @@
 block discarded – undo
29 29
  */
30 30
 class SosaComputeModal implements RequestHandlerInterface
31 31
 {
32
-    /**
33
-     * @var SosaModule $module
34
-     */
35
-    private $module;
32
+	/**
33
+	 * @var SosaModule $module
34
+	 */
35
+	private $module;
36 36
 
37
-    /**
38
-     * Constructor for SosaComputeModal Request Handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     */
42
-    public function __construct(ModuleService $module_service)
43
-    {
44
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
45
-    }
37
+	/**
38
+	 * Constructor for SosaComputeModal Request Handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 */
42
+	public function __construct(ModuleService $module_service)
43
+	{
44
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritDoc}
49
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
-     */
51
-    public function handle(ServerRequestInterface $request): ResponseInterface
52
-    {
53
-        if ($this->module === null) {
54
-            return response(
55
-                I18N::translate('The attached module could not be found.'),
56
-                StatusCodeInterface::STATUS_NOT_FOUND
57
-            );
58
-        }
47
+	/**
48
+	 * {@inheritDoc}
49
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
+	 */
51
+	public function handle(ServerRequestInterface $request): ResponseInterface
52
+	{
53
+		if ($this->module === null) {
54
+			return response(
55
+				I18N::translate('The attached module could not be found.'),
56
+				StatusCodeInterface::STATUS_NOT_FOUND
57
+			);
58
+		}
59 59
 
60
-        $tree = $request->getAttribute('tree');
61
-        assert($tree instanceof Tree);
60
+		$tree = $request->getAttribute('tree');
61
+		assert($tree instanceof Tree);
62 62
 
63
-        return response(view($this->module->name() . '::modals/sosa-compute', [
64
-            'tree'          => $tree,
65
-            'xref'          =>  $request->getAttribute('xref')
66
-        ]));
67
-    }
63
+		return response(view($this->module->name() . '::modals/sosa-compute', [
64
+			'tree'          => $tree,
65
+			'xref'          =>  $request->getAttribute('xref')
66
+		]));
67
+	}
68 68
 }
Please login to merge, or discard this 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.
src/Webtrees/Module/Sosa/Http/RequestHandlers/SosaComputeAction.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -31,61 +31,61 @@
 block discarded – undo
31 31
  */
32 32
 class SosaComputeAction implements RequestHandlerInterface
33 33
 {
34
-    /**
35
-     * @var UserService $user_service
36
-     */
37
-    private $user_service;
34
+	/**
35
+	 * @var UserService $user_service
36
+	 */
37
+	private $user_service;
38 38
 
39
-    /**
40
-     * Constructor for SosaConfigAction Request Handler
41
-     *
42
-     * @param UserService $user_service
43
-     */
44
-    public function __construct(UserService $user_service)
45
-    {
46
-        $this->user_service = $user_service;
47
-    }
39
+	/**
40
+	 * Constructor for SosaConfigAction Request Handler
41
+	 *
42
+	 * @param UserService $user_service
43
+	 */
44
+	public function __construct(UserService $user_service)
45
+	{
46
+		$this->user_service = $user_service;
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritDoc}
51
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
-     */
53
-    public function handle(ServerRequestInterface $request): ResponseInterface
54
-    {
55
-        $tree = $request->getAttribute('tree');
56
-        assert($tree instanceof Tree);
49
+	/**
50
+	 * {@inheritDoc}
51
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
+	 */
53
+	public function handle(ServerRequestInterface $request): ResponseInterface
54
+	{
55
+		$tree = $request->getAttribute('tree');
56
+		assert($tree instanceof Tree);
57 57
 
58
-        $params = $request->getParsedBody();
59
-        assert(is_array($params));
58
+		$params = $request->getParsedBody();
59
+		assert(is_array($params));
60 60
 
61
-        $user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0);
62
-        $partial_from = $params['partial_from'] ?? null;
61
+		$user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0);
62
+		$partial_from = $params['partial_from'] ?? null;
63 63
 
64
-        if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) {
65
-            $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
64
+		if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) {
65
+			$user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
66 66
 
67
-            /** @var SosaCalculatorService $sosa_calc_service */
68
-            $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]);
67
+			/** @var SosaCalculatorService $sosa_calc_service */
68
+			$sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]);
69 69
 
70
-            if (
71
-                $partial_from !== null &&
72
-                ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null
73
-            ) {
74
-                $res = $sosa_calc_service->computeFromIndividual($sosa_from);
75
-            } else {
76
-                $res = $sosa_calc_service->computeAll();
77
-            }
70
+			if (
71
+				$partial_from !== null &&
72
+				($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null
73
+			) {
74
+				$res = $sosa_calc_service->computeFromIndividual($sosa_from);
75
+			} else {
76
+				$res = $sosa_calc_service->computeAll();
77
+			}
78 78
 
79
-            return $res ?
80
-                response('', 200) :
81
-                response(
82
-                    I18N::translate('An error occurred while computing Sosa ancestors.'),
83
-                    StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR
84
-                );
85
-        }
86
-        return response(
87
-            I18N::translate('You do not have permission to modify the user.'),
88
-            StatusCodeInterface::STATUS_FORBIDDEN
89
-        );
90
-    }
79
+			return $res ?
80
+				response('', 200) :
81
+				response(
82
+					I18N::translate('An error occurred while computing Sosa ancestors.'),
83
+					StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR
84
+				);
85
+		}
86
+		return response(
87
+			I18N::translate('You do not have permission to modify the user.'),
88
+			StatusCodeInterface::STATUS_FORBIDDEN
89
+		);
90
+	}
91 91
 }
Please login to merge, or discard this 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.
src/Webtrees/Module/Sosa/Http/RequestHandlers/SosaConfig.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -31,59 +31,59 @@
 block discarded – undo
31 31
  */
32 32
 class SosaConfig implements RequestHandlerInterface
33 33
 {
34
-    use ViewResponseTrait;
34
+	use ViewResponseTrait;
35 35
 
36
-    /**
37
-     * @var SosaModule $module
38
-     */
39
-    private $module;
36
+	/**
37
+	 * @var SosaModule $module
38
+	 */
39
+	private $module;
40 40
 
41
-    /**
42
-     * Constructor for SosaConfig Request Handler
43
-     *
44
-     * @param ModuleService $module_service
45
-     */
46
-    public function __construct(ModuleService $module_service)
47
-    {
48
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
49
-    }
41
+	/**
42
+	 * Constructor for SosaConfig Request Handler
43
+	 *
44
+	 * @param ModuleService $module_service
45
+	 */
46
+	public function __construct(ModuleService $module_service)
47
+	{
48
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritDoc}
53
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
-     */
55
-    public function handle(ServerRequestInterface $request): ResponseInterface
56
-    {
57
-        if ($this->module === null) {
58
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
-        }
51
+	/**
52
+	 * {@inheritDoc}
53
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
+	 */
55
+	public function handle(ServerRequestInterface $request): ResponseInterface
56
+	{
57
+		if ($this->module === null) {
58
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
+		}
60 60
 
61
-        $tree = $request->getAttribute('tree');
62
-        assert($tree instanceof Tree);
61
+		$tree = $request->getAttribute('tree');
62
+		assert($tree instanceof Tree);
63 63
 
64
-        $users_root = array();
65
-        if (Auth::check()) {
66
-            /** @var \Fisharebest\Webtrees\User $user */
67
-            $user = Auth::user();
68
-            $users_root[] = ['user' => $user, 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID')];
64
+		$users_root = array();
65
+		if (Auth::check()) {
66
+			/** @var \Fisharebest\Webtrees\User $user */
67
+			$user = Auth::user();
68
+			$users_root[] = ['user' => $user, 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID')];
69 69
 
70
-            if (Auth::isManager($tree)) {
71
-                $default_user = new DefaultUser();
72
-                $users_root[] = [
73
-                    'user' => $default_user,
74
-                    'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID')
75
-                ];
76
-            }
77
-        }
70
+			if (Auth::isManager($tree)) {
71
+				$default_user = new DefaultUser();
72
+				$users_root[] = [
73
+					'user' => $default_user,
74
+					'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID')
75
+				];
76
+			}
77
+		}
78 78
 
79
-        return $this->viewResponse($this->module->name() . '::config-page', [
80
-            'module_name'       =>  $this->module->name(),
81
-            'title'             =>  I18N::translate('Sosa Configuration'),
82
-            'tree'              =>  $tree,
83
-            'user_id'           =>  $request->getAttribute('user'),
84
-            'selected_user_id'  =>  (int) ($request->getQueryParams()['user_id'] ?? 0),
85
-            'immediate_compute' =>  ($request->getQueryParams()['compute'] ?? '') == 'yes',
86
-            'users_root'        =>  $users_root
87
-        ]);
88
-    }
79
+		return $this->viewResponse($this->module->name() . '::config-page', [
80
+			'module_name'       =>  $this->module->name(),
81
+			'title'             =>  I18N::translate('Sosa Configuration'),
82
+			'tree'              =>  $tree,
83
+			'user_id'           =>  $request->getAttribute('user'),
84
+			'selected_user_id'  =>  (int) ($request->getQueryParams()['user_id'] ?? 0),
85
+			'immediate_compute' =>  ($request->getQueryParams()['compute'] ?? '') == 'yes',
86
+			'users_root'        =>  $users_root
87
+		]);
88
+	}
89 89
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -76,12 +76,12 @@
 block discarded – undo
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/Http/RequestHandlers/AncestorsList.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -33,59 +33,59 @@
 block discarded – undo
33 33
  */
34 34
 class AncestorsList implements RequestHandlerInterface
35 35
 {
36
-    use ViewResponseTrait;
36
+	use ViewResponseTrait;
37 37
 
38
-    /**
39
-     * @var SosaModule $module
40
-     */
41
-    private $module;
38
+	/**
39
+	 * @var SosaModule $module
40
+	 */
41
+	private $module;
42 42
 
43
-    /**
44
-     * @var SosaRecordsService $sosa_record_service
45
-     */
46
-    private $sosa_record_service;
43
+	/**
44
+	 * @var SosaRecordsService $sosa_record_service
45
+	 */
46
+	private $sosa_record_service;
47 47
 
48
-    /**
49
-     * Constructor for AncestorsList Request Handler
50
-     *
51
-     * @param ModuleService $module_service
52
-     * @param SosaRecordsService $sosa_record_service
53
-     */
54
-    public function __construct(
55
-        ModuleService $module_service,
56
-        SosaRecordsService $sosa_record_service
57
-    ) {
58
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
59
-        $this->sosa_record_service = $sosa_record_service;
60
-    }
48
+	/**
49
+	 * Constructor for AncestorsList Request Handler
50
+	 *
51
+	 * @param ModuleService $module_service
52
+	 * @param SosaRecordsService $sosa_record_service
53
+	 */
54
+	public function __construct(
55
+		ModuleService $module_service,
56
+		SosaRecordsService $sosa_record_service
57
+	) {
58
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
59
+		$this->sosa_record_service = $sosa_record_service;
60
+	}
61 61
 
62
-    /**
63
-     * {@inheritDoc}
64
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
65
-     */
66
-    public function handle(ServerRequestInterface $request): ResponseInterface
67
-    {
68
-        if ($this->module === null) {
69
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
70
-        }
62
+	/**
63
+	 * {@inheritDoc}
64
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
65
+	 */
66
+	public function handle(ServerRequestInterface $request): ResponseInterface
67
+	{
68
+		if ($this->module === null) {
69
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
70
+		}
71 71
 
72
-        $tree = $request->getAttribute('tree');
73
-        assert($tree instanceof Tree);
72
+		$tree = $request->getAttribute('tree');
73
+		assert($tree instanceof Tree);
74 74
 
75
-        $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
75
+		$user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
76 76
 
77
-        /** @var SosaStatisticsService $sosa_stats_service */
78
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
77
+		/** @var SosaStatisticsService $sosa_stats_service */
78
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
79 79
 
80
-        $current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
80
+		$current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
81 81
 
82
-        return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
83
-            'module_name'       =>  $this->module->name(),
84
-            'title'             =>  I18N::translate('Sosa Ancestors'),
85
-            'tree'              =>  $tree,
86
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
87
-            'max_gen'           =>  $sosa_stats_service->maxGeneration(),
88
-            'current_gen'       =>  $current_gen
89
-        ]);
90
-    }
82
+		return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
83
+			'module_name'       =>  $this->module->name(),
84
+			'title'             =>  I18N::translate('Sosa Ancestors'),
85
+			'tree'              =>  $tree,
86
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
87
+			'max_gen'           =>  $sosa_stats_service->maxGeneration(),
88
+			'current_gen'       =>  $current_gen
89
+		]);
90
+	}
91 91
 }
Please login to merge, or discard this 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->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
80
+        $current_gen = (int)($request->getAttribute('gen') ?? $request->getQueryParams()['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/SosaStatistics.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -34,136 +34,136 @@
 block discarded – undo
34 34
  */
35 35
 class SosaStatistics implements RequestHandlerInterface
36 36
 {
37
-    use ViewResponseTrait;
38
-
39
-    /**
40
-     * @var SosaModule $module
41
-     */
42
-    private $module;
43
-
44
-    /**
45
-     * Constructor for AncestorsList Request Handler
46
-     *
47
-     * @param ModuleService $module_service
48
-     */
49
-    public function __construct(ModuleService $module_service)
50
-    {
51
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
52
-    }
53
-
54
-    /**
55
-     * {@inheritDoc}
56
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
57
-     */
58
-    public function handle(ServerRequestInterface $request): ResponseInterface
59
-    {
60
-        if ($this->module === null) {
61
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
62
-        }
63
-
64
-        $tree = $request->getAttribute('tree');
65
-        assert($tree instanceof Tree);
66
-
67
-        $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
68
-
69
-        /** @var SosaStatisticsService $sosa_stats_service */
70
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
71
-
72
-        return $this->viewResponse($this->module->name() . '::statistics-page', [
73
-            'module_name'       =>  $this->module->name(),
74
-            'title'             =>  I18N::translate('Sosa Statistics'),
75
-            'tree'              =>  $tree,
76
-            'theme'             =>  app(ModuleThemeInterface::class),
77
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
78
-            'general_stats'     =>  $this->statisticsGeneral($sosa_stats_service),
79
-            'generation_stats'  =>  $this->statisticsByGenerations($sosa_stats_service),
80
-            'generation_depth'  =>  $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(),
81
-            'multiple_sosas'    =>  $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'),
82
-            'sosa_dispersion_g2' =>  $sosa_stats_service->ancestorsDispersionForGeneration(2),
83
-            'sosa_dispersion_g3' =>  $sosa_stats_service->ancestorsDispersionForGeneration(3),
84
-            'gen_depth_g3'      =>  $sosa_stats_service->generationDepthStatsAtGeneration(3)
85
-        ]);
86
-    }
87
-
88
-    /**
89
-     * Retrieve and compute the global statistics of ancestors for the tree.
90
-     * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse...
91
-     *
92
-     * @param SosaStatisticsService $sosa_stats_service
93
-     * @return array<string, int|float>
94
-     */
95
-    private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array
96
-    {
97
-        $ancestors_count = $sosa_stats_service->totalAncestors();
98
-        $ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors();
99
-        $individual_count = $sosa_stats_service->totalIndividuals();
100
-
101
-        return [
102
-            'sosa_count'            =>  $ancestors_count,
103
-            'distinct_count'        =>  $ancestors_distinct_count,
104
-            'sosa_rate'             =>  $this->safeDivision($ancestors_distinct_count, $individual_count),
105
-            'pedi_collapse'         =>  1 - $this->safeDivision($ancestors_distinct_count, $ancestors_count),
106
-            'mean_gen_time'         =>  $sosa_stats_service->meanGenerationTime()
107
-        ];
108
-    }
109
-
110
-    /**
111
-     * Retrieve and compute the statistics of ancestors by generations.
112
-     * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics...
113
-     *
114
-     * @param SosaStatisticsService $sosa_stats_service
115
-     * @return array<int, array<string, int|float>>
116
-     */
117
-    private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array
118
-    {
119
-        $stats_by_gen = $sosa_stats_service->statisticsByGenerations();
120
-
121
-        $generation_stats = array();
122
-
123
-        foreach ($stats_by_gen as $gen => $stats_gen) {
124
-            $gen_diff = $gen > 1 ?
125
-                (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
126
-                1;
127
-            $generation_stats[$gen] = array(
128
-                'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
129
-                'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
130
-                'theoretical' => pow(2, $gen - 1),
131
-                'known' => (int) $stats_gen['sosaCount'],
132
-                'perc_known' => $this->safeDivision((int) $stats_gen['sosaCount'], pow(2, $gen - 1)),
133
-                'missing' => $gen > 1 ?
134
-                    2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
135
-                    0,
136
-                'perc_missing' => $gen > 1 ?
137
-                    1 - $this->safeDivision(
138
-                        (int) $stats_gen['sosaCount'],
139
-                        2 * (int) $stats_by_gen[$gen - 1]['sosaCount']
140
-                    ) :
141
-                    0,
142
-                'total_known' => (int) $stats_gen['sosaTotalCount'],
143
-                'perc_total_known' => $this->safeDivision((int) $stats_gen['sosaTotalCount'], pow(2, $gen) - 1),
144
-                'different' => $gen_diff,
145
-                'perc_different' => $this->safeDivision($gen_diff, (int) $stats_gen['sosaCount']),
146
-                'total_different' => (int) $stats_gen['diffSosaTotalCount'],
147
-                'pedi_collapse' => 1 - $this->safeDivision(
148
-                    (int) $stats_gen['diffSosaTotalCount'],
149
-                    (int) $stats_gen['sosaTotalCount']
150
-                )
151
-            );
152
-        }
153
-
154
-        return $generation_stats;
155
-    }
156
-
157
-    /**
158
-     * Return the result of a division, and a default value if denominator is 0
159
-     *
160
-     * @param int $p Numerator
161
-     * @param int $q Denominator
162
-     * @param float $default Value if denominator is 0
163
-     * @return float
164
-     */
165
-    private function safeDivision(int $p, int $q, float $default = 0): float
166
-    {
167
-        return $q == 0 ? $default : $p / $q;
168
-    }
37
+	use ViewResponseTrait;
38
+
39
+	/**
40
+	 * @var SosaModule $module
41
+	 */
42
+	private $module;
43
+
44
+	/**
45
+	 * Constructor for AncestorsList Request Handler
46
+	 *
47
+	 * @param ModuleService $module_service
48
+	 */
49
+	public function __construct(ModuleService $module_service)
50
+	{
51
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
52
+	}
53
+
54
+	/**
55
+	 * {@inheritDoc}
56
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
57
+	 */
58
+	public function handle(ServerRequestInterface $request): ResponseInterface
59
+	{
60
+		if ($this->module === null) {
61
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
62
+		}
63
+
64
+		$tree = $request->getAttribute('tree');
65
+		assert($tree instanceof Tree);
66
+
67
+		$user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
68
+
69
+		/** @var SosaStatisticsService $sosa_stats_service */
70
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
71
+
72
+		return $this->viewResponse($this->module->name() . '::statistics-page', [
73
+			'module_name'       =>  $this->module->name(),
74
+			'title'             =>  I18N::translate('Sosa Statistics'),
75
+			'tree'              =>  $tree,
76
+			'theme'             =>  app(ModuleThemeInterface::class),
77
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
78
+			'general_stats'     =>  $this->statisticsGeneral($sosa_stats_service),
79
+			'generation_stats'  =>  $this->statisticsByGenerations($sosa_stats_service),
80
+			'generation_depth'  =>  $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(),
81
+			'multiple_sosas'    =>  $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'),
82
+			'sosa_dispersion_g2' =>  $sosa_stats_service->ancestorsDispersionForGeneration(2),
83
+			'sosa_dispersion_g3' =>  $sosa_stats_service->ancestorsDispersionForGeneration(3),
84
+			'gen_depth_g3'      =>  $sosa_stats_service->generationDepthStatsAtGeneration(3)
85
+		]);
86
+	}
87
+
88
+	/**
89
+	 * Retrieve and compute the global statistics of ancestors for the tree.
90
+	 * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse...
91
+	 *
92
+	 * @param SosaStatisticsService $sosa_stats_service
93
+	 * @return array<string, int|float>
94
+	 */
95
+	private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array
96
+	{
97
+		$ancestors_count = $sosa_stats_service->totalAncestors();
98
+		$ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors();
99
+		$individual_count = $sosa_stats_service->totalIndividuals();
100
+
101
+		return [
102
+			'sosa_count'            =>  $ancestors_count,
103
+			'distinct_count'        =>  $ancestors_distinct_count,
104
+			'sosa_rate'             =>  $this->safeDivision($ancestors_distinct_count, $individual_count),
105
+			'pedi_collapse'         =>  1 - $this->safeDivision($ancestors_distinct_count, $ancestors_count),
106
+			'mean_gen_time'         =>  $sosa_stats_service->meanGenerationTime()
107
+		];
108
+	}
109
+
110
+	/**
111
+	 * Retrieve and compute the statistics of ancestors by generations.
112
+	 * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics...
113
+	 *
114
+	 * @param SosaStatisticsService $sosa_stats_service
115
+	 * @return array<int, array<string, int|float>>
116
+	 */
117
+	private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array
118
+	{
119
+		$stats_by_gen = $sosa_stats_service->statisticsByGenerations();
120
+
121
+		$generation_stats = array();
122
+
123
+		foreach ($stats_by_gen as $gen => $stats_gen) {
124
+			$gen_diff = $gen > 1 ?
125
+				(int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
126
+				1;
127
+			$generation_stats[$gen] = array(
128
+				'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
129
+				'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
130
+				'theoretical' => pow(2, $gen - 1),
131
+				'known' => (int) $stats_gen['sosaCount'],
132
+				'perc_known' => $this->safeDivision((int) $stats_gen['sosaCount'], pow(2, $gen - 1)),
133
+				'missing' => $gen > 1 ?
134
+					2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
135
+					0,
136
+				'perc_missing' => $gen > 1 ?
137
+					1 - $this->safeDivision(
138
+						(int) $stats_gen['sosaCount'],
139
+						2 * (int) $stats_by_gen[$gen - 1]['sosaCount']
140
+					) :
141
+					0,
142
+				'total_known' => (int) $stats_gen['sosaTotalCount'],
143
+				'perc_total_known' => $this->safeDivision((int) $stats_gen['sosaTotalCount'], pow(2, $gen) - 1),
144
+				'different' => $gen_diff,
145
+				'perc_different' => $this->safeDivision($gen_diff, (int) $stats_gen['sosaCount']),
146
+				'total_different' => (int) $stats_gen['diffSosaTotalCount'],
147
+				'pedi_collapse' => 1 - $this->safeDivision(
148
+					(int) $stats_gen['diffSosaTotalCount'],
149
+					(int) $stats_gen['sosaTotalCount']
150
+				)
151
+			);
152
+		}
153
+
154
+		return $generation_stats;
155
+	}
156
+
157
+	/**
158
+	 * Return the result of a division, and a default value if denominator is 0
159
+	 *
160
+	 * @param int $p Numerator
161
+	 * @param int $q Denominator
162
+	 * @param float $default Value if denominator is 0
163
+	 * @return float
164
+	 */
165
+	private function safeDivision(int $p, int $q, float $default = 0): float
166
+	{
167
+		return $q == 0 ? $default : $p / $q;
168
+	}
169 169
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -19 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         /** @var SosaStatisticsService $sosa_stats_service */
70 70
         $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
71 71
 
72
-        return $this->viewResponse($this->module->name() . '::statistics-page', [
72
+        return $this->viewResponse($this->module->name().'::statistics-page', [
73 73
             'module_name'       =>  $this->module->name(),
74 74
             'title'             =>  I18N::translate('Sosa Statistics'),
75 75
             'tree'              =>  $tree,
@@ -122,31 +122,28 @@  discard block
 block discarded – undo
122 122
 
123 123
         foreach ($stats_by_gen as $gen => $stats_gen) {
124 124
             $gen_diff = $gen > 1 ?
125
-                (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
126
-                1;
125
+                (int)$stats_gen['diffSosaTotalCount'] - (int)$stats_by_gen[$gen - 1]['diffSosaTotalCount'] : 1;
127 126
             $generation_stats[$gen] = array(
128
-                'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
129
-                'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
127
+                'gen_min_birth' => $stats_gen['firstBirth'] ?? (int)$stats_gen['firstEstimatedBirth'],
128
+                'gen_max_birth' => $stats_gen['lastBirth'] ?? (int)$stats_gen['lastEstimatedBirth'],
130 129
                 'theoretical' => pow(2, $gen - 1),
131
-                'known' => (int) $stats_gen['sosaCount'],
132
-                'perc_known' => $this->safeDivision((int) $stats_gen['sosaCount'], pow(2, $gen - 1)),
130
+                'known' => (int)$stats_gen['sosaCount'],
131
+                'perc_known' => $this->safeDivision((int)$stats_gen['sosaCount'], pow(2, $gen - 1)),
133 132
                 'missing' => $gen > 1 ?
134
-                    2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
135
-                    0,
133
+                    2 * (int)$stats_by_gen[$gen - 1]['sosaCount'] - (int)$stats_gen['sosaCount'] : 0,
136 134
                 'perc_missing' => $gen > 1 ?
137 135
                     1 - $this->safeDivision(
138
-                        (int) $stats_gen['sosaCount'],
139
-                        2 * (int) $stats_by_gen[$gen - 1]['sosaCount']
140
-                    ) :
141
-                    0,
142
-                'total_known' => (int) $stats_gen['sosaTotalCount'],
143
-                'perc_total_known' => $this->safeDivision((int) $stats_gen['sosaTotalCount'], pow(2, $gen) - 1),
136
+                        (int)$stats_gen['sosaCount'],
137
+                        2 * (int)$stats_by_gen[$gen - 1]['sosaCount']
138
+                    ) : 0,
139
+                'total_known' => (int)$stats_gen['sosaTotalCount'],
140
+                'perc_total_known' => $this->safeDivision((int)$stats_gen['sosaTotalCount'], pow(2, $gen) - 1),
144 141
                 'different' => $gen_diff,
145
-                'perc_different' => $this->safeDivision($gen_diff, (int) $stats_gen['sosaCount']),
146
-                'total_different' => (int) $stats_gen['diffSosaTotalCount'],
142
+                'perc_different' => $this->safeDivision($gen_diff, (int)$stats_gen['sosaCount']),
143
+                'total_different' => (int)$stats_gen['diffSosaTotalCount'],
147 144
                 'pedi_collapse' => 1 - $this->safeDivision(
148
-                    (int) $stats_gen['diffSosaTotalCount'],
149
-                    (int) $stats_gen['sosaTotalCount']
145
+                    (int)$stats_gen['diffSosaTotalCount'],
146
+                    (int)$stats_gen['sosaTotalCount']
150 147
                 )
151 148
             );
152 149
         }
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Schema/Migration0.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@
 block discarded – undo
22 22
 class Migration0 implements MigrationInterface
23 23
 {
24 24
 
25
-    /**
26
-     * {@inheritDoc}
27
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
28
-     */
29
-    public function upgrade(): void
30
-    {
31
-        // These migrations have been merged into migration 2.
32
-    }
25
+	/**
26
+	 * {@inheritDoc}
27
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
28
+	 */
29
+	public function upgrade(): void
30
+	{
31
+		// These migrations have been merged into migration 2.
32
+	}
33 33
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Schema/Migration2.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -24,36 +24,36 @@
 block discarded – undo
24 24
 class Migration2 implements MigrationInterface
25 25
 {
26 26
 
27
-    /**
28
-     * {@inheritDoc}
29
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
30
-     */
31
-    public function upgrade(): void
32
-    {
33
-
34
-        // Clean up previous sosa table if it exists
35
-        DB::schema()->dropIfExists('maj_sosa');
36
-
37
-        DB::schema()->create('maj_sosa', static function (Blueprint $table): void {
38
-
39
-            $table->integer('majs_gedcom_id');
40
-            $table->integer('majs_user_id')->default(-1);
41
-            $table->bigInteger('majs_sosa')->unsigned(); // Allow to calculate sosa on 64 generations
42
-            $table->string('majs_i_id', 20);
43
-            $table->tinyInteger('majs_gen')->nullable();
44
-            $table->smallInteger('majs_birth_year')->nullable();
45
-            $table->smallInteger('majs_birth_year_est')->nullable();
46
-            $table->smallInteger('majs_death_year')->nullable();
47
-            $table->smallInteger('majs_death_year_est')->nullable();
48
-
49
-            $table->primary(['majs_gedcom_id', 'majs_user_id', 'majs_sosa']);
50
-
51
-            $table->index(['majs_gedcom_id', 'majs_user_id']);
52
-            $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_i_id']);
53
-            $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_gen']);
54
-
55
-            $table->foreign('majs_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade');
56
-            $table->foreign('majs_user_id')->references('user_id')->on('user')->onDelete('cascade');
57
-        });
58
-    }
27
+	/**
28
+	 * {@inheritDoc}
29
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
30
+	 */
31
+	public function upgrade(): void
32
+	{
33
+
34
+		// Clean up previous sosa table if it exists
35
+		DB::schema()->dropIfExists('maj_sosa');
36
+
37
+		DB::schema()->create('maj_sosa', static function (Blueprint $table): void {
38
+
39
+			$table->integer('majs_gedcom_id');
40
+			$table->integer('majs_user_id')->default(-1);
41
+			$table->bigInteger('majs_sosa')->unsigned(); // Allow to calculate sosa on 64 generations
42
+			$table->string('majs_i_id', 20);
43
+			$table->tinyInteger('majs_gen')->nullable();
44
+			$table->smallInteger('majs_birth_year')->nullable();
45
+			$table->smallInteger('majs_birth_year_est')->nullable();
46
+			$table->smallInteger('majs_death_year')->nullable();
47
+			$table->smallInteger('majs_death_year_est')->nullable();
48
+
49
+			$table->primary(['majs_gedcom_id', 'majs_user_id', 'majs_sosa']);
50
+
51
+			$table->index(['majs_gedcom_id', 'majs_user_id']);
52
+			$table->index(['majs_gedcom_id', 'majs_user_id', 'majs_i_id']);
53
+			$table->index(['majs_gedcom_id', 'majs_user_id', 'majs_gen']);
54
+
55
+			$table->foreign('majs_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade');
56
+			$table->foreign('majs_user_id')->references('user_id')->on('user')->onDelete('cascade');
57
+		});
58
+	}
59 59
 }
Please login to merge, or discard this 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.
src/Webtrees/Module/Sosa/Services/SosaStatisticsService.php 2 patches
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -29,367 +29,367 @@
 block discarded – undo
29 29
 class SosaStatisticsService
30 30
 {
31 31
 
32
-    /**
33
-     * Reference user
34
-     * @var User $user
35
-     */
36
-    private $user;
32
+	/**
33
+	 * Reference user
34
+	 * @var User $user
35
+	 */
36
+	private $user;
37 37
 
38
-    /**
39
-     * Reference tree
40
-     * @var Tree $tree
41
-     */
42
-    private $tree;
38
+	/**
39
+	 * Reference tree
40
+	 * @var Tree $tree
41
+	 */
42
+	private $tree;
43 43
 
44
-    /**
45
-     * Constructor for Sosa Statistics Service
46
-     *
47
-     * @param Tree $tree
48
-     * @param User $user
49
-     */
50
-    public function __construct(Tree $tree, User $user)
51
-    {
52
-        $this->tree = $tree;
53
-        $this->user = $user;
54
-    }
44
+	/**
45
+	 * Constructor for Sosa Statistics Service
46
+	 *
47
+	 * @param Tree $tree
48
+	 * @param User $user
49
+	 */
50
+	public function __construct(Tree $tree, User $user)
51
+	{
52
+		$this->tree = $tree;
53
+		$this->user = $user;
54
+	}
55 55
 
56
-    /**
57
-     * Return the root individual for the reference tree and user.
58
-     *
59
-     * @return Individual|NULL
60
-     */
61
-    public function rootIndividual(): ?Individual
62
-    {
63
-        $root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
64
-        return Registry::individualFactory()->make($root_indi_id, $this->tree);
65
-    }
56
+	/**
57
+	 * Return the root individual for the reference tree and user.
58
+	 *
59
+	 * @return Individual|NULL
60
+	 */
61
+	public function rootIndividual(): ?Individual
62
+	{
63
+		$root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
64
+		return Registry::individualFactory()->make($root_indi_id, $this->tree);
65
+	}
66 66
 
67
-    /**
68
-     * Get the highest generation for the reference tree and user.
69
-     *
70
-     * @return int
71
-     */
72
-    public function maxGeneration(): int
73
-    {
74
-        return (int) DB::table('maj_sosa')
75
-            ->where('majs_gedcom_id', '=', $this->tree->id())
76
-            ->where('majs_user_id', '=', $this->user->id())
77
-            ->max('majs_gen');
78
-    }
67
+	/**
68
+	 * Get the highest generation for the reference tree and user.
69
+	 *
70
+	 * @return int
71
+	 */
72
+	public function maxGeneration(): int
73
+	{
74
+		return (int) DB::table('maj_sosa')
75
+			->where('majs_gedcom_id', '=', $this->tree->id())
76
+			->where('majs_user_id', '=', $this->user->id())
77
+			->max('majs_gen');
78
+	}
79 79
 
80
-    /**
81
-     * Get the total count of individuals in the tree.
82
-     *
83
-     * @return int
84
-     */
85
-    public function totalIndividuals(): int
86
-    {
87
-        return DB::table('individuals')
88
-            ->where('i_file', '=', $this->tree->id())
89
-            ->count();
90
-    }
80
+	/**
81
+	 * Get the total count of individuals in the tree.
82
+	 *
83
+	 * @return int
84
+	 */
85
+	public function totalIndividuals(): int
86
+	{
87
+		return DB::table('individuals')
88
+			->where('i_file', '=', $this->tree->id())
89
+			->count();
90
+	}
91 91
 
92
-    /**
93
-     * Get the total count of Sosa ancestors for all generations
94
-     *
95
-     * @return int
96
-     */
97
-    public function totalAncestors(): int
98
-    {
99
-        return DB::table('maj_sosa')
100
-            ->where('majs_gedcom_id', '=', $this->tree->id())
101
-            ->where('majs_user_id', '=', $this->user->id())
102
-            ->count();
103
-    }
92
+	/**
93
+	 * Get the total count of Sosa ancestors for all generations
94
+	 *
95
+	 * @return int
96
+	 */
97
+	public function totalAncestors(): int
98
+	{
99
+		return DB::table('maj_sosa')
100
+			->where('majs_gedcom_id', '=', $this->tree->id())
101
+			->where('majs_user_id', '=', $this->user->id())
102
+			->count();
103
+	}
104 104
 
105
-    /**
106
-     * Get the total count of Sosa ancestors for a generation
107
-     *
108
-     * @return int
109
-     */
110
-    public function totalAncestorsAtGeneration(int $gen): int
111
-    {
112
-        return DB::table('maj_sosa')
113
-            ->where('majs_gedcom_id', '=', $this->tree->id())
114
-            ->where('majs_user_id', '=', $this->user->id())
115
-            ->where('majs_gen', '=', $gen)
116
-            ->count();
117
-    }
105
+	/**
106
+	 * Get the total count of Sosa ancestors for a generation
107
+	 *
108
+	 * @return int
109
+	 */
110
+	public function totalAncestorsAtGeneration(int $gen): int
111
+	{
112
+		return DB::table('maj_sosa')
113
+			->where('majs_gedcom_id', '=', $this->tree->id())
114
+			->where('majs_user_id', '=', $this->user->id())
115
+			->where('majs_gen', '=', $gen)
116
+			->count();
117
+	}
118 118
 
119
-    /**
120
-     * Get the total count of distinct Sosa ancestors for all generations
121
-     *
122
-     * @return int
123
-     */
124
-    public function totalDistinctAncestors(): int
125
-    {
126
-        return DB::table('maj_sosa')
127
-            ->where('majs_gedcom_id', '=', $this->tree->id())
128
-            ->where('majs_user_id', '=', $this->user->id())
129
-            ->distinct()
130
-            ->count('majs_i_id');
131
-    }
119
+	/**
120
+	 * Get the total count of distinct Sosa ancestors for all generations
121
+	 *
122
+	 * @return int
123
+	 */
124
+	public function totalDistinctAncestors(): int
125
+	{
126
+		return DB::table('maj_sosa')
127
+			->where('majs_gedcom_id', '=', $this->tree->id())
128
+			->where('majs_user_id', '=', $this->user->id())
129
+			->distinct()
130
+			->count('majs_i_id');
131
+	}
132 132
 
133
-    /**
134
-     * Get the mean generation time, as the slope of the linear regression of birth years vs generations
135
-     *
136
-     * @return float
137
-     */
138
-    public function meanGenerationTime(): float
139
-    {
140
-        $row = DB::table('maj_sosa')
141
-            ->where('majs_gedcom_id', '=', $this->tree->id())
142
-            ->where('majs_user_id', '=', $this->user->id())
143
-            ->whereNotNull('majs_birth_year')
144
-            ->selectRaw('COUNT(majs_sosa) AS n')
145
-            ->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy')
146
-            ->selectRaw('SUM(majs_gen) AS sum_x')
147
-            ->selectRaw('SUM(majs_birth_year) AS sum_y')
148
-            ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2')
149
-            ->get()->first();
133
+	/**
134
+	 * Get the mean generation time, as the slope of the linear regression of birth years vs generations
135
+	 *
136
+	 * @return float
137
+	 */
138
+	public function meanGenerationTime(): float
139
+	{
140
+		$row = DB::table('maj_sosa')
141
+			->where('majs_gedcom_id', '=', $this->tree->id())
142
+			->where('majs_user_id', '=', $this->user->id())
143
+			->whereNotNull('majs_birth_year')
144
+			->selectRaw('COUNT(majs_sosa) AS n')
145
+			->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy')
146
+			->selectRaw('SUM(majs_gen) AS sum_x')
147
+			->selectRaw('SUM(majs_birth_year) AS sum_y')
148
+			->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2')
149
+			->get()->first();
150 150
 
151
-        return $row->n == 0 ? 0 :
152
-            -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2));
153
-    }
151
+		return $row->n == 0 ? 0 :
152
+			-($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2));
153
+	}
154 154
 
155
-    /**
156
-     * Get the statistic array detailed by generation.
157
-     * Statistics for each generation are:
158
-     *  - The number of Sosa in generation
159
-     *  - The number of Sosa up to generation
160
-     *  - The number of distinct Sosa up to generation
161
-     *  - The year of the first birth in generation
162
-     *  - The year of the first estimated birth in generation
163
-     *  - The year of the last birth in generation
164
-     *  - The year of the last estimated birth in generation
165
-     *  - The average year of birth in generation
166
-     *
167
-     * @return array<int, array<string, int|null>> Statistics array
168
-     */
169
-    public function statisticsByGenerations(): array
170
-    {
171
-        $stats_by_gen = $this->statisticsByGenerationBasicData();
172
-        $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData();
155
+	/**
156
+	 * Get the statistic array detailed by generation.
157
+	 * Statistics for each generation are:
158
+	 *  - The number of Sosa in generation
159
+	 *  - The number of Sosa up to generation
160
+	 *  - The number of distinct Sosa up to generation
161
+	 *  - The year of the first birth in generation
162
+	 *  - The year of the first estimated birth in generation
163
+	 *  - The year of the last birth in generation
164
+	 *  - The year of the last estimated birth in generation
165
+	 *  - The average year of birth in generation
166
+	 *
167
+	 * @return array<int, array<string, int|null>> Statistics array
168
+	 */
169
+	public function statisticsByGenerations(): array
170
+	{
171
+		$stats_by_gen = $this->statisticsByGenerationBasicData();
172
+		$cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData();
173 173
 
174
-        $statistics_by_gen = [];
175
-        foreach ($stats_by_gen as $gen => $stats_gen) {
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,
180
-                'firstBirth'            =>  $stats_gen->first_year,
181
-                'firstEstimatedBirth'   =>  $stats_gen->first_est_year,
182
-                'lastBirth'             =>  $stats_gen->last_year,
183
-                'lastEstimatedBirth'    =>  $stats_gen->last_est_year
184
-            );
185
-        }
174
+		$statistics_by_gen = [];
175
+		foreach ($stats_by_gen as $gen => $stats_gen) {
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,
180
+				'firstBirth'            =>  $stats_gen->first_year,
181
+				'firstEstimatedBirth'   =>  $stats_gen->first_est_year,
182
+				'lastBirth'             =>  $stats_gen->last_year,
183
+				'lastEstimatedBirth'    =>  $stats_gen->last_est_year
184
+			);
185
+		}
186 186
 
187
-        return $statistics_by_gen;
188
-    }
187
+		return $statistics_by_gen;
188
+	}
189 189
 
190
-    /**
191
-     * Returns the basic statistics data by generation.
192
-     *
193
-     * @return Collection
194
-     */
195
-    private function statisticsByGenerationBasicData(): Collection
196
-    {
197
-        return DB::table('maj_sosa')
198
-            ->where('majs_gedcom_id', '=', $this->tree->id())
199
-            ->where('majs_user_id', '=', $this->user->id())
200
-            ->groupBy('majs_gen')
201
-            ->orderBy('majs_gen', 'asc')
202
-            ->select('majs_gen AS gen')
203
-            ->selectRaw('COUNT(majs_sosa) AS total_sosa')
204
-            ->selectRaw('MIN(majs_birth_year) AS first_year')
205
-            ->selectRaw('MIN(majs_birth_year_est) AS first_est_year')
206
-            ->selectRaw('MAX(majs_birth_year) AS last_year')
207
-            ->selectRaw('MAX(majs_birth_year_est) AS last_est_year')
208
-            ->get()->keyBy('gen');
209
-    }
190
+	/**
191
+	 * Returns the basic statistics data by generation.
192
+	 *
193
+	 * @return Collection
194
+	 */
195
+	private function statisticsByGenerationBasicData(): Collection
196
+	{
197
+		return DB::table('maj_sosa')
198
+			->where('majs_gedcom_id', '=', $this->tree->id())
199
+			->where('majs_user_id', '=', $this->user->id())
200
+			->groupBy('majs_gen')
201
+			->orderBy('majs_gen', 'asc')
202
+			->select('majs_gen AS gen')
203
+			->selectRaw('COUNT(majs_sosa) AS total_sosa')
204
+			->selectRaw('MIN(majs_birth_year) AS first_year')
205
+			->selectRaw('MIN(majs_birth_year_est) AS first_est_year')
206
+			->selectRaw('MAX(majs_birth_year) AS last_year')
207
+			->selectRaw('MAX(majs_birth_year_est) AS last_est_year')
208
+			->get()->keyBy('gen');
209
+	}
210 210
 
211
-    /**
212
-     * Returns the cumulative statistics data by generation
213
-     *
214
-     * @return Collection
215
-     */
216
-    private function statisticsByGenerationCumulativeData(): Collection
217
-    {
218
-        $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
219
-            ->where('majs_gedcom_id', '=', $this->tree->id())
220
-            ->where('majs_user_id', '=', $this->user->id());
211
+	/**
212
+	 * Returns the cumulative statistics data by generation
213
+	 *
214
+	 * @return Collection
215
+	 */
216
+	private function statisticsByGenerationCumulativeData(): Collection
217
+	{
218
+		$list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
219
+			->where('majs_gedcom_id', '=', $this->tree->id())
220
+			->where('majs_user_id', '=', $this->user->id());
221 221
 
222
-        return DB::table('maj_sosa')
223
-            ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
224
-                $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen')
225
-                ->where('majs_gedcom_id', '=', $this->tree->id())
226
-                ->where('majs_user_id', '=', $this->user->id());
227
-            })
228
-            ->groupBy('list_gen.majs_gen')
229
-            ->select('list_gen.majs_gen AS gen')
230
-            ->selectRaw('COUNT(majs_i_id) AS total_cumul')
231
-            ->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul')
232
-            ->get()->keyBy('gen');
233
-    }
222
+		return DB::table('maj_sosa')
223
+			->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
224
+				$join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen')
225
+				->where('majs_gedcom_id', '=', $this->tree->id())
226
+				->where('majs_user_id', '=', $this->user->id());
227
+			})
228
+			->groupBy('list_gen.majs_gen')
229
+			->select('list_gen.majs_gen AS gen')
230
+			->selectRaw('COUNT(majs_i_id) AS total_cumul')
231
+			->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul')
232
+			->get()->keyBy('gen');
233
+	}
234 234
 
235
-    /**
236
-     * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation.
237
-     * Sosa 1 is of generation 1.
238
-     *
239
-     * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes,
240
-     * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140
241
-     * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0
242
-     *
243
-     * Format:
244
-     *  - key : sosa number of the ancestor
245
-     *  - values:
246
-     *      - root_ancestor_id : ID of the ancestor
247
-     *      - mean_gen_depth : Mean generation depth
248
-     *      - stddev_gen_depth : Standard deviation of generation depth
249
-     *
250
-     * @param int $gen Sosa generation
251
-     * @return Collection
252
-     */
253
-    public function generationDepthStatsAtGeneration(int $gen): Collection
254
-    {
255
-        $table_prefix = DB::connection()->getTablePrefix();
256
-        $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa')
257
-            ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
258
-            ->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
259
-            ->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
260
-            ->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
261
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
262
-                // Link to sosa's father
263
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
264
-                ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
265
-                ->where('sosa_fat.majs_user_id', '=', $this->user->id());
266
-            })
267
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
268
-                // Link to sosa's mother
269
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
270
-                ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
271
-                ->where('sosa_mot.majs_user_id', '=', $this->user->id());
272
-            })
273
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
274
-            ->where('sosa.majs_user_id', '=', $this->user->id())
275
-            ->where('sosa.majs_gen', '>=', $gen)
276
-            ->where(function (Builder $query): void {
277
-                $query->whereNull('sosa_fat.majs_i_id')
278
-                    ->orWhereNull('sosa_mot.majs_i_id');
279
-            })
280
-            ->groupBy(['sosa.majs_gen', 'root_ancestor']);
235
+	/**
236
+	 * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation.
237
+	 * Sosa 1 is of generation 1.
238
+	 *
239
+	 * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes,
240
+	 * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140
241
+	 * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0
242
+	 *
243
+	 * Format:
244
+	 *  - key : sosa number of the ancestor
245
+	 *  - values:
246
+	 *      - root_ancestor_id : ID of the ancestor
247
+	 *      - mean_gen_depth : Mean generation depth
248
+	 *      - stddev_gen_depth : Standard deviation of generation depth
249
+	 *
250
+	 * @param int $gen Sosa generation
251
+	 * @return Collection
252
+	 */
253
+	public function generationDepthStatsAtGeneration(int $gen): Collection
254
+	{
255
+		$table_prefix = DB::connection()->getTablePrefix();
256
+		$missing_ancestors_by_gen = DB::table('maj_sosa AS sosa')
257
+			->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
258
+			->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
259
+			->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
260
+			->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
261
+			->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
262
+				// Link to sosa's father
263
+				$join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
264
+				->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
265
+				->where('sosa_fat.majs_user_id', '=', $this->user->id());
266
+			})
267
+			->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
268
+				// Link to sosa's mother
269
+				$join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
270
+				->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
271
+				->where('sosa_mot.majs_user_id', '=', $this->user->id());
272
+			})
273
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
274
+			->where('sosa.majs_user_id', '=', $this->user->id())
275
+			->where('sosa.majs_gen', '>=', $gen)
276
+			->where(function (Builder $query): void {
277
+				$query->whereNull('sosa_fat.majs_i_id')
278
+					->orWhereNull('sosa_mot.majs_i_id');
279
+			})
280
+			->groupBy(['sosa.majs_gen', 'root_ancestor']);
281 281
 
282
-        return DB::table('maj_sosa AS sosa_list')
283
-            ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id'])
284
-            ->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
285
-            ->selectRaw(' SQRT(' .
286
-                '   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
287
-                '   - 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
288
-                ' ) AS stddev_gen_depth')
289
-            ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void {
290
-                $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor')
291
-                    ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id())
292
-                    ->where('sosa_list.majs_user_id', '=', $this->user->id());
293
-            })
294
-            ->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id'])
295
-            ->orderBy('stats_by_gen.root_ancestor')
296
-            ->get()->keyBy('root_ancestor_sosa');
297
-    }
282
+		return DB::table('maj_sosa AS sosa_list')
283
+			->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id'])
284
+			->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
285
+			->selectRaw(' SQRT(' .
286
+				'   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
287
+				'   - 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
288
+				' ) AS stddev_gen_depth')
289
+			->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void {
290
+				$join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor')
291
+					->where('sosa_list.majs_gedcom_id', '=', $this->tree->id())
292
+					->where('sosa_list.majs_user_id', '=', $this->user->id());
293
+			})
294
+			->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id'])
295
+			->orderBy('stats_by_gen.root_ancestor')
296
+			->get()->keyBy('root_ancestor_sosa');
297
+	}
298 298
 
299
-    /**
300
-     * Return a collection of the most duplicated root Sosa ancestors.
301
-     * The number of ancestors to return is limited by the parameter $limit.
302
-     * If several individuals are tied when reaching the limit, none of them are returned,
303
-     * which means that there can be less individuals returned than requested.
304
-     *
305
-     * Format:
306
-     *  - value:
307
-     *      - sosa_i_id : sosa individual
308
-     *      - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times)
309
-     *
310
-     * @param int $limit
311
-     * @return Collection
312
-     */
313
-    public function topMultipleAncestorsWithNoTies(int $limit): Collection
314
-    {
315
-        $table_prefix = DB::connection()->getTablePrefix();
316
-        $multiple_ancestors = DB::table('maj_sosa AS sosa')
317
-            ->select('sosa.majs_i_id AS sosa_i_id')
318
-            ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count')
319
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
320
-                // Link to sosa's father
321
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
322
-                    ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
323
-                    ->where('sosa_fat.majs_user_id', '=', $this->user->id());
324
-            })
325
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
326
-                // Link to sosa's mother
327
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
328
-                ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
329
-                ->where('sosa_mot.majs_user_id', '=', $this->user->id());
330
-            })
331
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
332
-            ->where('sosa.majs_user_id', '=', $this->user->id())
333
-            ->whereNull('sosa_fat.majs_sosa')   // We keep only root individuals, i.e. those with no father or mother
334
-            ->whereNull('sosa_mot.majs_sosa')
335
-            ->groupBy('sosa.majs_i_id')
336
-            ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
337
-            ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC')   //@phpcs:ignore Generic.Files.LineLength.TooLong
338
-            ->limit($limit + 1)     // We want to select one more than required, for ties
339
-            ->get();
299
+	/**
300
+	 * Return a collection of the most duplicated root Sosa ancestors.
301
+	 * The number of ancestors to return is limited by the parameter $limit.
302
+	 * If several individuals are tied when reaching the limit, none of them are returned,
303
+	 * which means that there can be less individuals returned than requested.
304
+	 *
305
+	 * Format:
306
+	 *  - value:
307
+	 *      - sosa_i_id : sosa individual
308
+	 *      - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times)
309
+	 *
310
+	 * @param int $limit
311
+	 * @return Collection
312
+	 */
313
+	public function topMultipleAncestorsWithNoTies(int $limit): Collection
314
+	{
315
+		$table_prefix = DB::connection()->getTablePrefix();
316
+		$multiple_ancestors = DB::table('maj_sosa AS sosa')
317
+			->select('sosa.majs_i_id AS sosa_i_id')
318
+			->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count')
319
+			->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
320
+				// Link to sosa's father
321
+				$join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
322
+					->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
323
+					->where('sosa_fat.majs_user_id', '=', $this->user->id());
324
+			})
325
+			->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
326
+				// Link to sosa's mother
327
+				$join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
328
+				->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
329
+				->where('sosa_mot.majs_user_id', '=', $this->user->id());
330
+			})
331
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
332
+			->where('sosa.majs_user_id', '=', $this->user->id())
333
+			->whereNull('sosa_fat.majs_sosa')   // We keep only root individuals, i.e. those with no father or mother
334
+			->whereNull('sosa_mot.majs_sosa')
335
+			->groupBy('sosa.majs_i_id')
336
+			->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
337
+			->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC')   //@phpcs:ignore Generic.Files.LineLength.TooLong
338
+			->limit($limit + 1)     // We want to select one more than required, for ties
339
+			->get();
340 340
 
341
-        if ($multiple_ancestors->count() > $limit) {
342
-            $last_count = $multiple_ancestors->last()->sosa_count;
343
-            $multiple_ancestors = $multiple_ancestors->reject(function ($element) use ($last_count): bool {
344
-                return $element->sosa_count ==  $last_count;
345
-            });
346
-        }
347
-        return $multiple_ancestors;
348
-    }
341
+		if ($multiple_ancestors->count() > $limit) {
342
+			$last_count = $multiple_ancestors->last()->sosa_count;
343
+			$multiple_ancestors = $multiple_ancestors->reject(function ($element) use ($last_count): bool {
344
+				return $element->sosa_count ==  $last_count;
345
+			});
346
+		}
347
+		return $multiple_ancestors;
348
+	}
349 349
 
350
-    /**
351
-     * Return a computed array of statistics about the dispersion of ancestors across the ancestors
352
-     * at a specified generation.
353
-     *
354
-     * Format:
355
-     *  - key : rank of the ancestor in generation G for which exclusive ancestors have been found
356
-     *          For instance 3 represent the maternal grand father
357
-     *          0 is used for shared ancestors
358
-     *  - values: number of ancestors exclusively in the ancestors of the ancestor in key
359
-     *
360
-     *  For instance a result at generation 3 could be :
361
-     *      array (   0     =>  12      -> 12 ancestors are shared by the grand-parents
362
-     *                1     =>  32      -> 32 ancestors are exclusive to the paternal grand-father
363
-     *                2     =>  25      -> 25 ancestors are exclusive to the paternal grand-mother
364
-     *                3     =>  12      -> 12 ancestors are exclusive to the maternal grand-father
365
-     *                4     =>  30      -> 30 ancestors are exclusive to the maternal grand-mother
366
-     *            )
367
-     *
368
-     * @param int $gen
369
-     * @return Collection
370
-     */
371
-    public function ancestorsDispersionForGeneration(int $gen): Collection
372
-    {
373
-        $ancestors_branches = DB::table('maj_sosa')
374
-            ->select('majs_i_id AS i_id')
375
-            ->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen])
376
-            ->where('majs_gedcom_id', '=', $this->tree->id())
377
-            ->where('majs_user_id', '=', $this->user->id())
378
-            ->where('majs_gen', '>=', $gen)
379
-            ->groupBy('majs_i_id', 'branch');
350
+	/**
351
+	 * Return a computed array of statistics about the dispersion of ancestors across the ancestors
352
+	 * at a specified generation.
353
+	 *
354
+	 * Format:
355
+	 *  - key : rank of the ancestor in generation G for which exclusive ancestors have been found
356
+	 *          For instance 3 represent the maternal grand father
357
+	 *          0 is used for shared ancestors
358
+	 *  - values: number of ancestors exclusively in the ancestors of the ancestor in key
359
+	 *
360
+	 *  For instance a result at generation 3 could be :
361
+	 *      array (   0     =>  12      -> 12 ancestors are shared by the grand-parents
362
+	 *                1     =>  32      -> 32 ancestors are exclusive to the paternal grand-father
363
+	 *                2     =>  25      -> 25 ancestors are exclusive to the paternal grand-mother
364
+	 *                3     =>  12      -> 12 ancestors are exclusive to the maternal grand-father
365
+	 *                4     =>  30      -> 30 ancestors are exclusive to the maternal grand-mother
366
+	 *            )
367
+	 *
368
+	 * @param int $gen
369
+	 * @return Collection
370
+	 */
371
+	public function ancestorsDispersionForGeneration(int $gen): Collection
372
+	{
373
+		$ancestors_branches = DB::table('maj_sosa')
374
+			->select('majs_i_id AS i_id')
375
+			->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen])
376
+			->where('majs_gedcom_id', '=', $this->tree->id())
377
+			->where('majs_user_id', '=', $this->user->id())
378
+			->where('majs_gen', '>=', $gen)
379
+			->groupBy('majs_i_id', 'branch');
380 380
 
381 381
 
382
-        $consolidated_ancestors_branches = DB::table('maj_sosa')
383
-            ->fromSub($ancestors_branches, 'indi_branch')
384
-            ->select('i_id')
385
-            ->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches')
386
-            ->groupBy('i_id');
382
+		$consolidated_ancestors_branches = DB::table('maj_sosa')
383
+			->fromSub($ancestors_branches, 'indi_branch')
384
+			->select('i_id')
385
+			->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches')
386
+			->groupBy('i_id');
387 387
 
388
-        return DB::table('maj_sosa')
389
-            ->fromSub($consolidated_ancestors_branches, 'indi_branch_consolidated')
390
-            ->select('branches')
391
-            ->selectRaw('COUNT(i_id) AS count_indi')
392
-            ->groupBy('branches')
393
-            ->get()->pluck('count_indi', 'branches');
394
-    }
388
+		return DB::table('maj_sosa')
389
+			->fromSub($consolidated_ancestors_branches, 'indi_branch_consolidated')
390
+			->select('branches')
391
+			->selectRaw('COUNT(i_id) AS count_indi')
392
+			->groupBy('branches')
393
+			->get()->pluck('count_indi', 'branches');
394
+	}
395 395
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -30 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function maxGeneration(): int
73 73
     {
74
-        return (int) DB::table('maj_sosa')
74
+        return (int)DB::table('maj_sosa')
75 75
             ->where('majs_gedcom_id', '=', $this->tree->id())
76 76
             ->where('majs_user_id', '=', $this->user->id())
77 77
             ->max('majs_gen');
@@ -148,8 +148,7 @@  discard block
 block discarded – undo
148 148
             ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2')
149 149
             ->get()->first();
150 150
 
151
-        return $row->n == 0 ? 0 :
152
-            -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2));
151
+        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));
153 152
     }
154 153
 
155 154
     /**
@@ -173,10 +172,10 @@  discard block
 block discarded – undo
173 172
 
174 173
         $statistics_by_gen = [];
175 174
         foreach ($stats_by_gen as $gen => $stats_gen) {
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,
175
+            $statistics_by_gen[(int)$stats_gen->gen] = array(
176
+                'sosaCount'             =>  (int)$stats_gen->total_sosa,
177
+                'sosaTotalCount'        =>  (int)$cumul_stats_by_gen[$gen]->total_cumul,
178
+                'diffSosaTotalCount'    =>  (int)$cumul_stats_by_gen[$gen]->total_distinct_cumul,
180 179
                 'firstBirth'            =>  $stats_gen->first_year,
181 180
                 'firstEstimatedBirth'   =>  $stats_gen->first_est_year,
182 181
                 'lastBirth'             =>  $stats_gen->last_year,
@@ -220,7 +219,7 @@  discard block
 block discarded – undo
220 219
             ->where('majs_user_id', '=', $this->user->id());
221 220
 
222 221
         return DB::table('maj_sosa')
223
-            ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
222
+            ->joinSub($list_gen, 'list_gen', function(JoinClause $join): void {
224 223
                 $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen')
225 224
                 ->where('majs_gedcom_id', '=', $this->tree->id())
226 225
                 ->where('majs_user_id', '=', $this->user->id());
@@ -254,26 +253,26 @@  discard block
 block discarded – undo
254 253
     {
255 254
         $table_prefix = DB::connection()->getTablePrefix();
256 255
         $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa')
257
-            ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
258
-            ->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
259
-            ->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
260
-            ->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
261
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
256
+            ->selectRaw($table_prefix.'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
257
+            ->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
258
+            ->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
259
+            ->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
260
+            ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void {
262 261
                 // Link to sosa's father
263
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
262
+                $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa')
264 263
                 ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
265 264
                 ->where('sosa_fat.majs_user_id', '=', $this->user->id());
266 265
             })
267
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
266
+            ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void {
268 267
                 // Link to sosa's mother
269
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
268
+                $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1')
270 269
                 ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
271 270
                 ->where('sosa_mot.majs_user_id', '=', $this->user->id());
272 271
             })
273 272
             ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
274 273
             ->where('sosa.majs_user_id', '=', $this->user->id())
275 274
             ->where('sosa.majs_gen', '>=', $gen)
276
-            ->where(function (Builder $query): void {
275
+            ->where(function(Builder $query): void {
277 276
                 $query->whereNull('sosa_fat.majs_i_id')
278 277
                     ->orWhereNull('sosa_mot.majs_i_id');
279 278
             })
@@ -282,11 +281,11 @@  discard block
 block discarded – undo
282 281
         return DB::table('maj_sosa AS sosa_list')
283 282
             ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id'])
284 283
             ->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
285
-            ->selectRaw(' SQRT(' .
286
-                '   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
287
-                '   - 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
284
+            ->selectRaw(' SQRT('.
285
+                '   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
286
+                '   - 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
288 287
                 ' ) AS stddev_gen_depth')
289
-            ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void {
288
+            ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function(JoinClause $join): void {
290 289
                 $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor')
291 290
                     ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id())
292 291
                     ->where('sosa_list.majs_user_id', '=', $this->user->id());
@@ -315,16 +314,16 @@  discard block
 block discarded – undo
315 314
         $table_prefix = DB::connection()->getTablePrefix();
316 315
         $multiple_ancestors = DB::table('maj_sosa AS sosa')
317 316
             ->select('sosa.majs_i_id AS sosa_i_id')
318
-            ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count')
319
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
317
+            ->selectRaw('COUNT('.$table_prefix.'sosa.majs_sosa) AS sosa_count')
318
+            ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void {
320 319
                 // Link to sosa's father
321
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
320
+                $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa')
322 321
                     ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
323 322
                     ->where('sosa_fat.majs_user_id', '=', $this->user->id());
324 323
             })
325
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
324
+            ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void {
326 325
                 // Link to sosa's mother
327
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
326
+                $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1')
328 327
                 ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
329 328
                 ->where('sosa_mot.majs_user_id', '=', $this->user->id());
330 329
             })
@@ -333,15 +332,15 @@  discard block
 block discarded – undo
333 332
             ->whereNull('sosa_fat.majs_sosa')   // We keep only root individuals, i.e. those with no father or mother
334 333
             ->whereNull('sosa_mot.majs_sosa')
335 334
             ->groupBy('sosa.majs_i_id')
336
-            ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
337
-            ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC')   //@phpcs:ignore Generic.Files.LineLength.TooLong
335
+            ->havingRaw('COUNT('.$table_prefix.'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
336
+            ->orderByRaw('COUNT('.$table_prefix.'sosa.majs_sosa) DESC, MIN('.$table_prefix.'sosa.majs_sosa) ASC')   //@phpcs:ignore Generic.Files.LineLength.TooLong
338 337
             ->limit($limit + 1)     // We want to select one more than required, for ties
339 338
             ->get();
340 339
 
341 340
         if ($multiple_ancestors->count() > $limit) {
342 341
             $last_count = $multiple_ancestors->last()->sosa_count;
343
-            $multiple_ancestors = $multiple_ancestors->reject(function ($element) use ($last_count): bool {
344
-                return $element->sosa_count ==  $last_count;
342
+            $multiple_ancestors = $multiple_ancestors->reject(function($element) use ($last_count): bool {
343
+                return $element->sosa_count == $last_count;
345 344
             });
346 345
         }
347 346
         return $multiple_ancestors;
Please login to merge, or discard this patch.