Passed
Branch feature/2.1-geodispersion-dev (1d61a8)
by Jonathan
61:21
created
src/Webtrees/Module/GeoDispersion/Model/GeoAnalysisMapAdapter.php 1 patch
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -29,156 +29,156 @@
 block discarded – undo
29 29
  */
30 30
 class GeoAnalysisMapAdapter
31 31
 {
32
-    private int $id;
33
-    private MapDefinitionInterface $map;
34
-    private PlaceMapperInterface $place_mapper;
35
-    private MapViewConfigInterface $config;
36
-
37
-    /**
38
-     * Constructor for GeoAnalysisMapAdapter
39
-     *
40
-     * @param int $id
41
-     * @param MapDefinitionInterface $map
42
-     * @param PlaceMapperInterface $mapper
43
-     * @param MapViewConfigInterface $config
44
-     */
45
-    public function __construct(
46
-        int $id,
47
-        MapDefinitionInterface $map,
48
-        PlaceMapperInterface $mapper,
49
-        MapViewConfigInterface $config
50
-    ) {
51
-        $this->id = $id;
52
-        $this->map = $map;
53
-        $this->place_mapper = $mapper;
54
-        $this->config = $config;
55
-        $this->place_mapper->setConfig($this->config->mapperConfig());
56
-        $this->place_mapper->setData('map', $map);
57
-        $this->place_mapper->boot();
58
-    }
59
-
60
-    /**
61
-     * Get the GeoAnalysisMapAdapter ID
62
-     *
63
-     * @return int
64
-     */
65
-    public function id(): int
66
-    {
67
-        return $this->id;
68
-    }
69
-
70
-    /**
71
-     * Get the associated target map
72
-     *
73
-     * @return MapDefinitionInterface
74
-     */
75
-    public function map(): MapDefinitionInterface
76
-    {
77
-        return $this->map;
78
-    }
79
-
80
-    /**
81
-     * Get the Place Mapper used for the mapping
82
-     *
83
-     * @return PlaceMapperInterface
84
-     */
85
-    public function placeMapper(): PlaceMapperInterface
86
-    {
87
-        return $this->place_mapper;
88
-    }
89
-
90
-    /**
91
-     * Get the configuration of the Map View.
92
-     *
93
-     * @return MapViewConfigInterface
94
-     */
95
-    public function viewConfig(): MapViewConfigInterface
96
-    {
97
-        return $this->config;
98
-    }
99
-
100
-    /**
101
-     * Convert the geographical analysis result to a MapAdapter result for usage in the Map View
102
-     *
103
-     * @param GeoAnalysisResult $result
104
-     * @return MapAdapterResult
105
-     */
106
-    public function convert(GeoAnalysisResult $result): MapAdapterResult
107
-    {
108
-        $result = $result->copy();
109
-
110
-        $features = [];
111
-        list($features_data, $result) = $this->featureAnalysisData($result);
112
-
113
-        $places_found = $result->countFound();
114
-        foreach ($this->map->features() as $feature) {
115
-            $feature_id = $this->featureId($feature);
116
-            if ($feature_id !== null && $features_data->has($feature_id)) {
117
-                /** @var MapFeatureAnalysisData $feature_data */
118
-                $feature_data = $features_data->get($feature_id)->tagAsExisting();
119
-                $place_count = $feature_data->count();
120
-                $features[] = $feature
121
-                    ->withProperty('count', $place_count)
122
-                    ->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0)
123
-                    ->withProperty(
124
-                        'places',
125
-                        $feature_data->places()
126
-                            ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
127
-                            ->sort(I18N::comparator())
128
-                            ->toArray()
129
-                    );
130
-            } else {
131
-                $features[] = $feature;
132
-            }
133
-        }
134
-
135
-        $features_data
136
-            ->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap())
137
-            ->each(
138
-                fn (MapFeatureAnalysisData $data) =>
139
-                    $data->places()->each(
140
-                        fn(GeoAnalysisPlace $place) => $result->exclude($place)
141
-                    )
142
-            );
143
-
144
-        return new MapAdapterResult($result, $features);
145
-    }
146
-
147
-    /**
148
-     * Populate the map features with the mapped Places and total count
149
-     *
150
-     * @param GeoAnalysisResult $result
151
-     * @return array
152
-     */
153
-    protected function featureAnalysisData(GeoAnalysisResult $result): array
154
-    {
155
-        $features_mapping = new Collection();
156
-
157
-        $byplaces = $result->knownPlaces();
158
-        $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
159
-            $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
160
-
161
-            if ($id !== null && mb_strlen($id) > 0) {
162
-                $features_mapping->put(
163
-                    $id,
164
-                    $features_mapping->get($id, new MapFeatureAnalysisData($id))->add($item->place(), $item->count())
165
-                );
166
-            } else {
167
-                $result->exclude($item->place());
168
-            }
169
-        });
170
-
171
-        return [ $features_mapping, $result];
172
-    }
173
-
174
-    /**
175
-     * Get the value of the feature property used for the mapping
176
-     *
177
-     * @param Feature $feature
178
-     * @return string|NULL
179
-     */
180
-    protected function featureId(Feature $feature): ?string
181
-    {
182
-        return $feature->getProperty($this->config->mapMappingProperty());
183
-    }
32
+	private int $id;
33
+	private MapDefinitionInterface $map;
34
+	private PlaceMapperInterface $place_mapper;
35
+	private MapViewConfigInterface $config;
36
+
37
+	/**
38
+	 * Constructor for GeoAnalysisMapAdapter
39
+	 *
40
+	 * @param int $id
41
+	 * @param MapDefinitionInterface $map
42
+	 * @param PlaceMapperInterface $mapper
43
+	 * @param MapViewConfigInterface $config
44
+	 */
45
+	public function __construct(
46
+		int $id,
47
+		MapDefinitionInterface $map,
48
+		PlaceMapperInterface $mapper,
49
+		MapViewConfigInterface $config
50
+	) {
51
+		$this->id = $id;
52
+		$this->map = $map;
53
+		$this->place_mapper = $mapper;
54
+		$this->config = $config;
55
+		$this->place_mapper->setConfig($this->config->mapperConfig());
56
+		$this->place_mapper->setData('map', $map);
57
+		$this->place_mapper->boot();
58
+	}
59
+
60
+	/**
61
+	 * Get the GeoAnalysisMapAdapter ID
62
+	 *
63
+	 * @return int
64
+	 */
65
+	public function id(): int
66
+	{
67
+		return $this->id;
68
+	}
69
+
70
+	/**
71
+	 * Get the associated target map
72
+	 *
73
+	 * @return MapDefinitionInterface
74
+	 */
75
+	public function map(): MapDefinitionInterface
76
+	{
77
+		return $this->map;
78
+	}
79
+
80
+	/**
81
+	 * Get the Place Mapper used for the mapping
82
+	 *
83
+	 * @return PlaceMapperInterface
84
+	 */
85
+	public function placeMapper(): PlaceMapperInterface
86
+	{
87
+		return $this->place_mapper;
88
+	}
89
+
90
+	/**
91
+	 * Get the configuration of the Map View.
92
+	 *
93
+	 * @return MapViewConfigInterface
94
+	 */
95
+	public function viewConfig(): MapViewConfigInterface
96
+	{
97
+		return $this->config;
98
+	}
99
+
100
+	/**
101
+	 * Convert the geographical analysis result to a MapAdapter result for usage in the Map View
102
+	 *
103
+	 * @param GeoAnalysisResult $result
104
+	 * @return MapAdapterResult
105
+	 */
106
+	public function convert(GeoAnalysisResult $result): MapAdapterResult
107
+	{
108
+		$result = $result->copy();
109
+
110
+		$features = [];
111
+		list($features_data, $result) = $this->featureAnalysisData($result);
112
+
113
+		$places_found = $result->countFound();
114
+		foreach ($this->map->features() as $feature) {
115
+			$feature_id = $this->featureId($feature);
116
+			if ($feature_id !== null && $features_data->has($feature_id)) {
117
+				/** @var MapFeatureAnalysisData $feature_data */
118
+				$feature_data = $features_data->get($feature_id)->tagAsExisting();
119
+				$place_count = $feature_data->count();
120
+				$features[] = $feature
121
+					->withProperty('count', $place_count)
122
+					->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0)
123
+					->withProperty(
124
+						'places',
125
+						$feature_data->places()
126
+							->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
127
+							->sort(I18N::comparator())
128
+							->toArray()
129
+					);
130
+			} else {
131
+				$features[] = $feature;
132
+			}
133
+		}
134
+
135
+		$features_data
136
+			->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap())
137
+			->each(
138
+				fn (MapFeatureAnalysisData $data) =>
139
+					$data->places()->each(
140
+						fn(GeoAnalysisPlace $place) => $result->exclude($place)
141
+					)
142
+			);
143
+
144
+		return new MapAdapterResult($result, $features);
145
+	}
146
+
147
+	/**
148
+	 * Populate the map features with the mapped Places and total count
149
+	 *
150
+	 * @param GeoAnalysisResult $result
151
+	 * @return array
152
+	 */
153
+	protected function featureAnalysisData(GeoAnalysisResult $result): array
154
+	{
155
+		$features_mapping = new Collection();
156
+
157
+		$byplaces = $result->knownPlaces();
158
+		$byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
159
+			$id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
160
+
161
+			if ($id !== null && mb_strlen($id) > 0) {
162
+				$features_mapping->put(
163
+					$id,
164
+					$features_mapping->get($id, new MapFeatureAnalysisData($id))->add($item->place(), $item->count())
165
+				);
166
+			} else {
167
+				$result->exclude($item->place());
168
+			}
169
+		});
170
+
171
+		return [ $features_mapping, $result];
172
+	}
173
+
174
+	/**
175
+	 * Get the value of the feature property used for the mapping
176
+	 *
177
+	 * @param Feature $feature
178
+	 * @return string|NULL
179
+	 */
180
+	protected function featureId(Feature $feature): ?string
181
+	{
182
+		return $feature->getProperty($this->config->mapMappingProperty());
183
+	}
184 184
 }
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewTabs.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -30,66 +30,66 @@
 block discarded – undo
30 30
  */
31 31
 class GeoAnalysisViewTabs implements RequestHandlerInterface
32 32
 {
33
-    private ?GeoDispersionModule $module;
34
-    private GeoAnalysisViewDataService $geoviewdata_service;
33
+	private ?GeoDispersionModule $module;
34
+	private GeoAnalysisViewDataService $geoviewdata_service;
35 35
 
36
-    /**
37
-     * Constructor for GeoAnalysisMapsList Request Handler
38
-     *
39
-     * @param ModuleService $module_service
40
-     */
41
-    public function __construct(
42
-        ModuleService $module_service,
43
-        GeoAnalysisViewDataService $geoviewdata_service
44
-    ) {
45
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
46
-        $this->geoviewdata_service = $geoviewdata_service;
47
-    }
36
+	/**
37
+	 * Constructor for GeoAnalysisMapsList Request Handler
38
+	 *
39
+	 * @param ModuleService $module_service
40
+	 */
41
+	public function __construct(
42
+		ModuleService $module_service,
43
+		GeoAnalysisViewDataService $geoviewdata_service
44
+	) {
45
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
46
+		$this->geoviewdata_service = $geoviewdata_service;
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritDoc}
51
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
-     */
53
-    public function handle(ServerRequestInterface $request): ResponseInterface
54
-    {
55
-        if ($this->module === null) {
56
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
57
-        }
49
+	/**
50
+	 * {@inheritDoc}
51
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
+	 */
53
+	public function handle(ServerRequestInterface $request): ResponseInterface
54
+	{
55
+		if ($this->module === null) {
56
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
57
+		}
58 58
 
59
-        $tree = $request->getAttribute('tree');
60
-        assert($tree instanceof Tree);
59
+		$tree = $request->getAttribute('tree');
60
+		assert($tree instanceof Tree);
61 61
 
62
-        $view_id = $request->getAttribute('view_id');
63
-        $view_id = is_numeric($view_id) ? (int) $view_id : 0;
62
+		$view_id = $request->getAttribute('view_id');
63
+		$view_id = is_numeric($view_id) ? (int) $view_id : 0;
64 64
 
65
-        $view = $this->geoviewdata_service->find($tree, $view_id);
65
+		$view = $this->geoviewdata_service->find($tree, $view_id);
66 66
 
67
-        if ($view === null) {
68
-            throw new HttpNotFoundException(I18N::translate('The requested dispersion analysis does not exist.'));
69
-        }
67
+		if ($view === null) {
68
+			throw new HttpNotFoundException(I18N::translate('The requested dispersion analysis does not exist.'));
69
+		}
70 70
 
71
-        $results = $view->analysis()->results($tree, $view->placesDepth());
71
+		$results = $view->analysis()->results($tree, $view->placesDepth());
72 72
 
73
-        $params = [
74
-            'module_name'   =>  $this->module->name(),
75
-            'tree'          =>  $tree,
76
-            'view'          =>  $view,
77
-            'items_descr'   =>  $view->analysis()->itemsDescription()
78
-        ];
79
-        $response = [
80
-            'global'    =>  view('layouts/ajax', [
81
-                'content' =>    $view->globalTabContent(
82
-                    $this->module,
83
-                    $results->global(),
84
-                    $this->geoviewdata_service,
85
-                    $params
86
-                )
87
-            ]),
88
-            'detailed'  => view('layouts/ajax', [
89
-                'content' =>    $view->detailedTabContent($this->module, $results->sortedDetailed(), $params)
90
-            ])
91
-        ];
73
+		$params = [
74
+			'module_name'   =>  $this->module->name(),
75
+			'tree'          =>  $tree,
76
+			'view'          =>  $view,
77
+			'items_descr'   =>  $view->analysis()->itemsDescription()
78
+		];
79
+		$response = [
80
+			'global'    =>  view('layouts/ajax', [
81
+				'content' =>    $view->globalTabContent(
82
+					$this->module,
83
+					$results->global(),
84
+					$this->geoviewdata_service,
85
+					$params
86
+				)
87
+			]),
88
+			'detailed'  => view('layouts/ajax', [
89
+				'content' =>    $view->detailedTabContent($this->module, $results->sortedDetailed(), $params)
90
+			])
91
+		];
92 92
 
93
-        return response($response);
94
-    }
93
+		return response($response);
94
+	}
95 95
 }
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewsList.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -32,47 +32,47 @@
 block discarded – undo
32 32
  */
33 33
 class GeoAnalysisViewsList implements RequestHandlerInterface
34 34
 {
35
-    use ViewResponseTrait;
35
+	use ViewResponseTrait;
36 36
 
37
-    private ?GeoDispersionModule $module;
38
-    private GeoAnalysisViewDataService $geoviewdata_service;
37
+	private ?GeoDispersionModule $module;
38
+	private GeoAnalysisViewDataService $geoviewdata_service;
39 39
 
40
-    /**
41
-     * Constructor for GeoAnalysisViewsList Request Handler
42
-     *
43
-     * @param ModuleService $module_service
44
-     */
45
-    public function __construct(
46
-        ModuleService $module_service,
47
-        GeoAnalysisViewDataService $geoviewdata_service
48
-    ) {
49
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
50
-        $this->geoviewdata_service = $geoviewdata_service;
51
-    }
40
+	/**
41
+	 * Constructor for GeoAnalysisViewsList Request Handler
42
+	 *
43
+	 * @param ModuleService $module_service
44
+	 */
45
+	public function __construct(
46
+		ModuleService $module_service,
47
+		GeoAnalysisViewDataService $geoviewdata_service
48
+	) {
49
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
50
+		$this->geoviewdata_service = $geoviewdata_service;
51
+	}
52 52
 
53
-    /**
54
-     * {@inheritDoc}
55
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
-     */
57
-    public function handle(ServerRequestInterface $request): ResponseInterface
58
-    {
59
-        if ($this->module === null) {
60
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
61
-        }
53
+	/**
54
+	 * {@inheritDoc}
55
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
+	 */
57
+	public function handle(ServerRequestInterface $request): ResponseInterface
58
+	{
59
+		if ($this->module === null) {
60
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
61
+		}
62 62
 
63
-        $tree = $request->getAttribute('tree');
64
-        assert($tree instanceof Tree);
63
+		$tree = $request->getAttribute('tree');
64
+		assert($tree instanceof Tree);
65 65
 
66
-        $views_list = $this->geoviewdata_service
67
-            ->all($tree)
68
-            ->sortBy(fn(AbstractGeoAnalysisView $view) => $view->description());
66
+		$views_list = $this->geoviewdata_service
67
+			->all($tree)
68
+			->sortBy(fn(AbstractGeoAnalysisView $view) => $view->description());
69 69
 
70
-        return $this->viewResponse($this->module->name() . '::geoanalysisviews-list', [
71
-            'module'        =>  $this->module,
72
-            'title'         =>  I18N::translate('Geographical dispersion'),
73
-            'tree'          =>  $tree,
74
-            'views_list'    =>  $views_list,
75
-            'js_script_url' =>  $this->module->assetUrl('js/geodispersion.min.js')
76
-        ]);
77
-    }
70
+		return $this->viewResponse($this->module->name() . '::geoanalysisviews-list', [
71
+			'module'        =>  $this->module,
72
+			'title'         =>  I18N::translate('Geographical dispersion'),
73
+			'tree'          =>  $tree,
74
+			'views_list'    =>  $views_list,
75
+			'js_script_url' =>  $this->module->assetUrl('js/geodispersion.min.js')
76
+		]);
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewPage.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -31,45 +31,45 @@
 block discarded – undo
31 31
  */
32 32
 class GeoAnalysisViewPage implements RequestHandlerInterface
33 33
 {
34
-    use ViewResponseTrait;
34
+	use ViewResponseTrait;
35 35
 
36
-    private ?GeoDispersionModule $module;
37
-    private GeoAnalysisViewDataService $geoviewdata_service;
36
+	private ?GeoDispersionModule $module;
37
+	private GeoAnalysisViewDataService $geoviewdata_service;
38 38
 
39
-    /**
40
-     * Constructor for GeoAnalysisViewPage Request Handler
41
-     *
42
-     * @param ModuleService $module_service
43
-     */
44
-    public function __construct(
45
-        ModuleService $module_service,
46
-        GeoAnalysisViewDataService $geoviewdata_service
47
-    ) {
48
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
49
-        $this->geoviewdata_service = $geoviewdata_service;
50
-    }
39
+	/**
40
+	 * Constructor for GeoAnalysisViewPage Request Handler
41
+	 *
42
+	 * @param ModuleService $module_service
43
+	 */
44
+	public function __construct(
45
+		ModuleService $module_service,
46
+		GeoAnalysisViewDataService $geoviewdata_service
47
+	) {
48
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
49
+		$this->geoviewdata_service = $geoviewdata_service;
50
+	}
51 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
-        }
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 61
 
62
-        $tree = $request->getAttribute('tree');
63
-        assert($tree instanceof Tree);
62
+		$tree = $request->getAttribute('tree');
63
+		assert($tree instanceof Tree);
64 64
 
65
-        $view_id = $request->getAttribute('view_id');
66
-        $view_id = is_numeric($view_id) ? (int) $view_id : 0;
65
+		$view_id = $request->getAttribute('view_id');
66
+		$view_id = is_numeric($view_id) ? (int) $view_id : 0;
67 67
 
68
-        return $this->viewResponse($this->module->name() . '::geoanalysisview-page', [
69
-            'module_name'           =>  $this->module->name(),
70
-            'title'                 =>  I18N::translate('Geographical dispersion'),
71
-            'tree'                  =>  $tree,
72
-            'view'                  =>  $this->geoviewdata_service->find($tree, $view_id)
73
-        ]);
74
-    }
68
+		return $this->viewResponse($this->module->name() . '::geoanalysisview-page', [
69
+			'module_name'           =>  $this->module->name(),
70
+			'title'                 =>  I18N::translate('Geographical dispersion'),
71
+			'tree'                  =>  $tree,
72
+			'view'                  =>  $this->geoviewdata_service->find($tree, $view_id)
73
+		]);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/GeoDispersionModule.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -41,134 +41,134 @@
 block discarded – undo
41 41
  * Geographical Dispersion Module.
42 42
  */
43 43
 class GeoDispersionModule extends AbstractModule implements
44
-    ModuleMyArtJaubInterface,
45
-    ModuleChartInterface,
46
-    ModuleGlobalInterface,
47
-    ModuleGeoAnalysisProviderInterface,
48
-    ModulePlaceMapperProviderInterface
44
+	ModuleMyArtJaubInterface,
45
+	ModuleChartInterface,
46
+	ModuleGlobalInterface,
47
+	ModuleGeoAnalysisProviderInterface,
48
+	ModulePlaceMapperProviderInterface
49 49
 {
50
-    use ModuleMyArtJaubTrait {
51
-        boot as traitBoot;
52
-    }
53
-    use ModuleChartTrait;
54
-    use ModuleGlobalTrait;
55
-
56
-    // How to update the database schema for this module
57
-    private const SCHEMA_TARGET_VERSION   = 2;
58
-    private const SCHEMA_SETTING_NAME     = 'MAJ_GEODISP_SCHEMA_VERSION';
59
-    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
60
-
61
-    /**
62
-     * {@inheritDoc}
63
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
64
-     */
65
-    public function title(): string
66
-    {
67
-        return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical Dispersion');
68
-    }
69
-
70
-    /**
71
-     * {@inheritDoc}
72
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
73
-     */
74
-    public function description(): string
75
-    {
76
-        //phpcs:ignore Generic.Files.LineLength.TooLong
77
-        return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analysis');
78
-    }
79
-
80
-    /**
81
-     * {@inheritDoc}
82
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
83
-     */
84
-    public function boot(): void
85
-    {
86
-        $this->traitBoot();
87
-        app(MigrationService::class)->updateSchema(
88
-            self::SCHEMA_MIGRATION_PREFIX,
89
-            self::SCHEMA_SETTING_NAME,
90
-            self::SCHEMA_TARGET_VERSION
91
-        );
92
-    }
93
-
94
-    /**
95
-     * {@inheritDoc}
96
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
97
-     */
98
-    public function customModuleVersion(): string
99
-    {
100
-        return '2.1.0-v.1';
101
-    }
102
-
103
-    /**
104
-     * {@inheritDoc}
105
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
106
-     */
107
-    public function loadRoutes(Map $router): void
108
-    {
109
-        $router->attach('', '', static function (Map $router): void {
110
-
111
-            $router->attach('', '/module-maj/geodispersion', static function (Map $router): void {
112
-
113
-                $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class);
114
-
115
-                $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void {
116
-                    $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class);
117
-                    $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class);
118
-                });
119
-            });
120
-        });
121
-    }
122
-
123
-    /**
124
-     * {@inheritDoc}
125
-     * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl()
126
-     */
127
-    public function chartUrl(Individual $individual, array $parameters = []): string
128
-    {
129
-        return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters);
130
-    }
131
-
132
-    /**
133
-     * {@inheritDoc}
134
-     * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass()
135
-     */
136
-    public function chartMenuClass(): string
137
-    {
138
-        return 'menu-maj-geodispersion';
139
-    }
140
-
141
-    /**
142
-     * {@inheritDoc}
143
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
144
-     */
145
-    public function headContent(): string
146
-    {
147
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
148
-    }
149
-
150
-    /**
151
-     * {@inheritDoc}
152
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers()
153
-     */
154
-    public function listPlaceMappers(): array
155
-    {
156
-        return [
157
-            CoordinatesPlaceMapper::class,
158
-            SimplePlaceMapper::class,
159
-            SimpleTopFilteredPlaceMapper::class
160
-        ];
161
-    }
162
-
163
-    /**
164
-     * {@inheritDoc}
165
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
166
-     */
167
-    public function listGeoAnalyses(): array
168
-    {
169
-        return [
170
-            AllEventsByCenturyGeoAnalysis::class,
171
-            AllEventsByTypeGeoAnalysis::class
172
-        ];
173
-    }
50
+	use ModuleMyArtJaubTrait {
51
+		boot as traitBoot;
52
+	}
53
+	use ModuleChartTrait;
54
+	use ModuleGlobalTrait;
55
+
56
+	// How to update the database schema for this module
57
+	private const SCHEMA_TARGET_VERSION   = 2;
58
+	private const SCHEMA_SETTING_NAME     = 'MAJ_GEODISP_SCHEMA_VERSION';
59
+	private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
60
+
61
+	/**
62
+	 * {@inheritDoc}
63
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
64
+	 */
65
+	public function title(): string
66
+	{
67
+		return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical Dispersion');
68
+	}
69
+
70
+	/**
71
+	 * {@inheritDoc}
72
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
73
+	 */
74
+	public function description(): string
75
+	{
76
+		//phpcs:ignore Generic.Files.LineLength.TooLong
77
+		return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analysis');
78
+	}
79
+
80
+	/**
81
+	 * {@inheritDoc}
82
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
83
+	 */
84
+	public function boot(): void
85
+	{
86
+		$this->traitBoot();
87
+		app(MigrationService::class)->updateSchema(
88
+			self::SCHEMA_MIGRATION_PREFIX,
89
+			self::SCHEMA_SETTING_NAME,
90
+			self::SCHEMA_TARGET_VERSION
91
+		);
92
+	}
93
+
94
+	/**
95
+	 * {@inheritDoc}
96
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
97
+	 */
98
+	public function customModuleVersion(): string
99
+	{
100
+		return '2.1.0-v.1';
101
+	}
102
+
103
+	/**
104
+	 * {@inheritDoc}
105
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
106
+	 */
107
+	public function loadRoutes(Map $router): void
108
+	{
109
+		$router->attach('', '', static function (Map $router): void {
110
+
111
+			$router->attach('', '/module-maj/geodispersion', static function (Map $router): void {
112
+
113
+				$router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class);
114
+
115
+				$router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void {
116
+					$router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class);
117
+					$router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class);
118
+				});
119
+			});
120
+		});
121
+	}
122
+
123
+	/**
124
+	 * {@inheritDoc}
125
+	 * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl()
126
+	 */
127
+	public function chartUrl(Individual $individual, array $parameters = []): string
128
+	{
129
+		return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters);
130
+	}
131
+
132
+	/**
133
+	 * {@inheritDoc}
134
+	 * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass()
135
+	 */
136
+	public function chartMenuClass(): string
137
+	{
138
+		return 'menu-maj-geodispersion';
139
+	}
140
+
141
+	/**
142
+	 * {@inheritDoc}
143
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
144
+	 */
145
+	public function headContent(): string
146
+	{
147
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
148
+	}
149
+
150
+	/**
151
+	 * {@inheritDoc}
152
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers()
153
+	 */
154
+	public function listPlaceMappers(): array
155
+	{
156
+		return [
157
+			CoordinatesPlaceMapper::class,
158
+			SimplePlaceMapper::class,
159
+			SimpleTopFilteredPlaceMapper::class
160
+		];
161
+	}
162
+
163
+	/**
164
+	 * {@inheritDoc}
165
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
166
+	 */
167
+	public function listGeoAnalyses(): array
168
+	{
169
+		return [
170
+			AllEventsByCenturyGeoAnalysis::class,
171
+			AllEventsByTypeGeoAnalysis::class
172
+		];
173
+	}
174 174
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/PlaceMappers/CoordinatesPlaceMapper.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -35,174 +35,174 @@
 block discarded – undo
35 35
  */
36 36
 class CoordinatesPlaceMapper implements PlaceMapperInterface
37 37
 {
38
-    use PlaceMapperTrait;
38
+	use PlaceMapperTrait;
39 39
 
40
-    private ?string $cache_key = null;
40
+	private ?string $cache_key = null;
41 41
 
42
-    /**
43
-     * {@inheritDoc}
44
-     *
45
-     * {@internal The Place is associated to a Point only.
46
-     * PlaceLocation can calculate a BoundingBox.
47
-     * Using a BoundingBox could make the mapping more complex and potentially arbitary.
48
-     * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents.
49
-     * This could create the unwanted side effect of a very large area to consider}
50
-     *
51
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
52
-     */
53
-    public function map(Place $place, string $feature_property): ?string
54
-    {
55
-        $location = new PlaceLocation($place->gedcomName());
56
-        $longitude = $location->longitude();
57
-        $latitude = $location->latitude();
58
-        if ($longitude === null || $latitude === null) {
59
-            return null;
60
-        }
42
+	/**
43
+	 * {@inheritDoc}
44
+	 *
45
+	 * {@internal The Place is associated to a Point only.
46
+	 * PlaceLocation can calculate a BoundingBox.
47
+	 * Using a BoundingBox could make the mapping more complex and potentially arbitary.
48
+	 * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents.
49
+	 * This could create the unwanted side effect of a very large area to consider}
50
+	 *
51
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
52
+	 */
53
+	public function map(Place $place, string $feature_property): ?string
54
+	{
55
+		$location = new PlaceLocation($place->gedcomName());
56
+		$longitude = $location->longitude();
57
+		$latitude = $location->latitude();
58
+		if ($longitude === null || $latitude === null) {
59
+			return null;
60
+		}
61 61
 
62
-        $features_index = $this->featuresIndex();
63
-        if ($features_index === null) {
64
-            return null;
65
-        }
62
+		$features_index = $this->featuresIndex();
63
+		if ($features_index === null) {
64
+			return null;
65
+		}
66 66
 
67
-        $place_point = Point::xy($longitude, $latitude, $features_index['SRID']);
68
-        $grid_box = $this->getGridCell(
69
-            $place_point,
70
-            $features_index['map_NE'],
71
-            $features_index['map_SW'],
72
-            $features_index['nb_columns']
73
-        );
74
-        if ($grid_box === null || !$this->setGeometryEngine()) {
75
-            return null;
76
-        }
77
-        $features = $features_index['grid'][$grid_box[0]][$grid_box[1]];
78
-        foreach ($features as $feature) {
79
-            $geometry = $feature->getGeometry();
80
-            if ($place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) {
81
-                return $feature->getProperty($feature_property);
82
-            }
83
-        }
84
-        return null;
85
-    }
67
+		$place_point = Point::xy($longitude, $latitude, $features_index['SRID']);
68
+		$grid_box = $this->getGridCell(
69
+			$place_point,
70
+			$features_index['map_NE'],
71
+			$features_index['map_SW'],
72
+			$features_index['nb_columns']
73
+		);
74
+		if ($grid_box === null || !$this->setGeometryEngine()) {
75
+			return null;
76
+		}
77
+		$features = $features_index['grid'][$grid_box[0]][$grid_box[1]];
78
+		foreach ($features as $feature) {
79
+			$geometry = $feature->getGeometry();
80
+			if ($place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) {
81
+				return $feature->getProperty($feature_property);
82
+			}
83
+		}
84
+		return null;
85
+	}
86 86
 
87
-    /**
88
-     * Return the XY coordinates in a bounded grid of the cell containing a specific point.
89
-     *
90
-     * @param Point $point Point to find
91
-     * @param Point $grid_NE North-East point of the bounded grid
92
-     * @param Point $grid_SW South-West point fo the bounded grid
93
-     * @param int $grid_columns Number of columns/rows in the grid
94
-     * @return array|NULL
95
-     */
96
-    protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array
97
-    {
98
-        list($x, $y) = $point->toArray();
99
-        list($x_max, $y_max) = $grid_NE->toArray();
100
-        list($x_min, $y_min) = $grid_SW->toArray();
87
+	/**
88
+	 * Return the XY coordinates in a bounded grid of the cell containing a specific point.
89
+	 *
90
+	 * @param Point $point Point to find
91
+	 * @param Point $grid_NE North-East point of the bounded grid
92
+	 * @param Point $grid_SW South-West point fo the bounded grid
93
+	 * @param int $grid_columns Number of columns/rows in the grid
94
+	 * @return array|NULL
95
+	 */
96
+	protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array
97
+	{
98
+		list($x, $y) = $point->toArray();
99
+		list($x_max, $y_max) = $grid_NE->toArray();
100
+		list($x_min, $y_min) = $grid_SW->toArray();
101 101
 
102
-        $x_step = ($x_max - $x_min) / $grid_columns;
103
-        $y_step = ($y_max - $y_min) / $grid_columns;
102
+		$x_step = ($x_max - $x_min) / $grid_columns;
103
+		$y_step = ($y_max - $y_min) / $grid_columns;
104 104
 
105
-        if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) {
106
-            return [
107
-                $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step),
108
-                $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step)
109
-            ];
110
-        }
111
-        return null;
112
-    }
105
+		if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) {
106
+			return [
107
+				$x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step),
108
+				$y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step)
109
+			];
110
+		}
111
+		return null;
112
+	}
113 113
 
114
-    /**
115
-     * Get an indexed array of the features of the map.
116
-     *
117
-     * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell.
118
-     * The grid is computed once for each map, and cached.}
119
-     *
120
-     * @return array|NULL
121
-     */
122
-    protected function featuresIndex(): ?array
123
-    {
124
-        $cacheKey = $this->cacheKey();
125
-        if ($cacheKey === null) {
126
-            return null;
127
-        }
128
-        return Registry::cache()->array()->remember($cacheKey, function (): ?array {
129
-            $map_def = $this->data('map');
130
-            if (
131
-                !$this->setGeometryEngine()
132
-                || $map_def === null
133
-                || !($map_def instanceof MapDefinitionInterface)
134
-            ) {
135
-                return null;
136
-            }
137
-            $bounding_boxes = [];
138
-            $map_bounding_box = new BoundingBox();
139
-            $srid = 0;
140
-            foreach ($map_def->features() as $feature) {
141
-                $geometry = $feature->getGeometry();
142
-                if ($geometry === null) {
143
-                    continue;
144
-                }
145
-                $srid = $geometry->SRID();
146
-                $bounding_box = $geometry->getBoundingBox();
147
-                $bounding_boxes[] = [$feature, $bounding_box];
148
-                $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box);
149
-            }
150
-            $grid_columns = count($bounding_boxes);
151
-            $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, []));
152
-            $map_NE = $map_bounding_box->getNorthEast();
153
-            $map_SW = $map_bounding_box->getSouthWest();
154
-            foreach ($bounding_boxes as $item) {
155
-                $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1];
156
-                $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0];
157
-                for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) {
158
-                    for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) {
159
-                        $grid[$i][$j][] = $item[0];
160
-                    }
161
-                }
162
-            }
163
-            return [
164
-                'grid'          =>  $grid,
165
-                'nb_columns'    =>  $grid_columns,
166
-                'map_NE'        =>  $map_NE,
167
-                'map_SW'        =>  $map_SW,
168
-                'SRID'          =>  $srid
169
-            ];
170
-        });
171
-    }
114
+	/**
115
+	 * Get an indexed array of the features of the map.
116
+	 *
117
+	 * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell.
118
+	 * The grid is computed once for each map, and cached.}
119
+	 *
120
+	 * @return array|NULL
121
+	 */
122
+	protected function featuresIndex(): ?array
123
+	{
124
+		$cacheKey = $this->cacheKey();
125
+		if ($cacheKey === null) {
126
+			return null;
127
+		}
128
+		return Registry::cache()->array()->remember($cacheKey, function (): ?array {
129
+			$map_def = $this->data('map');
130
+			if (
131
+				!$this->setGeometryEngine()
132
+				|| $map_def === null
133
+				|| !($map_def instanceof MapDefinitionInterface)
134
+			) {
135
+				return null;
136
+			}
137
+			$bounding_boxes = [];
138
+			$map_bounding_box = new BoundingBox();
139
+			$srid = 0;
140
+			foreach ($map_def->features() as $feature) {
141
+				$geometry = $feature->getGeometry();
142
+				if ($geometry === null) {
143
+					continue;
144
+				}
145
+				$srid = $geometry->SRID();
146
+				$bounding_box = $geometry->getBoundingBox();
147
+				$bounding_boxes[] = [$feature, $bounding_box];
148
+				$map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box);
149
+			}
150
+			$grid_columns = count($bounding_boxes);
151
+			$grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, []));
152
+			$map_NE = $map_bounding_box->getNorthEast();
153
+			$map_SW = $map_bounding_box->getSouthWest();
154
+			foreach ($bounding_boxes as $item) {
155
+				$grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1];
156
+				$grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0];
157
+				for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) {
158
+					for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) {
159
+						$grid[$i][$j][] = $item[0];
160
+					}
161
+				}
162
+			}
163
+			return [
164
+				'grid'          =>  $grid,
165
+				'nb_columns'    =>  $grid_columns,
166
+				'map_NE'        =>  $map_NE,
167
+				'map_SW'        =>  $map_SW,
168
+				'SRID'          =>  $srid
169
+			];
170
+		});
171
+	}
172 172
 
173
-    /**
174
-     * Set the Brick Geo Engine to use the database for geospatial computations.
175
-     * The engine is set only if it has not been set beforehand.
176
-     *
177
-     * @return bool
178
-     */
179
-    protected function setGeometryEngine(): bool
180
-    {
181
-        try {
182
-            if (!GeometryEngineRegistry::has()) {
183
-                GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo()));
184
-            }
185
-            $point = Point::xy(1, 1);
186
-            return $point->equals($point);
187
-        } catch (Throwable $ex) {
188
-        }
189
-        return false;
190
-    }
173
+	/**
174
+	 * Set the Brick Geo Engine to use the database for geospatial computations.
175
+	 * The engine is set only if it has not been set beforehand.
176
+	 *
177
+	 * @return bool
178
+	 */
179
+	protected function setGeometryEngine(): bool
180
+	{
181
+		try {
182
+			if (!GeometryEngineRegistry::has()) {
183
+				GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo()));
184
+			}
185
+			$point = Point::xy(1, 1);
186
+			return $point->equals($point);
187
+		} catch (Throwable $ex) {
188
+		}
189
+		return false;
190
+	}
191 191
 
192
-    /**
193
-     * Get the key to cache the indexed grid of features.
194
-     *
195
-     * @return string|NULL
196
-     */
197
-    protected function cacheKey(): ?string
198
-    {
199
-        if ($this->cache_key === null) {
200
-            $map_def = $this->data('map');
201
-            if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) {
202
-                return null;
203
-            }
204
-            return spl_object_id($this) . '-map-' . $map_def->id();
205
-        }
206
-        return $this->cache_key;
207
-    }
192
+	/**
193
+	 * Get the key to cache the indexed grid of features.
194
+	 *
195
+	 * @return string|NULL
196
+	 */
197
+	protected function cacheKey(): ?string
198
+	{
199
+		if ($this->cache_key === null) {
200
+			$map_def = $this->data('map');
201
+			if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) {
202
+				return null;
203
+			}
204
+			return spl_object_id($this) . '-map-' . $map_def->id();
205
+		}
206
+		return $this->cache_key;
207
+	}
208 208
 }
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/PlaceMappers/SimpleTopFilteredPlaceMapper.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -25,22 +25,22 @@
 block discarded – undo
25 25
  */
26 26
 class SimpleTopFilteredPlaceMapper extends SimplePlaceMapper implements PlaceMapperInterface
27 27
 {
28
-    use TopFilteredPlaceMapperTrait;
28
+	use TopFilteredPlaceMapperTrait;
29 29
 
30
-    public function boot(): void
31
-    {
32
-        parent::boot();
33
-        $top_places = $this->config()->get('topPlaces');
34
-        if (is_array($top_places)) {
35
-            $this->setTopPlaces($top_places);
36
-        }
37
-    }
30
+	public function boot(): void
31
+	{
32
+		parent::boot();
33
+		$top_places = $this->config()->get('topPlaces');
34
+		if (is_array($top_places)) {
35
+			$this->setTopPlaces($top_places);
36
+		}
37
+	}
38 38
 
39
-    public function map(Place $place, string $feature_property): ?string
40
-    {
41
-        if (!$this->belongsToTopLevels($place)) {
42
-            return null;
43
-        }
44
-        return parent::map($place, $feature_property);
45
-    }
39
+	public function map(Place $place, string $feature_property): ?string
40
+	{
41
+		if (!$this->belongsToTopLevels($place)) {
42
+			return null;
43
+		}
44
+		return parent::map($place, $feature_property);
45
+	}
46 46
 }
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/PlaceMappers/TopFilteredPlaceMapperTrait.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -21,65 +21,65 @@
 block discarded – undo
21 21
  */
22 22
 trait TopFilteredPlaceMapperTrait
23 23
 {
24
-    /**
25
-     * @var Place[] $top_places
26
-     */
27
-    private array $top_places = [];
24
+	/**
25
+	 * @var Place[] $top_places
26
+	 */
27
+	private array $top_places = [];
28 28
 
29
-    /**
30
-     * Get the list of top level places.
31
-     *
32
-     * @return Place[]
33
-     */
34
-    public function topPlaces(): array
35
-    {
36
-        return $this->top_places;
37
-    }
29
+	/**
30
+	 * Get the list of top level places.
31
+	 *
32
+	 * @return Place[]
33
+	 */
34
+	public function topPlaces(): array
35
+	{
36
+		return $this->top_places;
37
+	}
38 38
 
39
-    /**
40
-     * Set the list of defined top level places.
41
-     *
42
-     * @param array $top_places
43
-     */
44
-    public function setTopPlaces(array $top_places): void
45
-    {
46
-        $this->top_places = collect($top_places)
47
-            ->filter(
48
-                /** @psalm-suppress MissingClosureParamType */
49
-                fn($top_places) => $top_places instanceof Place
50
-            )->toArray();
51
-    }
39
+	/**
40
+	 * Set the list of defined top level places.
41
+	 *
42
+	 * @param array $top_places
43
+	 */
44
+	public function setTopPlaces(array $top_places): void
45
+	{
46
+		$this->top_places = collect($top_places)
47
+			->filter(
48
+				/** @psalm-suppress MissingClosureParamType */
49
+				fn($top_places) => $top_places instanceof Place
50
+			)->toArray();
51
+	}
52 52
 
53
-    /**
54
-     * Check whether a string ($haystack) ends with another string ($needle)
55
-     *
56
-     * {@internal This is redundant with the function str_ends_with in PHP8}
57
-     *
58
-     * @param string $haystack
59
-     * @param string $needle
60
-     * @return bool
61
-     */
62
-    private function endsWith(string $haystack, string $needle): bool
63
-    {
64
-        return substr_compare($haystack, $needle, -strlen($needle)) === 0;
65
-    }
53
+	/**
54
+	 * Check whether a string ($haystack) ends with another string ($needle)
55
+	 *
56
+	 * {@internal This is redundant with the function str_ends_with in PHP8}
57
+	 *
58
+	 * @param string $haystack
59
+	 * @param string $needle
60
+	 * @return bool
61
+	 */
62
+	private function endsWith(string $haystack, string $needle): bool
63
+	{
64
+		return substr_compare($haystack, $needle, -strlen($needle)) === 0;
65
+	}
66 66
 
67
-    /**
68
-     * Check whether a Place belongs to one of the defined top places.
69
-     *
70
-     * @param Place $place
71
-     * @return bool
72
-     */
73
-    protected function belongsToTopLevels(Place $place): bool
74
-    {
75
-        foreach ($this->top_places as $top_place) {
76
-            if (
77
-                $top_place->tree()->id() === $place->tree()->id() &&
78
-                $this->endsWith($place->gedcomName(), $top_place->gedcomName())
79
-            ) {
80
-                    return true;
81
-            }
82
-        }
83
-        return false;
84
-    }
67
+	/**
68
+	 * Check whether a Place belongs to one of the defined top places.
69
+	 *
70
+	 * @param Place $place
71
+	 * @return bool
72
+	 */
73
+	protected function belongsToTopLevels(Place $place): bool
74
+	{
75
+		foreach ($this->top_places as $top_place) {
76
+			if (
77
+				$top_place->tree()->id() === $place->tree()->id() &&
78
+				$this->endsWith($place->gedcomName(), $top_place->gedcomName())
79
+			) {
80
+					return true;
81
+			}
82
+		}
83
+		return false;
84
+	}
85 85
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/PlaceMappers/SimplePlaceMapper.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@
 block discarded – undo
23 23
  */
24 24
 class SimplePlaceMapper implements PlaceMapperInterface
25 25
 {
26
-    use PlaceMapperTrait;
26
+	use PlaceMapperTrait;
27 27
 
28
-    /**
29
-     * {@inheritDoc}
30
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
31
-     */
32
-    public function map(Place $place, string $feature_property): ?string
33
-    {
34
-        return $place->firstParts(1)->first();
35
-    }
28
+	/**
29
+	 * {@inheritDoc}
30
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
31
+	 */
32
+	public function map(Place $place, string $feature_property): ?string
33
+	{
34
+		return $place->firstParts(1)->first();
35
+	}
36 36
 }
Please login to merge, or discard this patch.