Passed
Branch main (9d419d)
by Jonathan
04:01
created
app/Module/Hooks/Http/RequestHandlers/AdminConfigPage.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -29,38 +29,38 @@
 block discarded – undo
29 29
  */
30 30
 class AdminConfigPage implements RequestHandlerInterface
31 31
 {
32
-    use ViewResponseTrait;
32
+	use ViewResponseTrait;
33 33
 
34
-    private ?HooksModule $module;
35
-    private HookService $hook_service;
34
+	private ?HooksModule $module;
35
+	private HookService $hook_service;
36 36
 
37
-    /**
38
-     * Constructor for AdminConfigPage Request Handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     * @param HookService $hook_service
42
-     */
43
-    public function __construct(ModuleService $module_service, HookService $hook_service)
44
-    {
45
-        $this->module = $module_service->findByInterface(HooksModule::class)->first();
46
-        $this->hook_service = $hook_service;
47
-    }
37
+	/**
38
+	 * Constructor for AdminConfigPage Request Handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 * @param HookService $hook_service
42
+	 */
43
+	public function __construct(ModuleService $module_service, HookService $hook_service)
44
+	{
45
+		$this->module = $module_service->findByInterface(HooksModule::class)->first();
46
+		$this->hook_service = $hook_service;
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritDoc}
51
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
-     */
53
-    public function handle(ServerRequestInterface $request): ResponseInterface
54
-    {
55
-        $this->layout = 'layouts/administration';
49
+	/**
50
+	 * {@inheritDoc}
51
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
+	 */
53
+	public function handle(ServerRequestInterface $request): ResponseInterface
54
+	{
55
+		$this->layout = 'layouts/administration';
56 56
 
57
-        if ($this->module === null) {
58
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
-        }
57
+		if ($this->module === null) {
58
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
+		}
60 60
 
61
-        return $this->viewResponse($this->module->name() . '::admin/config', [
62
-            'title'                 =>  $this->module->title(),
63
-            'hook_interfaces_list'  =>  $this->hook_service->all(true)
64
-        ]);
65
-    }
61
+		return $this->viewResponse($this->module->name() . '::admin/config', [
62
+			'title'                 =>  $this->module->title(),
63
+			'hook_interfaces_list'  =>  $this->hook_service->all(true)
64
+		]);
65
+	}
66 66
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
             throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59 59
         }
60 60
 
61
-        return $this->viewResponse($this->module->name() . '::admin/config', [
61
+        return $this->viewResponse($this->module->name().'::admin/config', [
62 62
             'title'                 =>  $this->module->title(),
63 63
             'hook_interfaces_list'  =>  $this->hook_service->all(true)
64 64
         ]);
Please login to merge, or discard this patch.
app/Module/Hooks/Schema/Migration1.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
             DB::schema()->drop('maj_hooks');
35 35
         }
36 36
 
37
-        DB::schema()->create('maj_hook_order', static function (Blueprint $table): void {
37
+        DB::schema()->create('maj_hook_order', static function(Blueprint $table): void {
38 38
             $table->string('majho_module_name', 32);
39 39
             $table->string('majho_hook_name', 64);
40 40
             $table->integer('majho_hook_order')->nullable();
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -23,28 +23,28 @@
 block discarded – undo
23 23
  */
24 24
 class Migration1 implements MigrationInterface
25 25
 {
26
-    /**
27
-     * {@inheritDoc}
28
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
29
-     */
30
-    public function upgrade(): void
31
-    {
32
-        $in_transaction = DB::connection()->getPdo()->inTransaction();
33
-
34
-        if (DB::schema()->hasTable('maj_hooks')) {
35
-            DB::schema()->drop('maj_hooks');
36
-        }
37
-
38
-        DB::schema()->create('maj_hook_order', static function (Blueprint $table): void {
39
-            $table->string('majho_module_name', 32);
40
-            $table->string('majho_hook_name', 64);
41
-            $table->integer('majho_hook_order')->nullable();
42
-
43
-            $table->primary(['majho_module_name', 'majho_hook_name']);
44
-        });
45
-
46
-        if ($in_transaction && !DB::connection()->getPdo()->inTransaction()) {
47
-            DB::connection()->beginTransaction();
48
-        }
49
-    }
26
+	/**
27
+	 * {@inheritDoc}
28
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
29
+	 */
30
+	public function upgrade(): void
31
+	{
32
+		$in_transaction = DB::connection()->getPdo()->inTransaction();
33
+
34
+		if (DB::schema()->hasTable('maj_hooks')) {
35
+			DB::schema()->drop('maj_hooks');
36
+		}
37
+
38
+		DB::schema()->create('maj_hook_order', static function (Blueprint $table): void {
39
+			$table->string('majho_module_name', 32);
40
+			$table->string('majho_hook_name', 64);
41
+			$table->integer('majho_hook_order')->nullable();
42
+
43
+			$table->primary(['majho_module_name', 'majho_hook_name']);
44
+		});
45
+
46
+		if ($in_transaction && !DB::connection()->getPdo()->inTransaction()) {
47
+			DB::connection()->beginTransaction();
48
+		}
49
+	}
50 50
 }
Please login to merge, or discard this patch.
app/Module/Hooks/Services/HookService.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function all(bool $include_disabled = false): Collection
76 76
     {
77
-        return Registry::cache()->array()->remember('all-hooks', function () use ($include_disabled): Collection {
77
+        return Registry::cache()->array()->remember('all-hooks', function() use ($include_disabled): Collection {
78 78
             $hooks_info = DB::table('maj_hook_order')
79 79
                 ->get()
80 80
                 ->groupBy(['majho_hook_name', 'majho_module_name']);
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
                     ) as $hook_instance
105 105
                 ) {
106 106
                     $hook_module_info = $hook_info->get($hook_instance->module()->name(), collect())->first();
107
-                    $hook_order = $hook_module_info instanceof stdClass ? (int) $hook_module_info->majho_hook_order : 0;
107
+                    $hook_order = $hook_module_info instanceof stdClass ? (int)$hook_module_info->majho_hook_order : 0;
108 108
                     $hook_collector->register($hook_instance, $hook_order);
109 109
                 }
110 110
             }
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -30,101 +30,101 @@
 block discarded – undo
30 30
  */
31 31
 class HookService implements HookServiceInterface
32 32
 {
33
-    private ModuleService $module_service;
33
+	private ModuleService $module_service;
34 34
 
35
-    /**
36
-     * Constructor for HookService
37
-     *
38
-     * @param ModuleService $module_service
39
-     */
40
-    public function __construct(ModuleService $module_service)
41
-    {
42
-        $this->module_service = $module_service;
43
-    }
35
+	/**
36
+	 * Constructor for HookService
37
+	 *
38
+	 * @param ModuleService $module_service
39
+	 */
40
+	public function __construct(ModuleService $module_service)
41
+	{
42
+		$this->module_service = $module_service;
43
+	}
44 44
 
45
-    /**
46
-     * {@inheritDoc}
47
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookServiceInterface::use()
48
-     */
49
-    public function use(string $hook_interface): ?HookCollectorInterface
50
-    {
51
-        return $this->all()->get($hook_interface);
52
-    }
45
+	/**
46
+	 * {@inheritDoc}
47
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookServiceInterface::use()
48
+	 */
49
+	public function use(string $hook_interface): ?HookCollectorInterface
50
+	{
51
+		return $this->all()->get($hook_interface);
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Find a hook collector by its name, with or without the disabled ones.
57
-     *
58
-     * @param string $hook_name
59
-     * @return HookCollectorInterface|null
60
-     */
61
-    public function find(string $hook_name, bool $include_disabled = false): ?HookCollectorInterface
62
-    {
63
-        return $this->all($include_disabled)
64
-            ->first(fn(HookCollectorInterface $hook_collector) => $hook_collector->name() === $hook_name);
65
-    }
55
+	/**
56
+	 * Find a hook collector by its name, with or without the disabled ones.
57
+	 *
58
+	 * @param string $hook_name
59
+	 * @return HookCollectorInterface|null
60
+	 */
61
+	public function find(string $hook_name, bool $include_disabled = false): ?HookCollectorInterface
62
+	{
63
+		return $this->all($include_disabled)
64
+			->first(fn(HookCollectorInterface $hook_collector) => $hook_collector->name() === $hook_name);
65
+	}
66 66
 
67
-    /**
68
-     * Get all hook collectors subscribed by modules, with hooks ordered, with or without the disabled ones.
69
-     *
70
-     * @param bool $include_disabled
71
-     * @return Collection<string, HookCollectorInterface>
72
-     */
73
-    public function all(bool $include_disabled = false): Collection
74
-    {
75
-        return Registry::cache()->array()->remember('all-hooks', function () use ($include_disabled): Collection {
76
-            $hooks_info = DB::table('maj_hook_order')
77
-                ->get()
78
-                ->groupBy(['majho_hook_name', 'majho_module_name']);
67
+	/**
68
+	 * Get all hook collectors subscribed by modules, with hooks ordered, with or without the disabled ones.
69
+	 *
70
+	 * @param bool $include_disabled
71
+	 * @return Collection<string, HookCollectorInterface>
72
+	 */
73
+	public function all(bool $include_disabled = false): Collection
74
+	{
75
+		return Registry::cache()->array()->remember('all-hooks', function () use ($include_disabled): Collection {
76
+			$hooks_info = DB::table('maj_hook_order')
77
+				->get()
78
+				->groupBy(['majho_hook_name', 'majho_module_name']);
79 79
 
80
-            $hooks = $this->module_service
81
-                ->findByInterface(ModuleHookSubscriberInterface::class, $include_disabled)
82
-                ->flatMap(fn(ModuleHookSubscriberInterface $module) => $module->listSubscribedHooks());
80
+			$hooks = $this->module_service
81
+				->findByInterface(ModuleHookSubscriberInterface::class, $include_disabled)
82
+				->flatMap(fn(ModuleHookSubscriberInterface $module) => $module->listSubscribedHooks());
83 83
 
84
-            $hook_collectors = collect();
85
-            $hook_instances = collect();
86
-            foreach ($hooks as $hook) {
87
-                if (!($hook instanceof HookInterface)) {
88
-                    continue;
89
-                }
90
-                if ($hook instanceof HookCollectorInterface) {
91
-                    $hook_collectors->put($hook->hookInterface(), $hook);
92
-                } else {
93
-                    $hook_instances->add($hook);
94
-                }
95
-            }
84
+			$hook_collectors = collect();
85
+			$hook_instances = collect();
86
+			foreach ($hooks as $hook) {
87
+				if (!($hook instanceof HookInterface)) {
88
+					continue;
89
+				}
90
+				if ($hook instanceof HookCollectorInterface) {
91
+					$hook_collectors->put($hook->hookInterface(), $hook);
92
+				} else {
93
+					$hook_instances->add($hook);
94
+				}
95
+			}
96 96
 
97
-            foreach ($hook_collectors as $hook_interface => $hook_collector) {
98
-                $hook_info = $hooks_info->get($hook_collector->name()) ?? collect();
99
-                foreach (
100
-                    $hook_instances->filter(
101
-                        fn(HookInterface $hook): bool => $hook instanceof $hook_interface
102
-                    ) as $hook_instance
103
-                ) {
104
-                    $hook_module_info = $hook_info->get($hook_instance->module()->name(), collect())->first();
105
-                    $hook_order = $hook_module_info instanceof stdClass ? (int) $hook_module_info->majho_hook_order : 0;
106
-                    $hook_collector->register($hook_instance, $hook_order);
107
-                }
108
-            }
109
-            return $hook_collectors;
110
-        });
111
-    }
97
+			foreach ($hook_collectors as $hook_interface => $hook_collector) {
98
+				$hook_info = $hooks_info->get($hook_collector->name()) ?? collect();
99
+				foreach (
100
+					$hook_instances->filter(
101
+						fn(HookInterface $hook): bool => $hook instanceof $hook_interface
102
+					) as $hook_instance
103
+				) {
104
+					$hook_module_info = $hook_info->get($hook_instance->module()->name(), collect())->first();
105
+					$hook_order = $hook_module_info instanceof stdClass ? (int) $hook_module_info->majho_hook_order : 0;
106
+					$hook_collector->register($hook_instance, $hook_order);
107
+				}
108
+			}
109
+			return $hook_collectors;
110
+		});
111
+	}
112 112
 
113
-    /**
114
-     * Update the order of the modules implementing a hook in the database.
115
-     *
116
-     * @param HookCollectorInterface $hook_collector
117
-     * @param ModuleInterface $module
118
-     * @param int $order
119
-     * @return int
120
-     */
121
-    public function updateOrder(HookCollectorInterface $hook_collector, ModuleInterface $module, int $order): int
122
-    {
123
-        return DB::table('maj_hook_order')
124
-            ->upsert([
125
-                'majho_module_name' =>  $module->name(),
126
-                'majho_hook_name'   =>  $hook_collector->name(),
127
-                'majho_hook_order'  =>  $order
128
-            ], ['majho_module_name', 'majho_hook_name'], ['majho_hook_order']);
129
-    }
113
+	/**
114
+	 * Update the order of the modules implementing a hook in the database.
115
+	 *
116
+	 * @param HookCollectorInterface $hook_collector
117
+	 * @param ModuleInterface $module
118
+	 * @param int $order
119
+	 * @return int
120
+	 */
121
+	public function updateOrder(HookCollectorInterface $hook_collector, ModuleInterface $module, int $order): int
122
+	{
123
+		return DB::table('maj_hook_order')
124
+			->upsert([
125
+				'majho_module_name' =>  $module->name(),
126
+				'majho_hook_name'   =>  $hook_collector->name(),
127
+				'majho_hook_order'  =>  $order
128
+			], ['majho_module_name', 'majho_hook_name'], ['majho_hook_order']);
129
+	}
130 130
 }
Please login to merge, or discard this patch.
app/Module/MiscExtensions/Http/RequestHandlers/AdminConfigPage.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -28,35 +28,35 @@
 block discarded – undo
28 28
  */
29 29
 class AdminConfigPage implements RequestHandlerInterface
30 30
 {
31
-    use ViewResponseTrait;
32
-
33
-    private ?MiscExtensionsModule $module;
34
-
35
-    /**
36
-     * Constructor for AdminConfigPage Request Handler
37
-     *
38
-     * @param ModuleService $module_service
39
-     */
40
-    public function __construct(ModuleService $module_service)
41
-    {
42
-        $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first();
43
-    }
44
-
45
-    /**
46
-     * {@inheritDoc}
47
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
48
-     */
49
-    public function handle(ServerRequestInterface $request): ResponseInterface
50
-    {
51
-        $this->layout = 'layouts/administration';
52
-
53
-        if ($this->module === null) {
54
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
55
-        }
56
-
57
-        return $this->viewResponse($this->module->name() . '::admin/config', [
58
-            'module'    =>  $this->module,
59
-            'title'     =>  $this->module->title()
60
-        ]);
61
-    }
31
+	use ViewResponseTrait;
32
+
33
+	private ?MiscExtensionsModule $module;
34
+
35
+	/**
36
+	 * Constructor for AdminConfigPage Request Handler
37
+	 *
38
+	 * @param ModuleService $module_service
39
+	 */
40
+	public function __construct(ModuleService $module_service)
41
+	{
42
+		$this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first();
43
+	}
44
+
45
+	/**
46
+	 * {@inheritDoc}
47
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
48
+	 */
49
+	public function handle(ServerRequestInterface $request): ResponseInterface
50
+	{
51
+		$this->layout = 'layouts/administration';
52
+
53
+		if ($this->module === null) {
54
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
55
+		}
56
+
57
+		return $this->viewResponse($this->module->name() . '::admin/config', [
58
+			'module'    =>  $this->module,
59
+			'title'     =>  $this->module->title()
60
+		]);
61
+	}
62 62
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
             throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
55 55
         }
56 56
 
57
-        return $this->viewResponse($this->module->name() . '::admin/config', [
57
+        return $this->viewResponse($this->module->name().'::admin/config', [
58 58
             'module'    =>  $this->module,
59 59
             'title'     =>  $this->module->title()
60 60
         ]);
Please login to merge, or discard this patch.
app/Module/MiscExtensions/MiscExtensionsModule.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     public function boot(): void
68 68
     {
69 69
         $this->traitBoot();
70
-        View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy');
70
+        View::registerCustomView('::modules/privacy-policy/page', $this->name().'::privacy-policy');
71 71
     }
72 72
 
73 73
     /**
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function loadRoutes(Map $router): void
78 78
     {
79
-        $router->attach('', '', static function (Map $router): void {
79
+        $router->attach('', '', static function(Map $router): void {
80 80
 
81
-            $router->attach('', '/module-maj/misc', static function (Map $router): void {
81
+            $router->attach('', '/module-maj/misc', static function(Map $router): void {
82 82
 
83
-                $router->attach('', '/config/admin', static function (Map $router): void {
83
+                $router->attach('', '/config/admin', static function(Map $router): void {
84 84
 
85 85
                     $router->get(AdminConfigPage::class, '', AdminConfigPage::class);
86 86
                     $router->post(AdminConfigAction::class, '', AdminConfigAction::class);
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     public function listSubscribedHooks(): array
115 115
     {
116 116
         return [
117
-            app()->makeWith(TitlesCardHook::class, [ 'module' => $this ])
117
+            app()->makeWith(TitlesCardHook::class, ['module' => $this])
118 118
         ];
119 119
     }
120 120
 }
Please login to merge, or discard this patch.
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -32,89 +32,89 @@
 block discarded – undo
32 32
  * Provide miscellaneous improvements to webtrees.
33 33
  */
34 34
 class MiscExtensionsModule extends AbstractModule implements
35
-    ModuleMyArtJaubInterface,
36
-    ModuleConfigInterface,
37
-    ModuleHookSubscriberInterface
35
+	ModuleMyArtJaubInterface,
36
+	ModuleConfigInterface,
37
+	ModuleHookSubscriberInterface
38 38
 {
39
-    use ModuleMyArtJaubTrait {
40
-        boot as traitBoot;
41
-    }
42
-    use ModuleConfigTrait;
39
+	use ModuleMyArtJaubTrait {
40
+		boot as traitBoot;
41
+	}
42
+	use ModuleConfigTrait;
43 43
 
44
-    /**
45
-     * {@inheritDoc}
46
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
47
-     */
48
-    public function title(): string
49
-    {
50
-        return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions');
51
-    }
44
+	/**
45
+	 * {@inheritDoc}
46
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
47
+	 */
48
+	public function title(): string
49
+	{
50
+		return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions');
51
+	}
52 52
 
53
-    /**
54
-     * {@inheritDoc}
55
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
56
-     */
57
-    public function description(): string
58
-    {
59
-        //phpcs:ignore Generic.Files.LineLength.TooLong
60
-        return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.');
61
-    }
53
+	/**
54
+	 * {@inheritDoc}
55
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
56
+	 */
57
+	public function description(): string
58
+	{
59
+		//phpcs:ignore Generic.Files.LineLength.TooLong
60
+		return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.');
61
+	}
62 62
 
63
-    /**
64
-     * {@inheritDoc}
65
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
66
-     */
67
-    public function boot(): void
68
-    {
69
-        $this->traitBoot();
70
-        View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy');
71
-    }
63
+	/**
64
+	 * {@inheritDoc}
65
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
66
+	 */
67
+	public function boot(): void
68
+	{
69
+		$this->traitBoot();
70
+		View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy');
71
+	}
72 72
 
73
-    /**
74
-     * {@inheritDoc}
75
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
76
-     */
77
-    public function loadRoutes(Map $router): void
78
-    {
79
-        $router->attach('', '', static function (Map $router): void {
73
+	/**
74
+	 * {@inheritDoc}
75
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
76
+	 */
77
+	public function loadRoutes(Map $router): void
78
+	{
79
+		$router->attach('', '', static function (Map $router): void {
80 80
 
81
-            $router->attach('', '/module-maj/misc', static function (Map $router): void {
81
+			$router->attach('', '/module-maj/misc', static function (Map $router): void {
82 82
 
83
-                $router->attach('', '/config/admin', static function (Map $router): void {
83
+				$router->attach('', '/config/admin', static function (Map $router): void {
84 84
 
85
-                    $router->get(AdminConfigPage::class, '', AdminConfigPage::class);
86
-                    $router->post(AdminConfigAction::class, '', AdminConfigAction::class);
87
-                });
88
-            });
89
-        });
90
-    }
85
+					$router->get(AdminConfigPage::class, '', AdminConfigPage::class);
86
+					$router->post(AdminConfigAction::class, '', AdminConfigAction::class);
87
+				});
88
+			});
89
+		});
90
+	}
91 91
 
92
-    /**
93
-     * {@inheritDoc}
94
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
95
-     */
96
-    public function customModuleVersion(): string
97
-    {
98
-        return '2.1.3-v.1';
99
-    }
92
+	/**
93
+	 * {@inheritDoc}
94
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
95
+	 */
96
+	public function customModuleVersion(): string
97
+	{
98
+		return '2.1.3-v.1';
99
+	}
100 100
 
101
-    /**
102
-     * {@inheritDoc}
103
-     * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
104
-     */
105
-    public function getConfigLink(): string
106
-    {
107
-        return route(AdminConfigPage::class);
108
-    }
101
+	/**
102
+	 * {@inheritDoc}
103
+	 * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
104
+	 */
105
+	public function getConfigLink(): string
106
+	{
107
+		return route(AdminConfigPage::class);
108
+	}
109 109
 
110
-    /**
111
-     * {@inheritDoc}
112
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
113
-     */
114
-    public function listSubscribedHooks(): array
115
-    {
116
-        return [
117
-            app()->makeWith(TitlesCardHook::class, [ 'module' => $this ])
118
-        ];
119
-    }
110
+	/**
111
+	 * {@inheritDoc}
112
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
113
+	 */
114
+	public function listSubscribedHooks(): array
115
+	{
116
+		return [
117
+			app()->makeWith(TitlesCardHook::class, [ 'module' => $this ])
118
+		];
119
+	}
120 120
 }
Please login to merge, or discard this patch.
app/Module/ModuleMyArtJaubTrait.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function boot(): void
35 35
     {
36
-        View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/');
36
+        View::registerNamespace($this->name(), $this->resourcesFolder().'views/');
37 37
 
38 38
         $this->loadRoutes(app(RouterContainer::class)->getMap());
39 39
     }
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function resourcesFolder(): string
45 45
     {
46
-        return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/';
46
+        return Webtrees::MODULES_DIR.trim($this->name(), '_').'/resources/';
47 47
     }
48 48
 
49 49
     /**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function customTranslations(string $language): array
71 71
     {
72
-        $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php';
72
+        $translation_file = $this->resourcesFolder().'lang/'.$language.'/messages.php';
73 73
 
74 74
         try {
75 75
             $translation  = new Translation($translation_file);
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
     {
95 95
         /** @var ModuleThemeInterface $theme */
96 96
         $theme = app(ModuleThemeInterface::class);
97
-        $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css';
97
+        $css_file = $this->resourcesFolder().'css/'.$theme->name().'.min.css';
98 98
 
99 99
         if (file_exists($css_file)) {
100
-            return $this->assetUrl('css/' . $theme->name() . '.min.css');
100
+            return $this->assetUrl('css/'.$theme->name().'.min.css');
101 101
         } else {
102 102
             return $this->assetUrl('css/default.min.css');
103 103
         }
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -26,82 +26,82 @@
 block discarded – undo
26 26
  */
27 27
 trait ModuleMyArtJaubTrait
28 28
 {
29
-    use ModuleCustomTrait;
30
-
31
-    /**
32
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
33
-     */
34
-    public function boot(): void
35
-    {
36
-        View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/');
37
-
38
-        $this->loadRoutes(app(RouterContainer::class)->getMap());
39
-    }
40
-
41
-    /**
42
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder()
43
-     */
44
-    public function resourcesFolder(): string
45
-    {
46
-        return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/';
47
-    }
48
-
49
-    /**
50
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName()
51
-     */
52
-    public function customModuleAuthorName(): string
53
-    {
54
-        return 'Jonathan Jaubart';
55
-    }
56
-
57
-    /**
58
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl()
59
-     */
60
-    public function customModuleSupportUrl(): string
61
-    {
62
-        return 'https://github.com/jon48/webtrees-lib';
63
-    }
64
-
65
-    /**
66
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations()
67
-     *
68
-     * @return array<string, string>
69
-     */
70
-    public function customTranslations(string $language): array
71
-    {
72
-        $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php';
73
-
74
-        try {
75
-            $translation  = new Translation($translation_file);
76
-            return $translation->asArray();
77
-        } catch (\Exception $e) {
78
-        }
79
-
80
-        return [];
81
-    }
82
-
83
-    /**
84
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes
85
-     *
86
-     * @param Map<\Aura\Router\Route> $router
87
-     */
88
-    public function loadRoutes(Map $router): void
89
-    {
90
-    }
91
-
92
-    /**
93
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl
94
-     */
95
-    public function moduleCssUrl(): string
96
-    {
97
-        /** @var ModuleThemeInterface $theme */
98
-        $theme = app(ModuleThemeInterface::class);
99
-        $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css';
100
-
101
-        if (file_exists($css_file)) {
102
-            return $this->assetUrl('css/' . $theme->name() . '.min.css');
103
-        } else {
104
-            return $this->assetUrl('css/default.min.css');
105
-        }
106
-    }
29
+	use ModuleCustomTrait;
30
+
31
+	/**
32
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
33
+	 */
34
+	public function boot(): void
35
+	{
36
+		View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/');
37
+
38
+		$this->loadRoutes(app(RouterContainer::class)->getMap());
39
+	}
40
+
41
+	/**
42
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder()
43
+	 */
44
+	public function resourcesFolder(): string
45
+	{
46
+		return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/';
47
+	}
48
+
49
+	/**
50
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName()
51
+	 */
52
+	public function customModuleAuthorName(): string
53
+	{
54
+		return 'Jonathan Jaubart';
55
+	}
56
+
57
+	/**
58
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl()
59
+	 */
60
+	public function customModuleSupportUrl(): string
61
+	{
62
+		return 'https://github.com/jon48/webtrees-lib';
63
+	}
64
+
65
+	/**
66
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations()
67
+	 *
68
+	 * @return array<string, string>
69
+	 */
70
+	public function customTranslations(string $language): array
71
+	{
72
+		$translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php';
73
+
74
+		try {
75
+			$translation  = new Translation($translation_file);
76
+			return $translation->asArray();
77
+		} catch (\Exception $e) {
78
+		}
79
+
80
+		return [];
81
+	}
82
+
83
+	/**
84
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes
85
+	 *
86
+	 * @param Map<\Aura\Router\Route> $router
87
+	 */
88
+	public function loadRoutes(Map $router): void
89
+	{
90
+	}
91
+
92
+	/**
93
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl
94
+	 */
95
+	public function moduleCssUrl(): string
96
+	{
97
+		/** @var ModuleThemeInterface $theme */
98
+		$theme = app(ModuleThemeInterface::class);
99
+		$css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css';
100
+
101
+		if (file_exists($css_file)) {
102
+			return $this->assetUrl('css/' . $theme->name() . '.min.css');
103
+		} else {
104
+			return $this->assetUrl('css/default.min.css');
105
+		}
106
+	}
107 107
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Data/MissingAncestor.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -21,79 +21,79 @@
 block discarded – undo
21 21
  */
22 22
 class MissingAncestor
23 23
 {
24
-    /**
25
-     * @var Individual $individual
26
-     */
27
-    private $individual;
24
+	/**
25
+	 * @var Individual $individual
26
+	 */
27
+	private $individual;
28 28
 
29
-    /**
30
-     * @var int $sosa
31
-     */
32
-    private $sosa;
29
+	/**
30
+	 * @var int $sosa
31
+	 */
32
+	private $sosa;
33 33
 
34
-    /**
35
-     * @var bool $missing_father
36
-     */
37
-    private $missing_father;
34
+	/**
35
+	 * @var bool $missing_father
36
+	 */
37
+	private $missing_father;
38 38
 
39
-    /**
40
-     * @var bool $missing_mother
41
-     */
42
-    private $missing_mother;
39
+	/**
40
+	 * @var bool $missing_mother
41
+	 */
42
+	private $missing_mother;
43 43
 
44
-    /**
45
-     * Constructor for MissingAncestor data class
46
-     *
47
-     * @param Individual $ancestor
48
-     * @param int $sosa
49
-     * @param bool $missing_father
50
-     * @param bool $missing_mother
51
-     */
52
-    public function __construct(Individual $ancestor, int $sosa, bool $missing_father, bool $missing_mother)
53
-    {
54
-        $this->individual = $ancestor;
55
-        $this->sosa = $sosa;
56
-        $this->missing_father = $missing_father;
57
-        $this->missing_mother = $missing_mother;
58
-    }
44
+	/**
45
+	 * Constructor for MissingAncestor data class
46
+	 *
47
+	 * @param Individual $ancestor
48
+	 * @param int $sosa
49
+	 * @param bool $missing_father
50
+	 * @param bool $missing_mother
51
+	 */
52
+	public function __construct(Individual $ancestor, int $sosa, bool $missing_father, bool $missing_mother)
53
+	{
54
+		$this->individual = $ancestor;
55
+		$this->sosa = $sosa;
56
+		$this->missing_father = $missing_father;
57
+		$this->missing_mother = $missing_mother;
58
+	}
59 59
 
60
-    /**
61
-     * Reference individual of the row
62
-     *
63
-     * @return Individual
64
-     */
65
-    public function individual(): Individual
66
-    {
67
-        return $this->individual;
68
-    }
60
+	/**
61
+	 * Reference individual of the row
62
+	 *
63
+	 * @return Individual
64
+	 */
65
+	public function individual(): Individual
66
+	{
67
+		return $this->individual;
68
+	}
69 69
 
70
-    /**
71
-     * Minimum sosa of the reference individual
72
-     *
73
-     * @return int
74
-     */
75
-    public function sosa(): int
76
-    {
77
-        return $this->sosa;
78
-    }
70
+	/**
71
+	 * Minimum sosa of the reference individual
72
+	 *
73
+	 * @return int
74
+	 */
75
+	public function sosa(): int
76
+	{
77
+		return $this->sosa;
78
+	}
79 79
 
80
-    /**
81
-     * Indicate whether the reference individual does not have a father
82
-     *
83
-     * @return bool
84
-     */
85
-    public function isFatherMissing(): bool
86
-    {
87
-        return $this->missing_father;
88
-    }
80
+	/**
81
+	 * Indicate whether the reference individual does not have a father
82
+	 *
83
+	 * @return bool
84
+	 */
85
+	public function isFatherMissing(): bool
86
+	{
87
+		return $this->missing_father;
88
+	}
89 89
 
90
-    /**
91
-     * Indicate whether the reference individual does not have a mother
92
-     *
93
-     * @return bool
94
-     */
95
-    public function isMotherMissing(): bool
96
-    {
97
-        return $this->missing_mother;
98
-    }
90
+	/**
91
+	 * Indicate whether the reference individual does not have a mother
92
+	 *
93
+	 * @return bool
94
+	 */
95
+	public function isMotherMissing(): bool
96
+	{
97
+		return $this->missing_mother;
98
+	}
99 99
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaStatistics.php 2 patches
Spacing   +14 added lines, -17 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         /** @var SosaStatisticsService $sosa_stats_service */
72 72
         $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
73 73
 
74
-        return $this->viewResponse($this->module->name() . '::statistics-page', [
74
+        return $this->viewResponse($this->module->name().'::statistics-page', [
75 75
             'module_name'       =>  $this->module->name(),
76 76
             'title'             =>  I18N::translate('Sosa Statistics'),
77 77
             'tree'              =>  $tree,
@@ -126,37 +126,34 @@  discard block
 block discarded – undo
126 126
 
127 127
         foreach ($stats_by_gen as $gen => $stats_gen) {
128 128
             $gen_diff = $gen > 1 ?
129
-                (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
130
-                1;
129
+                (int)$stats_gen['diffSosaTotalCount'] - (int)$stats_by_gen[$gen - 1]['diffSosaTotalCount'] : 1;
131 130
             $generation_stats[$gen] = array(
132
-                'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
133
-                'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
131
+                'gen_min_birth' => $stats_gen['firstBirth'] ?? (int)$stats_gen['firstEstimatedBirth'],
132
+                'gen_max_birth' => $stats_gen['lastBirth'] ?? (int)$stats_gen['lastEstimatedBirth'],
134 133
                 'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(),
135
-                'known' => (int) $stats_gen['sosaCount'],
134
+                'known' => (int)$stats_gen['sosaCount'],
136 135
                 'perc_known' => $this->safeDivision(
137
-                    BigInteger::of((int) $stats_gen['sosaCount']),
136
+                    BigInteger::of((int)$stats_gen['sosaCount']),
138 137
                     BigInteger::of(2)->power($gen - 1)
139 138
                 ),
140 139
                 'missing' => $gen > 1 ?
141
-                    2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
142
-                    0,
140
+                    2 * (int)$stats_by_gen[$gen - 1]['sosaCount'] - (int)$stats_gen['sosaCount'] : 0,
143 141
                 'perc_missing' => $gen > 1 ?
144 142
                     1 - $this->safeDivision(
145
-                        BigInteger::of((int) $stats_gen['sosaCount']),
146
-                        BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount'])
147
-                    ) :
148
-                    0,
149
-                'total_known' => (int) $stats_gen['sosaTotalCount'],
143
+                        BigInteger::of((int)$stats_gen['sosaCount']),
144
+                        BigInteger::of(2 * (int)$stats_by_gen[$gen - 1]['sosaCount'])
145
+                    ) : 0,
146
+                'total_known' => (int)$stats_gen['sosaTotalCount'],
150 147
                 'perc_total_known' => $this->safeDivision(
151
-                    BigInteger::of((int) $stats_gen['sosaTotalCount']),
148
+                    BigInteger::of((int)$stats_gen['sosaTotalCount']),
152 149
                     BigInteger::of(2)->power($gen)->minus(1)
153 150
                 ),
154 151
                 'different' => $gen_diff,
155 152
                 'perc_different' => $this->safeDivision(
156 153
                     BigInteger::of($gen_diff),
157
-                    BigInteger::of((int) $stats_gen['sosaCount'])
154
+                    BigInteger::of((int)$stats_gen['sosaCount'])
158 155
                 ),
159
-                'total_different' => (int) $stats_gen['diffSosaTotalCount']
156
+                'total_different' => (int)$stats_gen['diffSosaTotalCount']
160 157
             );
161 158
         }
162 159
 
Please login to merge, or discard this patch.
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -38,142 +38,142 @@
 block discarded – undo
38 38
  */
39 39
 class SosaStatistics implements RequestHandlerInterface
40 40
 {
41
-    use ViewResponseTrait;
42
-
43
-    private ?SosaModule $module;
44
-    private RelationshipService $relationship_service;
45
-
46
-    /**
47
-     * Constructor for AncestorsList Request Handler
48
-     *
49
-     * @param ModuleService $module_service
50
-     */
51
-    public function __construct(ModuleService $module_service, RelationshipService $relationship_service)
52
-    {
53
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
54
-        $this->relationship_service = $relationship_service;
55
-    }
56
-
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
60
-     */
61
-    public function handle(ServerRequestInterface $request): ResponseInterface
62
-    {
63
-        if ($this->module === null) {
64
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
65
-        }
66
-
67
-        $tree = Validator::attributes($request)->tree();
68
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
69
-
70
-        /** @var SosaStatisticsService $sosa_stats_service */
71
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
72
-
73
-        return $this->viewResponse($this->module->name() . '::statistics-page', [
74
-            'module_name'       =>  $this->module->name(),
75
-            'title'             =>  I18N::translate('Sosa Statistics'),
76
-            'tree'              =>  $tree,
77
-            'theme'             =>  app(ModuleThemeInterface::class),
78
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
79
-            'general_stats'     =>  $this->statisticsGeneral($sosa_stats_service),
80
-            'generation_stats'  =>  $this->statisticsByGenerations($sosa_stats_service),
81
-            'generation_depth'  =>  $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(),
82
-            'multiple_sosas'    =>  $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'),
83
-            'sosa_dispersion_g2' =>  $sosa_stats_service->ancestorsDispersionForGeneration(2),
84
-            'sosa_dispersion_g3' =>  $sosa_stats_service->ancestorsDispersionForGeneration(3),
85
-            'gen_depth_g3'      =>  $sosa_stats_service->generationDepthStatsAtGeneration(3),
86
-            'relationship_service'  =>  $this->relationship_service,
87
-        ]);
88
-    }
89
-
90
-    /**
91
-     * Retrieve and compute the global statistics of ancestors for the tree.
92
-     * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse...
93
-     *
94
-     * @param SosaStatisticsService $sosa_stats_service
95
-     * @return array<string, int|float>
96
-     */
97
-    private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array
98
-    {
99
-        $ancestors_count = $sosa_stats_service->totalAncestors();
100
-        $ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors();
101
-        $individual_count = $sosa_stats_service->totalIndividuals();
102
-
103
-        return [
104
-            'sosa_count'    =>  $ancestors_count,
105
-            'distinct_count'    =>  $ancestors_distinct_count,
106
-            'sosa_rate' =>  $this->safeDivision(
107
-                BigInteger::of($ancestors_distinct_count),
108
-                BigInteger::of($individual_count)
109
-            ),
110
-            'mean_gen_time'         =>  $sosa_stats_service->meanGenerationTime()
111
-        ];
112
-    }
113
-
114
-    /**
115
-     * Retrieve and compute the statistics of ancestors by generations.
116
-     * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics...
117
-     *
118
-     * @param SosaStatisticsService $sosa_stats_service
119
-     * @return array<int, array<string, int|float>>
120
-     */
121
-    private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array
122
-    {
123
-        $stats_by_gen = $sosa_stats_service->statisticsByGenerations();
124
-
125
-        $generation_stats = array();
126
-
127
-        foreach ($stats_by_gen as $gen => $stats_gen) {
128
-            $gen_diff = $gen > 1 ?
129
-                (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
130
-                1;
131
-            $generation_stats[$gen] = array(
132
-                'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
133
-                'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
134
-                'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(),
135
-                'known' => (int) $stats_gen['sosaCount'],
136
-                'perc_known' => $this->safeDivision(
137
-                    BigInteger::of((int) $stats_gen['sosaCount']),
138
-                    BigInteger::of(2)->power($gen - 1)
139
-                ),
140
-                'missing' => $gen > 1 ?
141
-                    2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
142
-                    0,
143
-                'perc_missing' => $gen > 1 ?
144
-                    1 - $this->safeDivision(
145
-                        BigInteger::of((int) $stats_gen['sosaCount']),
146
-                        BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount'])
147
-                    ) :
148
-                    0,
149
-                'total_known' => (int) $stats_gen['sosaTotalCount'],
150
-                'perc_total_known' => $this->safeDivision(
151
-                    BigInteger::of((int) $stats_gen['sosaTotalCount']),
152
-                    BigInteger::of(2)->power($gen)->minus(1)
153
-                ),
154
-                'different' => $gen_diff,
155
-                'perc_different' => $this->safeDivision(
156
-                    BigInteger::of($gen_diff),
157
-                    BigInteger::of((int) $stats_gen['sosaCount'])
158
-                ),
159
-                'total_different' => (int) $stats_gen['diffSosaTotalCount']
160
-            );
161
-        }
162
-
163
-        return $generation_stats;
164
-    }
165
-
166
-    /**
167
-     * Return the result of a division, and a default value if denominator is 0
168
-     *
169
-     * @param BigInteger $p Numerator
170
-     * @param BigInteger $q Denominator
171
-     * @param int $scale Rounding scale
172
-     * @param float $default Value if denominator is 0
173
-     * @return float
174
-     */
175
-    private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float
176
-    {
177
-        return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat();
178
-    }
41
+	use ViewResponseTrait;
42
+
43
+	private ?SosaModule $module;
44
+	private RelationshipService $relationship_service;
45
+
46
+	/**
47
+	 * Constructor for AncestorsList Request Handler
48
+	 *
49
+	 * @param ModuleService $module_service
50
+	 */
51
+	public function __construct(ModuleService $module_service, RelationshipService $relationship_service)
52
+	{
53
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
54
+		$this->relationship_service = $relationship_service;
55
+	}
56
+
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
60
+	 */
61
+	public function handle(ServerRequestInterface $request): ResponseInterface
62
+	{
63
+		if ($this->module === null) {
64
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
65
+		}
66
+
67
+		$tree = Validator::attributes($request)->tree();
68
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
69
+
70
+		/** @var SosaStatisticsService $sosa_stats_service */
71
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
72
+
73
+		return $this->viewResponse($this->module->name() . '::statistics-page', [
74
+			'module_name'       =>  $this->module->name(),
75
+			'title'             =>  I18N::translate('Sosa Statistics'),
76
+			'tree'              =>  $tree,
77
+			'theme'             =>  app(ModuleThemeInterface::class),
78
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
79
+			'general_stats'     =>  $this->statisticsGeneral($sosa_stats_service),
80
+			'generation_stats'  =>  $this->statisticsByGenerations($sosa_stats_service),
81
+			'generation_depth'  =>  $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(),
82
+			'multiple_sosas'    =>  $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'),
83
+			'sosa_dispersion_g2' =>  $sosa_stats_service->ancestorsDispersionForGeneration(2),
84
+			'sosa_dispersion_g3' =>  $sosa_stats_service->ancestorsDispersionForGeneration(3),
85
+			'gen_depth_g3'      =>  $sosa_stats_service->generationDepthStatsAtGeneration(3),
86
+			'relationship_service'  =>  $this->relationship_service,
87
+		]);
88
+	}
89
+
90
+	/**
91
+	 * Retrieve and compute the global statistics of ancestors for the tree.
92
+	 * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse...
93
+	 *
94
+	 * @param SosaStatisticsService $sosa_stats_service
95
+	 * @return array<string, int|float>
96
+	 */
97
+	private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array
98
+	{
99
+		$ancestors_count = $sosa_stats_service->totalAncestors();
100
+		$ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors();
101
+		$individual_count = $sosa_stats_service->totalIndividuals();
102
+
103
+		return [
104
+			'sosa_count'    =>  $ancestors_count,
105
+			'distinct_count'    =>  $ancestors_distinct_count,
106
+			'sosa_rate' =>  $this->safeDivision(
107
+				BigInteger::of($ancestors_distinct_count),
108
+				BigInteger::of($individual_count)
109
+			),
110
+			'mean_gen_time'         =>  $sosa_stats_service->meanGenerationTime()
111
+		];
112
+	}
113
+
114
+	/**
115
+	 * Retrieve and compute the statistics of ancestors by generations.
116
+	 * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics...
117
+	 *
118
+	 * @param SosaStatisticsService $sosa_stats_service
119
+	 * @return array<int, array<string, int|float>>
120
+	 */
121
+	private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array
122
+	{
123
+		$stats_by_gen = $sosa_stats_service->statisticsByGenerations();
124
+
125
+		$generation_stats = array();
126
+
127
+		foreach ($stats_by_gen as $gen => $stats_gen) {
128
+			$gen_diff = $gen > 1 ?
129
+				(int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
130
+				1;
131
+			$generation_stats[$gen] = array(
132
+				'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
133
+				'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
134
+				'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(),
135
+				'known' => (int) $stats_gen['sosaCount'],
136
+				'perc_known' => $this->safeDivision(
137
+					BigInteger::of((int) $stats_gen['sosaCount']),
138
+					BigInteger::of(2)->power($gen - 1)
139
+				),
140
+				'missing' => $gen > 1 ?
141
+					2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
142
+					0,
143
+				'perc_missing' => $gen > 1 ?
144
+					1 - $this->safeDivision(
145
+						BigInteger::of((int) $stats_gen['sosaCount']),
146
+						BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount'])
147
+					) :
148
+					0,
149
+				'total_known' => (int) $stats_gen['sosaTotalCount'],
150
+				'perc_total_known' => $this->safeDivision(
151
+					BigInteger::of((int) $stats_gen['sosaTotalCount']),
152
+					BigInteger::of(2)->power($gen)->minus(1)
153
+				),
154
+				'different' => $gen_diff,
155
+				'perc_different' => $this->safeDivision(
156
+					BigInteger::of($gen_diff),
157
+					BigInteger::of((int) $stats_gen['sosaCount'])
158
+				),
159
+				'total_different' => (int) $stats_gen['diffSosaTotalCount']
160
+			);
161
+		}
162
+
163
+		return $generation_stats;
164
+	}
165
+
166
+	/**
167
+	 * Return the result of a division, and a default value if denominator is 0
168
+	 *
169
+	 * @param BigInteger $p Numerator
170
+	 * @param BigInteger $q Denominator
171
+	 * @param int $scale Rounding scale
172
+	 * @param float $default Value if denominator is 0
173
+	 * @return float
174
+	 */
175
+	private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float
176
+	{
177
+		return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat();
178
+	}
179 179
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/PedigreeCollapseData.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,10 +67,10 @@
 block discarded – undo
67 67
         $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
68 68
         $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData();
69 69
 
70
-        $response = [ 'cells' => [] ];
70
+        $response = ['cells' => []];
71 71
         $last_pedi_collapse = 0;
72 72
         foreach ($pedi_collapse_data as $gen => $rec) {
73
-            $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [
73
+            $response['cells'][$gen] = view($this->module->name().'::components/pedigree-collapse-cell', [
74 74
                 'pedi_collapse_roots'   =>  $rec['pedi_collapse_roots'],
75 75
                 'pedi_collapse_xgen'    =>  $rec['pedi_collapse_xgen']
76 76
             ]);
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -33,49 +33,49 @@
 block discarded – undo
33 33
  */
34 34
 class PedigreeCollapseData implements RequestHandlerInterface
35 35
 {
36
-    /**
37
-     * @var SosaModule|null $module
38
-     */
39
-    private $module;
36
+	/**
37
+	 * @var SosaModule|null $module
38
+	 */
39
+	private $module;
40 40
 
41
-    /**
42
-     * Constructor for PedigreeCollapseData 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 PedigreeCollapseData 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 = Validator::attributes($request)->tree();
62
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
61
+		$tree = Validator::attributes($request)->tree();
62
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
63 63
 
64
-        /** @var SosaStatisticsService $sosa_stats_service */
65
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
66
-        $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData();
64
+		/** @var SosaStatisticsService $sosa_stats_service */
65
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
66
+		$pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData();
67 67
 
68
-        $response = [ 'cells' => [] ];
69
-        $last_pedi_collapse = 0;
70
-        foreach ($pedi_collapse_data as $gen => $rec) {
71
-            $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [
72
-                'pedi_collapse_roots'   =>  $rec['pedi_collapse_roots'],
73
-                'pedi_collapse_xgen'    =>  $rec['pedi_collapse_xgen']
74
-            ]);
75
-            $last_pedi_collapse = $rec['pedi_collapse_roots'];
76
-        }
77
-        $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2);
68
+		$response = [ 'cells' => [] ];
69
+		$last_pedi_collapse = 0;
70
+		foreach ($pedi_collapse_data as $gen => $rec) {
71
+			$response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [
72
+				'pedi_collapse_roots'   =>  $rec['pedi_collapse_roots'],
73
+				'pedi_collapse_xgen'    =>  $rec['pedi_collapse_xgen']
74
+			]);
75
+			$last_pedi_collapse = $rec['pedi_collapse_roots'];
76
+		}
77
+		$response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2);
78 78
 
79
-        return Registry::responseFactory()->response($response);
80
-    }
79
+		return Registry::responseFactory()->response($response);
80
+	}
81 81
 }
Please login to merge, or discard this patch.