Passed
Push — feature/code-analysis ( e321b8...2d8a51 )
by Jonathan
13:14 queued 09:07
created
app/Module/PatronymicLineage/Http/RequestHandlers/SurnamesList.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -30,70 +30,70 @@
 block discarded – undo
30 30
  */
31 31
 class SurnamesList implements RequestHandlerInterface
32 32
 {
33
-    use ViewResponseTrait;
33
+	use ViewResponseTrait;
34 34
 
35
-    private ?PatronymicLineageModule $module;
35
+	private ?PatronymicLineageModule $module;
36 36
 
37
-    /**
38
-     * Constructor for SurnamesList Request Handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     */
42
-    public function __construct(ModuleService $module_service)
43
-    {
44
-        $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first();
45
-    }
37
+	/**
38
+	 * Constructor for SurnamesList Request Handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 */
42
+	public function __construct(ModuleService $module_service)
43
+	{
44
+		$this->module = $module_service->findByInterface(PatronymicLineageModule::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
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
55
-        }
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
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
55
+		}
56 56
 
57
-        $tree = Validator::attributes($request)->tree();
58
-        $initial = Validator::attributes($request)->string('alpha', '');
57
+		$tree = Validator::attributes($request)->tree();
58
+		$initial = Validator::attributes($request)->string('alpha', '');
59 59
 
60
-        $surname_data     = $this->module->surnameData($tree, false, false);
61
-        $all_surnames     = $this->module->allSurnames($surname_data);
62
-        $initials_list = array_filter(
63
-            $this->module->surnameInitials($surname_data),
64
-            static fn (string $x): bool => $x !== '@' && $x !== ',',
65
-            ARRAY_FILTER_USE_KEY
66
-        );
60
+		$surname_data     = $this->module->surnameData($tree, false, false);
61
+		$all_surnames     = $this->module->allSurnames($surname_data);
62
+		$initials_list = array_filter(
63
+			$this->module->surnameInitials($surname_data),
64
+			static fn (string $x): bool => $x !== '@' && $x !== ',',
65
+			ARRAY_FILTER_USE_KEY
66
+		);
67 67
 
68
-        $show_all = Validator::queryParams($request)->string('show_all', 'no') === 'yes';
68
+		$show_all = Validator::queryParams($request)->string('show_all', 'no') === 'yes';
69 69
 
70
-        if ($show_all) {
71
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All');
72
-            $surnames = array_filter(
73
-                $all_surnames,
74
-                static fn (string $x): bool => $x !== '' && $x !== Individual::NOMEN_NESCIO,
75
-                ARRAY_FILTER_USE_KEY
76
-            );
77
-        } elseif (array_key_exists($initial, $initials_list)) {
78
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial;
79
-            $surnames = array_filter(
80
-                $all_surnames,
81
-                static fn (string $x): bool => I18N::language()->initialLetter($x) === $initial,
82
-                ARRAY_FILTER_USE_KEY
83
-            );
84
-        } else {
85
-            $title =  I18N::translate('Patronymic Lineages');
86
-            $surnames = [];
87
-        }
70
+		if ($show_all) {
71
+			$title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All');
72
+			$surnames = array_filter(
73
+				$all_surnames,
74
+				static fn (string $x): bool => $x !== '' && $x !== Individual::NOMEN_NESCIO,
75
+				ARRAY_FILTER_USE_KEY
76
+			);
77
+		} elseif (array_key_exists($initial, $initials_list)) {
78
+			$title = I18N::translate('Patronymic Lineages') . ' — ' . $initial;
79
+			$surnames = array_filter(
80
+				$all_surnames,
81
+				static fn (string $x): bool => I18N::language()->initialLetter($x) === $initial,
82
+				ARRAY_FILTER_USE_KEY
83
+			);
84
+		} else {
85
+			$title =  I18N::translate('Patronymic Lineages');
86
+			$surnames = [];
87
+		}
88 88
 
89
-        return $this->viewResponse($this->module->name() . '::surnames-page', [
90
-            'title'         =>  $title,
91
-            'module'        =>  $this->module,
92
-            'tree'          =>  $tree,
93
-            'initials_list' =>  $initials_list,
94
-            'initial'       =>  $initial,
95
-            'show_all'      =>  $show_all ? 'yes' : 'no',
96
-            'surnames'      =>  $surnames
97
-        ]);
98
-    }
89
+		return $this->viewResponse($this->module->name() . '::surnames-page', [
90
+			'title'         =>  $title,
91
+			'module'        =>  $this->module,
92
+			'tree'          =>  $tree,
93
+			'initials_list' =>  $initials_list,
94
+			'initial'       =>  $initial,
95
+			'show_all'      =>  $show_all ? 'yes' : 'no',
96
+			'surnames'      =>  $surnames
97
+		]);
98
+	}
99 99
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -68,25 +68,25 @@
 block discarded – undo
68 68
         $show_all = Validator::queryParams($request)->string('show_all', 'no') === 'yes';
69 69
 
70 70
         if ($show_all) {
71
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All');
71
+            $title = I18N::translate('Patronymic Lineages').' — '.I18N::translate('All');
72 72
             $surnames = array_filter(
73 73
                 $all_surnames,
74 74
                 static fn (string $x): bool => $x !== '' && $x !== Individual::NOMEN_NESCIO,
75 75
                 ARRAY_FILTER_USE_KEY
76 76
             );
77 77
         } elseif (array_key_exists($initial, $initials_list)) {
78
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial;
78
+            $title = I18N::translate('Patronymic Lineages').' — '.$initial;
79 79
             $surnames = array_filter(
80 80
                 $all_surnames,
81 81
                 static fn (string $x): bool => I18N::language()->initialLetter($x) === $initial,
82 82
                 ARRAY_FILTER_USE_KEY
83 83
             );
84 84
         } else {
85
-            $title =  I18N::translate('Patronymic Lineages');
85
+            $title = I18N::translate('Patronymic Lineages');
86 86
             $surnames = [];
87 87
         }
88 88
 
89
-        return $this->viewResponse($this->module->name() . '::surnames-page', [
89
+        return $this->viewResponse($this->module->name().'::surnames-page', [
90 90
             'title'         =>  $title,
91 91
             'module'        =>  $this->module,
92 92
             'tree'          =>  $tree,
Please login to merge, or discard this patch.
app/Module/PatronymicLineage/Http/RequestHandlers/LineagesPage.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -32,75 +32,75 @@
 block discarded – undo
32 32
  */
33 33
 class LineagesPage implements RequestHandlerInterface
34 34
 {
35
-    use ViewResponseTrait;
36
-
37
-    /**
38
-     * @var PatronymicLineageModule|null $module
39
-     */
40
-    private $module;
41
-
42
-    /**
43
-     * Constructor for LineagesPage Request handler
44
-     *
45
-     * @param ModuleService $module_service
46
-     */
47
-    public function __construct(ModuleService $module_service)
48
-    {
49
-        $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first();
50
-    }
51
-
52
-    /**
53
-     * {@inheritDoc}
54
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
55
-     */
56
-    public function handle(ServerRequestInterface $request): ResponseInterface
57
-    {
58
-        if ($this->module === null) {
59
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
60
-        }
61
-
62
-        $tree = Validator::attributes($request)->tree();
63
-        $surname_attr = Validator::attributes($request)->string('surname', '');
64
-        $surname = I18N::strtoupper(I18N::language()->normalize($surname_attr));
65
-
66
-        if ($surname_attr !== $surname) {
67
-            return Registry::responseFactory()
68
-                ->redirect(LineagesPage::class, ['tree' => $tree->name(), 'surname' => $surname]);
69
-        }
70
-
71
-        if ($surname === '' ||  $surname === Individual::NOMEN_NESCIO) {
72
-            return Registry::responseFactory()->redirect(SurnamesList::class, ['tree' => $tree->name()]);
73
-        }
74
-
75
-        $surn_initial = I18N::language()->initialLetter($surname);
76
-
77
-        $surname_data     = $this->module->surnameData($tree, false, false);
78
-        $all_surnames     = $this->module->allSurnames($surname_data);
79
-        $initials_list = array_filter(
80
-            $this->module->surnameInitials($surname_data),
81
-            static fn (string $x): bool => $x !== '@' && $x !== ',',
82
-            ARRAY_FILTER_USE_KEY
83
-        );
84
-
85
-        $surname_variants = array_keys($all_surnames[$surname] ?? [$surname => $surname]);
86
-        uasort($surname_variants, I18N::comparator());
87
-        $surname_legend = implode('/', $surname_variants);
88
-
89
-        $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname_legend;
90
-
91
-        $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages();
92
-
93
-        return $this->viewResponse($this->module->name() . '::lineages-page', [
94
-            'title'         =>  $title,
95
-            'module'        =>  $this->module,
96
-            'tree'          =>  $tree,
97
-            'initials_list' =>  $initials_list,
98
-            'initial'       =>  $surn_initial,
99
-            'show_all'      =>  'no',
100
-            'surname'       =>  $surname,
101
-            'surname_legend' =>  $surname_legend,
102
-            'lineages'      =>  $lineages,
103
-            'nb_lineages'   =>  $lineages !== null ? $lineages->count() : 0
104
-        ]);
105
-    }
35
+	use ViewResponseTrait;
36
+
37
+	/**
38
+	 * @var PatronymicLineageModule|null $module
39
+	 */
40
+	private $module;
41
+
42
+	/**
43
+	 * Constructor for LineagesPage Request handler
44
+	 *
45
+	 * @param ModuleService $module_service
46
+	 */
47
+	public function __construct(ModuleService $module_service)
48
+	{
49
+		$this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first();
50
+	}
51
+
52
+	/**
53
+	 * {@inheritDoc}
54
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
55
+	 */
56
+	public function handle(ServerRequestInterface $request): ResponseInterface
57
+	{
58
+		if ($this->module === null) {
59
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
60
+		}
61
+
62
+		$tree = Validator::attributes($request)->tree();
63
+		$surname_attr = Validator::attributes($request)->string('surname', '');
64
+		$surname = I18N::strtoupper(I18N::language()->normalize($surname_attr));
65
+
66
+		if ($surname_attr !== $surname) {
67
+			return Registry::responseFactory()
68
+				->redirect(LineagesPage::class, ['tree' => $tree->name(), 'surname' => $surname]);
69
+		}
70
+
71
+		if ($surname === '' ||  $surname === Individual::NOMEN_NESCIO) {
72
+			return Registry::responseFactory()->redirect(SurnamesList::class, ['tree' => $tree->name()]);
73
+		}
74
+
75
+		$surn_initial = I18N::language()->initialLetter($surname);
76
+
77
+		$surname_data     = $this->module->surnameData($tree, false, false);
78
+		$all_surnames     = $this->module->allSurnames($surname_data);
79
+		$initials_list = array_filter(
80
+			$this->module->surnameInitials($surname_data),
81
+			static fn (string $x): bool => $x !== '@' && $x !== ',',
82
+			ARRAY_FILTER_USE_KEY
83
+		);
84
+
85
+		$surname_variants = array_keys($all_surnames[$surname] ?? [$surname => $surname]);
86
+		uasort($surname_variants, I18N::comparator());
87
+		$surname_legend = implode('/', $surname_variants);
88
+
89
+		$title = I18N::translate('Patronymic Lineages') . ' — ' . $surname_legend;
90
+
91
+		$lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages();
92
+
93
+		return $this->viewResponse($this->module->name() . '::lineages-page', [
94
+			'title'         =>  $title,
95
+			'module'        =>  $this->module,
96
+			'tree'          =>  $tree,
97
+			'initials_list' =>  $initials_list,
98
+			'initial'       =>  $surn_initial,
99
+			'show_all'      =>  'no',
100
+			'surname'       =>  $surname,
101
+			'surname_legend' =>  $surname_legend,
102
+			'lineages'      =>  $lineages,
103
+			'nb_lineages'   =>  $lineages !== null ? $lineages->count() : 0
104
+		]);
105
+	}
106 106
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
                 ->redirect(LineagesPage::class, ['tree' => $tree->name(), 'surname' => $surname]);
69 69
         }
70 70
 
71
-        if ($surname === '' ||  $surname === Individual::NOMEN_NESCIO) {
71
+        if ($surname === '' || $surname === Individual::NOMEN_NESCIO) {
72 72
             return Registry::responseFactory()->redirect(SurnamesList::class, ['tree' => $tree->name()]);
73 73
         }
74 74
 
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
         uasort($surname_variants, I18N::comparator());
87 87
         $surname_legend = implode('/', $surname_variants);
88 88
 
89
-        $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname_legend;
89
+        $title = I18N::translate('Patronymic Lineages').' — '.$surname_legend;
90 90
 
91 91
         $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages();
92 92
 
93
-        return $this->viewResponse($this->module->name() . '::lineages-page', [
93
+        return $this->viewResponse($this->module->name().'::lineages-page', [
94 94
             'title'         =>  $title,
95 95
             'module'        =>  $this->module,
96 96
             'tree'          =>  $tree,
Please login to merge, or discard this patch.
app/Module/PatronymicLineage/PatronymicLineageModule.php 2 patches
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -39,177 +39,177 @@
 block discarded – undo
39 39
  * Display lineages of people with the same surname.
40 40
  */
41 41
 class PatronymicLineageModule extends IndividualListModule implements
42
-    ModuleMyArtJaubInterface,
43
-    ModuleListInterface,
44
-    ModuleGlobalInterface
42
+	ModuleMyArtJaubInterface,
43
+	ModuleListInterface,
44
+	ModuleGlobalInterface
45 45
 {
46
-    use ModuleMyArtJaubTrait;
47
-    use ModuleListTrait;
48
-    use ModuleGlobalTrait;
49
-
50
-     /**
51
-     * {@inheritDoc}
52
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
53
-     */
54
-    public function title(): string
55
-    {
56
-        return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages');
57
-    }
58
-
59
-    /**
60
-     * {@inheritDoc}
61
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
62
-     */
63
-    public function description(): string
64
-    {
65
-        //phpcs:ignore Generic.Files.LineLength.TooLong
66
-        return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.');
67
-    }
68
-
69
-    /**
70
-     * {@inheritDoc}
71
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
72
-     */
73
-    public function loadRoutes(Map $router): void
74
-    {
75
-        $router->attach('', '', static function (Map $router): void {
76
-
77
-            $router->attach('', '/module-maj/lineages', static function (Map $router): void {
78
-
79
-                $router->attach('', '/Page', static function (Map $router): void {
80
-
81
-                    $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class);
82
-                    $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class);
83
-                });
84
-            });
85
-        });
86
-    }
87
-
88
-    /**
89
-     * {@inheritDoc}
90
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
91
-     */
92
-    public function customModuleVersion(): string
93
-    {
94
-        return '2.1.18-v.1';
95
-    }
96
-
97
-    /**
98
-     * {@inheritDoc}
99
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
100
-     *
101
-     * @param array<bool|int|string|array<mixed>|null> $parameters
102
-     */
103
-    public function listUrl(Tree $tree, array $parameters = []): string
104
-    {
105
-        $surname = $parameters['surname'] ?? null;
106
-        $surname = is_string($surname) ? $surname : null;
107
-
108
-        $request = app(ServerRequestInterface::class);
109
-
110
-        // If a surname is already in the query attribute, use it
111
-        if ($surname === null) {
112
-            $surname_attr =  Validator::attributes($request)->string('surname', '');
113
-            $surname_param =  Validator::queryParams($request)->string('surname', '');
114
-            $surname_body =  Validator::parsedBody($request)->string('surname', '');
115
-            $surname = $surname_attr !== '' ? $surname_attr : (
116
-                $surname_param !== '' ? $surname_param : (
117
-                $surname_body !== '' ? $surname_body : null
118
-            ));
119
-        }
120
-
121
-        // If nothing found, and on an individual page, use its name
122
-        $xref = Validator::attributes($request)->isXref()->string('xref', '');
123
-        if ($xref !== '') {
124
-            $individual = Registry::individualFactory()->make($xref, $tree);
125
-            if ($individual instanceof Individual && $individual->canShow()) {
126
-                $primary_name = $individual->getPrimaryName();
127
-                $surname ??= $individual->getAllNames()[$primary_name]['surn'] ?? null;
128
-            }
129
-        }
130
-
131
-        if (Str::length($surname ?? '') > 0 && $surname !== Individual::NOMEN_NESCIO) {
132
-            return route(LineagesPage::class, [
133
-                'tree'      =>  $tree->name(),
134
-                'surname'   =>  $surname
135
-            ] + $parameters);
136
-        }
137
-        return route(SurnamesList::class, ['tree'  =>  $tree->name() ] + $parameters);
138
-    }
139
-
140
-    /**
141
-     * {@inheritDoc}
142
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
143
-     */
144
-    public function listMenuClass(): string
145
-    {
146
-        return 'menu-maj-patrolineage';
147
-    }
148
-
149
-    /**
150
-     * {@inheritDoc}
151
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
152
-     */
153
-    public function headContent(): string
154
-    {
155
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
156
-    }
157
-
158
-    /**
159
-     * {@inheritDoc}
160
-     * @see \Fisharebest\Webtrees\Module\IndividualListModule::individuals()
161
-     *
162
-     * Implemented to set the visibility to public.
163
-     * This should probably be in a service, but this hack allows for reuse of mainstream code.
164
-     */
165
-    public function individuals(
166
-        Tree $tree,
167
-        array $surns_to_show,
168
-        string $galpha,
169
-        bool $marnm,
170
-        bool $fams
171
-    ): Collection {
172
-        return parent::individuals($tree, $surns_to_show, $galpha, $marnm, $fams);
173
-    }
174
-
175
-    /**
176
-     * {@inheritDoc}
177
-     * @see \Fisharebest\Webtrees\Module\IndividualListModule::surnameData()
178
-     *
179
-     * Implemented to set the visibility to public.
180
-     * This should probably be in a service, but this hack allows for reuse of mainstream code.
181
-     *
182
-     * @return array<object{n_surn:string,n_surname:string,total:int}>
183
-     */
184
-    public function surnameData(Tree $tree, bool $marnm, bool $fams): array
185
-    {
186
-        $reflectionMethod = new ReflectionMethod(IndividualListModule::class, 'surnameData');
187
-        $reflectionMethod->setAccessible(true);
188
-
189
-        return $reflectionMethod->invoke($this, $tree, $marnm, $fams);
190
-    }
191
-
192
-    /**
193
-     * {@inheritDoc}
194
-     * @see \Fisharebest\Webtrees\Module\IndividualListModule::allSurnames()
195
-     *
196
-     * Implemented to set the visibility to public.
197
-     * This should probably be in a service, but this hack allows for reuse of mainstream code.
198
-     */
199
-    public function allSurnames(array $surname_data): array
200
-    {
201
-        return parent::allSurnames($surname_data);
202
-    }
203
-
204
-    /**
205
-     * {@inheritDoc}
206
-     * @see \Fisharebest\Webtrees\Module\IndividualListModule::surnameInitials()
207
-     *
208
-     * Implemented to set the visibility to public.
209
-     * This should probably be in a service, but this hack allows for reuse of mainstream code.
210
-     */
211
-    public function surnameInitials(array $surname_data): array
212
-    {
213
-        return parent::surnameInitials($surname_data);
214
-    }
46
+	use ModuleMyArtJaubTrait;
47
+	use ModuleListTrait;
48
+	use ModuleGlobalTrait;
49
+
50
+	 /**
51
+	  * {@inheritDoc}
52
+	  * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
53
+	  */
54
+	public function title(): string
55
+	{
56
+		return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages');
57
+	}
58
+
59
+	/**
60
+	 * {@inheritDoc}
61
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
62
+	 */
63
+	public function description(): string
64
+	{
65
+		//phpcs:ignore Generic.Files.LineLength.TooLong
66
+		return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.');
67
+	}
68
+
69
+	/**
70
+	 * {@inheritDoc}
71
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
72
+	 */
73
+	public function loadRoutes(Map $router): void
74
+	{
75
+		$router->attach('', '', static function (Map $router): void {
76
+
77
+			$router->attach('', '/module-maj/lineages', static function (Map $router): void {
78
+
79
+				$router->attach('', '/Page', static function (Map $router): void {
80
+
81
+					$router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class);
82
+					$router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class);
83
+				});
84
+			});
85
+		});
86
+	}
87
+
88
+	/**
89
+	 * {@inheritDoc}
90
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
91
+	 */
92
+	public function customModuleVersion(): string
93
+	{
94
+		return '2.1.18-v.1';
95
+	}
96
+
97
+	/**
98
+	 * {@inheritDoc}
99
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
100
+	 *
101
+	 * @param array<bool|int|string|array<mixed>|null> $parameters
102
+	 */
103
+	public function listUrl(Tree $tree, array $parameters = []): string
104
+	{
105
+		$surname = $parameters['surname'] ?? null;
106
+		$surname = is_string($surname) ? $surname : null;
107
+
108
+		$request = app(ServerRequestInterface::class);
109
+
110
+		// If a surname is already in the query attribute, use it
111
+		if ($surname === null) {
112
+			$surname_attr =  Validator::attributes($request)->string('surname', '');
113
+			$surname_param =  Validator::queryParams($request)->string('surname', '');
114
+			$surname_body =  Validator::parsedBody($request)->string('surname', '');
115
+			$surname = $surname_attr !== '' ? $surname_attr : (
116
+				$surname_param !== '' ? $surname_param : (
117
+				$surname_body !== '' ? $surname_body : null
118
+			));
119
+		}
120
+
121
+		// If nothing found, and on an individual page, use its name
122
+		$xref = Validator::attributes($request)->isXref()->string('xref', '');
123
+		if ($xref !== '') {
124
+			$individual = Registry::individualFactory()->make($xref, $tree);
125
+			if ($individual instanceof Individual && $individual->canShow()) {
126
+				$primary_name = $individual->getPrimaryName();
127
+				$surname ??= $individual->getAllNames()[$primary_name]['surn'] ?? null;
128
+			}
129
+		}
130
+
131
+		if (Str::length($surname ?? '') > 0 && $surname !== Individual::NOMEN_NESCIO) {
132
+			return route(LineagesPage::class, [
133
+				'tree'      =>  $tree->name(),
134
+				'surname'   =>  $surname
135
+			] + $parameters);
136
+		}
137
+		return route(SurnamesList::class, ['tree'  =>  $tree->name() ] + $parameters);
138
+	}
139
+
140
+	/**
141
+	 * {@inheritDoc}
142
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
143
+	 */
144
+	public function listMenuClass(): string
145
+	{
146
+		return 'menu-maj-patrolineage';
147
+	}
148
+
149
+	/**
150
+	 * {@inheritDoc}
151
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
152
+	 */
153
+	public function headContent(): string
154
+	{
155
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
156
+	}
157
+
158
+	/**
159
+	 * {@inheritDoc}
160
+	 * @see \Fisharebest\Webtrees\Module\IndividualListModule::individuals()
161
+	 *
162
+	 * Implemented to set the visibility to public.
163
+	 * This should probably be in a service, but this hack allows for reuse of mainstream code.
164
+	 */
165
+	public function individuals(
166
+		Tree $tree,
167
+		array $surns_to_show,
168
+		string $galpha,
169
+		bool $marnm,
170
+		bool $fams
171
+	): Collection {
172
+		return parent::individuals($tree, $surns_to_show, $galpha, $marnm, $fams);
173
+	}
174
+
175
+	/**
176
+	 * {@inheritDoc}
177
+	 * @see \Fisharebest\Webtrees\Module\IndividualListModule::surnameData()
178
+	 *
179
+	 * Implemented to set the visibility to public.
180
+	 * This should probably be in a service, but this hack allows for reuse of mainstream code.
181
+	 *
182
+	 * @return array<object{n_surn:string,n_surname:string,total:int}>
183
+	 */
184
+	public function surnameData(Tree $tree, bool $marnm, bool $fams): array
185
+	{
186
+		$reflectionMethod = new ReflectionMethod(IndividualListModule::class, 'surnameData');
187
+		$reflectionMethod->setAccessible(true);
188
+
189
+		return $reflectionMethod->invoke($this, $tree, $marnm, $fams);
190
+	}
191
+
192
+	/**
193
+	 * {@inheritDoc}
194
+	 * @see \Fisharebest\Webtrees\Module\IndividualListModule::allSurnames()
195
+	 *
196
+	 * Implemented to set the visibility to public.
197
+	 * This should probably be in a service, but this hack allows for reuse of mainstream code.
198
+	 */
199
+	public function allSurnames(array $surname_data): array
200
+	{
201
+		return parent::allSurnames($surname_data);
202
+	}
203
+
204
+	/**
205
+	 * {@inheritDoc}
206
+	 * @see \Fisharebest\Webtrees\Module\IndividualListModule::surnameInitials()
207
+	 *
208
+	 * Implemented to set the visibility to public.
209
+	 * This should probably be in a service, but this hack allows for reuse of mainstream code.
210
+	 */
211
+	public function surnameInitials(array $surname_data): array
212
+	{
213
+		return parent::surnameInitials($surname_data);
214
+	}
215 215
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function loadRoutes(Map $router): void
74 74
     {
75
-        $router->attach('', '', static function (Map $router): void {
75
+        $router->attach('', '', static function(Map $router): void {
76 76
 
77
-            $router->attach('', '/module-maj/lineages', static function (Map $router): void {
77
+            $router->attach('', '/module-maj/lineages', static function(Map $router): void {
78 78
 
79
-                $router->attach('', '/Page', static function (Map $router): void {
79
+                $router->attach('', '/Page', static function(Map $router): void {
80 80
 
81 81
                     $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class);
82 82
                     $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class);
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 
110 110
         // If a surname is already in the query attribute, use it
111 111
         if ($surname === null) {
112
-            $surname_attr =  Validator::attributes($request)->string('surname', '');
113
-            $surname_param =  Validator::queryParams($request)->string('surname', '');
114
-            $surname_body =  Validator::parsedBody($request)->string('surname', '');
112
+            $surname_attr = Validator::attributes($request)->string('surname', '');
113
+            $surname_param = Validator::queryParams($request)->string('surname', '');
114
+            $surname_body = Validator::parsedBody($request)->string('surname', '');
115 115
             $surname = $surname_attr !== '' ? $surname_attr : (
116 116
                 $surname_param !== '' ? $surname_param : (
117 117
                 $surname_body !== '' ? $surname_body : null
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                 'surname'   =>  $surname
135 135
             ] + $parameters);
136 136
         }
137
-        return route(SurnamesList::class, ['tree'  =>  $tree->name() ] + $parameters);
137
+        return route(SurnamesList::class, ['tree'  =>  $tree->name()] + $parameters);
138 138
     }
139 139
 
140 140
     /**
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function headContent(): string
154 154
     {
155
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
155
+        return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">';
156 156
     }
157 157
 
158 158
     /**
Please login to merge, or discard this patch.
app/Module/GeoDispersion/PlaceMappers/CoordinatesPlaceMapper.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -36,184 +36,184 @@
 block discarded – undo
36 36
  */
37 37
 class CoordinatesPlaceMapper implements PlaceMapperInterface
38 38
 {
39
-    use PlaceMapperTrait;
40
-
41
-    private ?GeometryEngine $geometry_engine = null;
42
-
43
-    /**
44
-     * {@inheritDoc}
45
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title()
46
-     */
47
-    public function title(): string
48
-    {
49
-        return I18N::translate('Mapping on place coordinates');
50
-    }
51
-
52
-    /**
53
-     * {@inheritDoc}
54
-     *
55
-     * {@internal The Place is associated to a Point only.
56
-     * PlaceLocation can calculate a BoundingBox.
57
-     * Using a BoundingBox could make the mapping more complex and potentially arbitary.
58
-     * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents.
59
-     * This could create the unwanted side effect of a very large area to consider}
60
-     *
61
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
62
-     */
63
-    public function map(Place $place, string $feature_property): ?string
64
-    {
65
-        $location = new PlaceLocation($place->gedcomName());
66
-        $longitude = $location->longitude();
67
-        $latitude = $location->latitude();
68
-        if ($longitude === null || $latitude === null) {
69
-            return null;
70
-        }
71
-
72
-        $features_index = $this->featuresIndex();
73
-        if ($features_index === null) {
74
-            return null;
75
-        }
76
-
77
-        $place_point = Point::xy($longitude, $latitude, $features_index['SRID']);
78
-        $grid_box = $this->getGridCell(
79
-            $place_point,
80
-            $features_index['map_NE'],
81
-            $features_index['map_SW'],
82
-            $features_index['nb_columns']
83
-        );
84
-        if ($grid_box === null || !$this->setGeometryEngine() || $this->geometry_engine === null) {
85
-            return null;
86
-        }
87
-        $features = $features_index['grid'][$grid_box[0]][$grid_box[1]];
88
-        foreach ($features as $feature) {
89
-            $geometry = $feature->getGeometry();
90
-            if (
91
-                $geometry !== null && $place_point->SRID() === $geometry->SRID() &&
92
-                $this->geometry_engine->contains($geometry, $place_point)
93
-            ) {
94
-                return $feature->getProperty($feature_property);
95
-            }
96
-        }
97
-        return null;
98
-    }
99
-
100
-    /**
101
-     * Return the XY coordinates in a bounded grid of the cell containing a specific point.
102
-     *
103
-     * @param Point $point Point to find
104
-     * @param Point $grid_NE North-East point of the bounded grid
105
-     * @param Point $grid_SW South-West point fo the bounded grid
106
-     * @param int $grid_columns Number of columns/rows in the grid
107
-     * @return int[]|NULL
108
-     */
109
-    protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array
110
-    {
111
-        list($x, $y) = [$point->x() ?? 0, $point->y() ?? 0];
112
-        list($x_max, $y_max) = [$grid_NE->x() ?? 0, $grid_NE->y() ?? 0];
113
-        list($x_min, $y_min) = [$grid_SW->x() ?? 0, $grid_SW->y() ?? 0];
114
-
115
-        $x_step = ($x_max - $x_min) / $grid_columns;
116
-        $y_step = ($y_max - $y_min) / $grid_columns;
117
-
118
-        if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) {
119
-            return [
120
-                $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step),
121
-                $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step)
122
-            ];
123
-        }
124
-        return null;
125
-    }
126
-
127
-    /**
128
-     * Get an indexed array of the features of the map.
129
-     *
130
-     * {@internal The map is divided in a grid, each cell containing the features which bounding box overlaps that cell.
131
-     * The grid is computed once for each map, and cached.}
132
-     *
133
-     * @phpcs:ignore Generic.Files.LineLength.TooLong
134
-     * @return array{grid: array<int, array<int, \Brick\Geo\IO\GeoJSON\Feature[]>>, nb_columns: int, map_NE: \Brick\Geo\Point, map_SW: \Brick\Geo\Point, SRID: int}|NULL
135
-     */
136
-    protected function featuresIndex(): ?array
137
-    {
138
-        $cacheKey = $this->cacheKey();
139
-        if ($cacheKey === null) {
140
-            return null;
141
-        }
142
-        return Registry::cache()->array()->remember($cacheKey, function (): ?array {
143
-            $map_def = $this->data('map');
144
-            if (
145
-                !$this->setGeometryEngine()
146
-                || $map_def === null
147
-                || !($map_def instanceof MapDefinitionInterface)
148
-            ) {
149
-                return null;
150
-            }
151
-            $bounding_boxes = [];
152
-            $map_bounding_box = new BoundingBox();
153
-            $srid = 0;
154
-            foreach ($map_def->features() as $feature) {
155
-                $geometry = $feature->getGeometry();
156
-                if ($geometry === null) {
157
-                    continue;
158
-                }
159
-                $srid = $geometry->SRID();
160
-                $bounding_box = $geometry->getBoundingBox();
161
-                $bounding_boxes[] = [$feature, $bounding_box];
162
-                $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box);
163
-            }
164
-            $grid_columns = count($bounding_boxes);
165
-            $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, []));
166
-            $map_NE = $map_bounding_box->getNorthEast();
167
-            $map_SW = $map_bounding_box->getSouthWest();
168
-            foreach ($bounding_boxes as $item) {
169
-                $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1];
170
-                $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0];
171
-                for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) {
172
-                    for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) {
173
-                        $grid[$i][$j][] = $item[0];
174
-                    }
175
-                }
176
-            }
177
-            return [
178
-                'grid'          =>  $grid,
179
-                'nb_columns'    =>  $grid_columns,
180
-                'map_NE'        =>  $map_NE,
181
-                'map_SW'        =>  $map_SW,
182
-                'SRID'          =>  $srid
183
-            ];
184
-        });
185
-    }
186
-
187
-    /**
188
-     * Set the Brick Geo Engine to use the database for geospatial computations.
189
-     * The engine is set only if it has not been set beforehand.
190
-     *
191
-     * @return bool
192
-     */
193
-    protected function setGeometryEngine(): bool
194
-    {
195
-        try {
196
-            if ($this->geometry_engine === null) {
197
-                $this->geometry_engine = new PDOEngine(DB::connection()->getPdo());
198
-            }
199
-            $point = Point::xy(1, 1);
200
-            return $this->geometry_engine->equals($point, $point);
201
-        } catch (Throwable $ex) {
202
-        }
203
-        return false;
204
-    }
205
-
206
-    /**
207
-     * Get the key to cache the indexed grid of features.
208
-     *
209
-     * @return string|NULL
210
-     */
211
-    protected function cacheKey(): ?string
212
-    {
213
-        $map_def = $this->data('map');
214
-        if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) {
215
-            return null;
216
-        }
217
-        return spl_object_id($this) . '-map-' . $map_def->id();
218
-    }
39
+	use PlaceMapperTrait;
40
+
41
+	private ?GeometryEngine $geometry_engine = null;
42
+
43
+	/**
44
+	 * {@inheritDoc}
45
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title()
46
+	 */
47
+	public function title(): string
48
+	{
49
+		return I18N::translate('Mapping on place coordinates');
50
+	}
51
+
52
+	/**
53
+	 * {@inheritDoc}
54
+	 *
55
+	 * {@internal The Place is associated to a Point only.
56
+	 * PlaceLocation can calculate a BoundingBox.
57
+	 * Using a BoundingBox could make the mapping more complex and potentially arbitary.
58
+	 * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents.
59
+	 * This could create the unwanted side effect of a very large area to consider}
60
+	 *
61
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
62
+	 */
63
+	public function map(Place $place, string $feature_property): ?string
64
+	{
65
+		$location = new PlaceLocation($place->gedcomName());
66
+		$longitude = $location->longitude();
67
+		$latitude = $location->latitude();
68
+		if ($longitude === null || $latitude === null) {
69
+			return null;
70
+		}
71
+
72
+		$features_index = $this->featuresIndex();
73
+		if ($features_index === null) {
74
+			return null;
75
+		}
76
+
77
+		$place_point = Point::xy($longitude, $latitude, $features_index['SRID']);
78
+		$grid_box = $this->getGridCell(
79
+			$place_point,
80
+			$features_index['map_NE'],
81
+			$features_index['map_SW'],
82
+			$features_index['nb_columns']
83
+		);
84
+		if ($grid_box === null || !$this->setGeometryEngine() || $this->geometry_engine === null) {
85
+			return null;
86
+		}
87
+		$features = $features_index['grid'][$grid_box[0]][$grid_box[1]];
88
+		foreach ($features as $feature) {
89
+			$geometry = $feature->getGeometry();
90
+			if (
91
+				$geometry !== null && $place_point->SRID() === $geometry->SRID() &&
92
+				$this->geometry_engine->contains($geometry, $place_point)
93
+			) {
94
+				return $feature->getProperty($feature_property);
95
+			}
96
+		}
97
+		return null;
98
+	}
99
+
100
+	/**
101
+	 * Return the XY coordinates in a bounded grid of the cell containing a specific point.
102
+	 *
103
+	 * @param Point $point Point to find
104
+	 * @param Point $grid_NE North-East point of the bounded grid
105
+	 * @param Point $grid_SW South-West point fo the bounded grid
106
+	 * @param int $grid_columns Number of columns/rows in the grid
107
+	 * @return int[]|NULL
108
+	 */
109
+	protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array
110
+	{
111
+		list($x, $y) = [$point->x() ?? 0, $point->y() ?? 0];
112
+		list($x_max, $y_max) = [$grid_NE->x() ?? 0, $grid_NE->y() ?? 0];
113
+		list($x_min, $y_min) = [$grid_SW->x() ?? 0, $grid_SW->y() ?? 0];
114
+
115
+		$x_step = ($x_max - $x_min) / $grid_columns;
116
+		$y_step = ($y_max - $y_min) / $grid_columns;
117
+
118
+		if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) {
119
+			return [
120
+				$x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step),
121
+				$y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step)
122
+			];
123
+		}
124
+		return null;
125
+	}
126
+
127
+	/**
128
+	 * Get an indexed array of the features of the map.
129
+	 *
130
+	 * {@internal The map is divided in a grid, each cell containing the features which bounding box overlaps that cell.
131
+	 * The grid is computed once for each map, and cached.}
132
+	 *
133
+	 * @phpcs:ignore Generic.Files.LineLength.TooLong
134
+	 * @return array{grid: array<int, array<int, \Brick\Geo\IO\GeoJSON\Feature[]>>, nb_columns: int, map_NE: \Brick\Geo\Point, map_SW: \Brick\Geo\Point, SRID: int}|NULL
135
+	 */
136
+	protected function featuresIndex(): ?array
137
+	{
138
+		$cacheKey = $this->cacheKey();
139
+		if ($cacheKey === null) {
140
+			return null;
141
+		}
142
+		return Registry::cache()->array()->remember($cacheKey, function (): ?array {
143
+			$map_def = $this->data('map');
144
+			if (
145
+				!$this->setGeometryEngine()
146
+				|| $map_def === null
147
+				|| !($map_def instanceof MapDefinitionInterface)
148
+			) {
149
+				return null;
150
+			}
151
+			$bounding_boxes = [];
152
+			$map_bounding_box = new BoundingBox();
153
+			$srid = 0;
154
+			foreach ($map_def->features() as $feature) {
155
+				$geometry = $feature->getGeometry();
156
+				if ($geometry === null) {
157
+					continue;
158
+				}
159
+				$srid = $geometry->SRID();
160
+				$bounding_box = $geometry->getBoundingBox();
161
+				$bounding_boxes[] = [$feature, $bounding_box];
162
+				$map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box);
163
+			}
164
+			$grid_columns = count($bounding_boxes);
165
+			$grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, []));
166
+			$map_NE = $map_bounding_box->getNorthEast();
167
+			$map_SW = $map_bounding_box->getSouthWest();
168
+			foreach ($bounding_boxes as $item) {
169
+				$grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1];
170
+				$grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0];
171
+				for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) {
172
+					for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) {
173
+						$grid[$i][$j][] = $item[0];
174
+					}
175
+				}
176
+			}
177
+			return [
178
+				'grid'          =>  $grid,
179
+				'nb_columns'    =>  $grid_columns,
180
+				'map_NE'        =>  $map_NE,
181
+				'map_SW'        =>  $map_SW,
182
+				'SRID'          =>  $srid
183
+			];
184
+		});
185
+	}
186
+
187
+	/**
188
+	 * Set the Brick Geo Engine to use the database for geospatial computations.
189
+	 * The engine is set only if it has not been set beforehand.
190
+	 *
191
+	 * @return bool
192
+	 */
193
+	protected function setGeometryEngine(): bool
194
+	{
195
+		try {
196
+			if ($this->geometry_engine === null) {
197
+				$this->geometry_engine = new PDOEngine(DB::connection()->getPdo());
198
+			}
199
+			$point = Point::xy(1, 1);
200
+			return $this->geometry_engine->equals($point, $point);
201
+		} catch (Throwable $ex) {
202
+		}
203
+		return false;
204
+	}
205
+
206
+	/**
207
+	 * Get the key to cache the indexed grid of features.
208
+	 *
209
+	 * @return string|NULL
210
+	 */
211
+	protected function cacheKey(): ?string
212
+	{
213
+		$map_def = $this->data('map');
214
+		if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) {
215
+			return null;
216
+		}
217
+		return spl_object_id($this) . '-map-' . $map_def->id();
218
+	}
219 219
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         if ($cacheKey === null) {
140 140
             return null;
141 141
         }
142
-        return Registry::cache()->array()->remember($cacheKey, function (): ?array {
142
+        return Registry::cache()->array()->remember($cacheKey, function(): ?array {
143 143
             $map_def = $this->data('map');
144 144
             if (
145 145
                 !$this->setGeometryEngine()
@@ -214,6 +214,6 @@  discard block
 block discarded – undo
214 214
         if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) {
215 215
             return null;
216 216
         }
217
-        return spl_object_id($this) . '-map-' . $map_def->id();
217
+        return spl_object_id($this).'-map-'.$map_def->id();
218 218
     }
219 219
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/PlacesReferenceTableService.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -21,88 +21,88 @@
 block discarded – undo
21 21
  */
22 22
 class PlacesReferenceTableService
23 23
 {
24
-    /**
25
-     * Mapping format placeholder tags => table column names
26
-     * @var array<string, string>
27
-     */
28
-    private const COLUMN_MAPPING = [
29
-        'name'  =>  'majgr_place_name',
30
-        'id'    =>  'majgr_place_admin_id',
31
-        'zip'   =>  'majgr_place_zip',
32
-        'gov'   =>  'majgr_place_gov_id',
33
-        'mls'   =>  'majgr_place_mls_id'
34
-    ];
24
+	/**
25
+	 * Mapping format placeholder tags => table column names
26
+	 * @var array<string, string>
27
+	 */
28
+	private const COLUMN_MAPPING = [
29
+		'name'  =>  'majgr_place_name',
30
+		'id'    =>  'majgr_place_admin_id',
31
+		'zip'   =>  'majgr_place_zip',
32
+		'gov'   =>  'majgr_place_gov_id',
33
+		'mls'   =>  'majgr_place_mls_id'
34
+	];
35 35
 
36
-    /**
37
-     * Get the formatted target mapping value of a place defined by a source format.
38
-     *
39
-     * @param string $source
40
-     * @param string $source_format
41
-     * @param string $target_format
42
-     * @return string|NULL
43
-     */
44
-    public function targetId(string $source, string $source_format, string $target_format): ?string
45
-    {
46
-        // Extract parts for the WHERE clause
47
-        $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format);
48
-        $source_parts = preg_split('/[{}]/i', $source_format);
49
-        if ($source_parts === false) {
50
-            return null;
51
-        }
52
-        $source_parts = array_map(function (string $part): string {
53
-            if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54
-                return $this->columnName($column_id[1]);
55
-            }
56
-            return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57
-        }, array_filter($source_parts));
58
-        $source_parts[] = "'%'";
59
-        $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
36
+	/**
37
+	 * Get the formatted target mapping value of a place defined by a source format.
38
+	 *
39
+	 * @param string $source
40
+	 * @param string $source_format
41
+	 * @param string $target_format
42
+	 * @return string|NULL
43
+	 */
44
+	public function targetId(string $source, string $source_format, string $target_format): ?string
45
+	{
46
+		// Extract parts for the WHERE clause
47
+		$source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format);
48
+		$source_parts = preg_split('/[{}]/i', $source_format);
49
+		if ($source_parts === false) {
50
+			return null;
51
+		}
52
+		$source_parts = array_map(function (string $part): string {
53
+			if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54
+				return $this->columnName($column_id[1]);
55
+			}
56
+			return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57
+		}, array_filter($source_parts));
58
+		$source_parts[] = "'%'";
59
+		$concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
60 60
 
61
-        // Extract columns used in target
62
-        $columns = [];
63
-        if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) {
64
-            $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1])));
65
-        }
61
+		// Extract columns used in target
62
+		$columns = [];
63
+		if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) {
64
+			$columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1])));
65
+		}
66 66
 
67
-        // Get the mapping
68
-        $rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69
-            ->select($columns)
70
-            ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
71
-            ->get();
67
+		// Get the mapping
68
+		$rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69
+			->select($columns)
70
+			->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
71
+			->get();
72 72
 
73
-        // Format the output ID
74
-        if ($rows->count() === 0) {
75
-            return null;
76
-        }
73
+		// Format the output ID
74
+		if ($rows->count() === 0) {
75
+			return null;
76
+		}
77 77
 
78
-        $mapping = (array) $rows->first();
78
+		$mapping = (array) $rows->first();
79 79
 
80
-        return str_replace(
81
-            array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
82
-            array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
83
-            $target_format
84
-        );
85
-    }
80
+		return str_replace(
81
+			array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
82
+			array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
83
+			$target_format
84
+		);
85
+	}
86 86
 
87
-    /**
88
-     * Get the column name for a format placeholder tag
89
-     *
90
-     * @param string $placeholder
91
-     * @return string
92
-     */
93
-    private function columnName(string $placeholder): string
94
-    {
95
-        return self::COLUMN_MAPPING[$placeholder] ?? '';
96
-    }
87
+	/**
88
+	 * Get the column name for a format placeholder tag
89
+	 *
90
+	 * @param string $placeholder
91
+	 * @return string
92
+	 */
93
+	private function columnName(string $placeholder): string
94
+	{
95
+		return self::COLUMN_MAPPING[$placeholder] ?? '';
96
+	}
97 97
 
98
-    /**
99
-     * Sanitize string for use in a SQL query.
100
-     *
101
-     * @param string $string
102
-     * @return string
103
-     */
104
-    private function sanitizeString(string $string): string
105
-    {
106
-        return DB::connection()->getPdo()->quote($string);
107
-    }
98
+	/**
99
+	 * Sanitize string for use in a SQL query.
100
+	 *
101
+	 * @param string $string
102
+	 * @return string
103
+	 */
104
+	private function sanitizeString(string $string): string
105
+	{
106
+		return DB::connection()->getPdo()->quote($string);
107
+	}
108 108
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
         if ($source_parts === false) {
50 50
             return null;
51 51
         }
52
-        $source_parts = array_map(function (string $part): string {
52
+        $source_parts = array_map(function(string $part): string {
53 53
             if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54 54
                 return $this->columnName($column_id[1]);
55 55
             }
56 56
             return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57 57
         }, array_filter($source_parts));
58 58
         $source_parts[] = "'%'";
59
-        $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
59
+        $concat_statement = 'CONCAT('.implode(', ', $source_parts).')';
60 60
 
61 61
         // Extract columns used in target
62 62
         $columns = [];
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         // Get the mapping
68 68
         $rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69 69
             ->select($columns)
70
-            ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
70
+            ->whereRaw($this->sanitizeString($source)." LIKE ".$concat_statement)
71 71
             ->get();
72 72
 
73 73
         // Format the output ID
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
             return null;
76 76
         }
77 77
 
78
-        $mapping = (array) $rows->first();
78
+        $mapping = (array)$rows->first();
79 79
 
80 80
         return str_replace(
81
-            array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
81
+            array_map(fn($tag) => '{'.$tag.'}', $columns_select[1]),
82 82
             array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
83 83
             $target_format
84 84
         );
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/GeoAnalysisDataService.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -26,64 +26,64 @@
 block discarded – undo
26 26
  */
27 27
 class GeoAnalysisDataService
28 28
 {
29
-    /**
30
-     * Yields indviduals and family records for a specified tree.
31
-     *
32
-     * @param Tree $tree
33
-     * @return \Generator<\Fisharebest\Webtrees\GedcomRecord>
34
-     */
35
-    public function individualsAndFamilies(Tree $tree): Generator
36
-    {
37
-        yield from DB::table('individuals')
38
-            ->where('i_file', '=', $tree->id())
39
-            ->select(['individuals.*'])
40
-            ->get()
41
-            ->map(Registry::individualFactory()->mapper($tree))
42
-            ->filter(GedcomRecord::accessFilter())
43
-            ->all();
29
+	/**
30
+	 * Yields indviduals and family records for a specified tree.
31
+	 *
32
+	 * @param Tree $tree
33
+	 * @return \Generator<\Fisharebest\Webtrees\GedcomRecord>
34
+	 */
35
+	public function individualsAndFamilies(Tree $tree): Generator
36
+	{
37
+		yield from DB::table('individuals')
38
+			->where('i_file', '=', $tree->id())
39
+			->select(['individuals.*'])
40
+			->get()
41
+			->map(Registry::individualFactory()->mapper($tree))
42
+			->filter(GedcomRecord::accessFilter())
43
+			->all();
44 44
 
45
-        yield from DB::table('families')
46
-            ->where('f_file', '=', $tree->id())
47
-            ->select(['families.*'])
48
-            ->get()
49
-            ->map(Registry::familyFactory()->mapper($tree))
50
-            ->filter(GedcomRecord::accessFilter())
51
-            ->all();
52
-    }
45
+		yield from DB::table('families')
46
+			->where('f_file', '=', $tree->id())
47
+			->select(['families.*'])
48
+			->get()
49
+			->map(Registry::familyFactory()->mapper($tree))
50
+			->filter(GedcomRecord::accessFilter())
51
+			->all();
52
+	}
53 53
 
54
-    /**
55
-     * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest
56
-     * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first).
57
-     *
58
-     * {@internal The places are taken only from the individuals and families records.}
59
-     *
60
-     * @param Tree $tree
61
-     * @return array<int, string[]>
62
-     */
63
-    public function placeHierarchyExample(Tree $tree): array
64
-    {
65
-        $query_individuals = DB::table('individuals')
66
-            ->select(['i_gedcom AS g_gedcom'])
67
-            ->where('i_file', '=', $tree->id())
68
-            ->where('i_gedcom', 'like', '%2 PLAC %');
54
+	/**
55
+	 * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest
56
+	 * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first).
57
+	 *
58
+	 * {@internal The places are taken only from the individuals and families records.}
59
+	 *
60
+	 * @param Tree $tree
61
+	 * @return array<int, string[]>
62
+	 */
63
+	public function placeHierarchyExample(Tree $tree): array
64
+	{
65
+		$query_individuals = DB::table('individuals')
66
+			->select(['i_gedcom AS g_gedcom'])
67
+			->where('i_file', '=', $tree->id())
68
+			->where('i_gedcom', 'like', '%2 PLAC %');
69 69
 
70
-        $query_families = DB::table('families')
71
-            ->select(['f_gedcom AS g_gedcom'])
72
-            ->where('f_file', '=', $tree->id())
73
-            ->where('f_gedcom', 'like', '%2 PLAC %');
70
+		$query_families = DB::table('families')
71
+			->select(['f_gedcom AS g_gedcom'])
72
+			->where('f_file', '=', $tree->id())
73
+			->where('f_gedcom', 'like', '%2 PLAC %');
74 74
 
75
-        return $query_individuals->unionAll($query_families)
76
-            ->get()->pluck('g_gedcom')
77
-            ->flatMap(static function (string $gedcom): array {
78
-                preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches);
79
-                return $matches[1];
80
-            })
81
-            ->sort(I18N::comparator())->reverse()
82
-            ->mapWithKeys(static function (string $place): array {
83
-                $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place))));
84
-                return [ count($place_array) => $place_array ];
85
-            })
86
-            ->sortKeys()
87
-            ->last() ?? [];
88
-    }
75
+		return $query_individuals->unionAll($query_families)
76
+			->get()->pluck('g_gedcom')
77
+			->flatMap(static function (string $gedcom): array {
78
+				preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches);
79
+				return $matches[1];
80
+			})
81
+			->sort(I18N::comparator())->reverse()
82
+			->mapWithKeys(static function (string $place): array {
83
+				$place_array = array_reverse(array_filter(array_map('trim', explode(",", $place))));
84
+				return [ count($place_array) => $place_array ];
85
+			})
86
+			->sortKeys()
87
+			->last() ?? [];
88
+	}
89 89
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -74,14 +74,14 @@
 block discarded – undo
74 74
 
75 75
         return $query_individuals->unionAll($query_families)
76 76
             ->get()->pluck('g_gedcom')
77
-            ->flatMap(static function (string $gedcom): array {
77
+            ->flatMap(static function(string $gedcom): array {
78 78
                 preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches);
79 79
                 return $matches[1];
80 80
             })
81 81
             ->sort(I18N::comparator())->reverse()
82
-            ->mapWithKeys(static function (string $place): array {
82
+            ->mapWithKeys(static function(string $place): array {
83 83
                 $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place))));
84
-                return [ count($place_array) => $place_array ];
84
+                return [count($place_array) => $place_array];
85 85
             })
86 86
             ->sortKeys()
87 87
             ->last() ?? [];
Please login to merge, or discard this patch.
app/Module/ModuleMyArtJaubTrait.php 2 patches
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(Registry::routeFactory()->routeMap());
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(Registry::routeFactory()->routeMap());
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.
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(Registry::routeFactory()->routeMap());
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);
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
     {
97 97
         /** @var ModuleThemeInterface $theme */
98 98
         $theme = app(ModuleThemeInterface::class);
99
-        $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css';
99
+        $css_file = $this->resourcesFolder().'css/'.$theme->name().'.min.css';
100 100
 
101 101
         if (file_exists($css_file)) {
102
-            return $this->assetUrl('css/' . $theme->name() . '.min.css');
102
+            return $this->assetUrl('css/'.$theme->name().'.min.css');
103 103
         } else {
104 104
             return $this->assetUrl('css/default.min.css');
105 105
         }
Please login to merge, or discard this patch.