Passed
Push — main ( f9aaf7...4197a4 )
by Jonathan
14:34
created
app/Module/GeoDispersion/Views/GeoAnalysisTable.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -21,51 +21,51 @@
 block discarded – undo
21 21
 
22 22
 class GeoAnalysisTable extends AbstractGeoAnalysisView
23 23
 {
24
-    /**
25
-     * {@inheritDoc}
26
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::type()
27
-     */
28
-    public function type(): string
29
-    {
30
-        return I18N::translateContext('GEODISPERSION', 'Table');
31
-    }
24
+	/**
25
+	 * {@inheritDoc}
26
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::type()
27
+	 */
28
+	public function type(): string
29
+	{
30
+		return I18N::translateContext('GEODISPERSION', 'Table');
31
+	}
32 32
 
33
-    /**
34
-     * {@inheritDoc}
35
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon()
36
-     */
37
-    public function icon(ModuleInterface $module): string
38
-    {
39
-        return view($module->name() . '::icons/view-table', ['type' => $this->type()]);
40
-    }
33
+	/**
34
+	 * {@inheritDoc}
35
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon()
36
+	 */
37
+	public function icon(ModuleInterface $module): string
38
+	{
39
+		return view($module->name() . '::icons/view-table', ['type' => $this->type()]);
40
+	}
41 41
 
42
-    /**
43
-     * {@inheritDoc}
44
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent()
45
-     */
46
-    public function globalSettingsContent(ModuleInterface $module): string
47
-    {
48
-        return '';
49
-    }
42
+	/**
43
+	 * {@inheritDoc}
44
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent()
45
+	 */
46
+	public function globalSettingsContent(ModuleInterface $module): string
47
+	{
48
+		return '';
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritDoc}
53
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate()
54
-     * @return $this
55
-     */
56
-    public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
57
-    {
58
-        return $this;
59
-    }
51
+	/**
52
+	 * {@inheritDoc}
53
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate()
54
+	 * @return $this
55
+	 */
56
+	public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
57
+	{
58
+		return $this;
59
+	}
60 60
 
61
-    /**
62
-     * {@inheritDoc}
63
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent()
64
-     */
65
-    public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
66
-    {
67
-        return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [
68
-            'result'    =>  $result
69
-        ]);
70
-    }
61
+	/**
62
+	 * {@inheritDoc}
63
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent()
64
+	 */
65
+	public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
66
+	{
67
+		return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [
68
+			'result'    =>  $result
69
+		]);
70
+	}
71 71
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function icon(ModuleInterface $module): string
38 38
     {
39
-        return view($module->name() . '::icons/view-table', ['type' => $this->type()]);
39
+        return view($module->name().'::icons/view-table', ['type' => $this->type()]);
40 40
     }
41 41
 
42 42
     /**
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
65 65
     {
66
-        return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [
66
+        return view($module->name().'::geoanalysisview-tab-glb-table', $params + [
67 67
             'result'    =>  $result
68 68
         ]);
69 69
     }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Views/GeoAnalysisMap.php 2 patches
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -29,128 +29,128 @@
 block discarded – undo
29 29
  */
30 30
 class GeoAnalysisMap extends AbstractGeoAnalysisView
31 31
 {
32
-    private ?MapColorsConfig $colors_config = null;
33
-
34
-    public function type(): string
35
-    {
36
-        return I18N::translateContext('GEODISPERSION', 'Map');
37
-    }
38
-
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon()
42
-     */
43
-    public function icon(ModuleInterface $module): string
44
-    {
45
-        return view($module->name() . '::icons/view-map', ['type' => $this->type()]);
46
-    }
47
-
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent()
51
-     */
52
-    public function globalSettingsContent(ModuleInterface $module): string
53
-    {
54
-        return view($module->name() . '::admin/view-edit-map', [
55
-            'module_name'   =>  $module->name(),
56
-            'view'          =>  $this,
57
-            'colors'        =>  $this->colors(),
58
-            'map_adapters'  =>  app(MapAdapterDataService::class)->allForView($this, true)
59
-        ]);
60
-    }
61
-
62
-    /**
63
-     * {@inheritDoc}
64
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate()
65
-     * @return static
66
-     */
67
-    public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
68
-    {
69
-        $params = (array) $request->getParsedBody();
70
-
71
-        $default_color  = $params['view_map_color_default'] ?? '';
72
-        $stroke_color   = $params['view_map_color_stroke'] ?? '';
73
-        $maxvalue_color  = $params['view_map_color_maxvalue'] ?? '';
74
-        $hover_color  = $params['view_map_color_hover'] ?? '';
75
-
76
-        try {
77
-            return $this->withColors(new MapColorsConfig(
78
-                Hex::fromString($default_color),
79
-                Hex::fromString($stroke_color),
80
-                Hex::fromString($maxvalue_color),
81
-                Hex::fromString($hover_color)
82
-            ));
83
-        } catch (InvalidColorValue $ex) {
84
-        }
85
-
86
-        return $this;
87
-    }
88
-
89
-    /**
90
-     * {@inheritDoc}
91
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent()
92
-     */
93
-    public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
94
-    {
95
-        $map_adapters = app(MapAdapterDataService::class)->allForView($this);
96
-
97
-        $adapter_result = null;
98
-        foreach ($map_adapters as $map_adapter) {
99
-            $adapter_result_tmp = $map_adapter->convert($result);
100
-            $adapter_result = $adapter_result === null ?
101
-                $adapter_result_tmp :
102
-                $adapter_result->merge($adapter_result_tmp);
103
-        }
104
-
105
-        if ($adapter_result === null) {
106
-            return view($module->name() . '::errors/tab-error', [
107
-                'message'   =>  I18N::translate('The map could not be loaded.'),
108
-            ]);
109
-        }
110
-
111
-        //phpcs:disable Generic.Files.LineLength.TooLong
112
-        $basemap_provider = [
113
-            'url'    => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
114
-            'options' => [
115
-                'attribution' => '<a href="https://www.openstreetmap.org/copyright">&copy; OpenStreetMap</a> contributors',
116
-                'max_zoom'    => 19
117
-            ]
118
-        ];
119
-        //phpcs:enable
120
-
121
-        return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [
122
-            'result'            =>  $adapter_result->geoAnalysisResult(),
123
-            'features'          =>  $adapter_result->features(),
124
-            'colors'            =>  $this->colors(),
125
-            'basemap_provider'  =>  $basemap_provider
126
-        ]);
127
-    }
128
-
129
-    /**
130
-     * Get the color scheme configuration for the map view
131
-     *
132
-     * @return MapColorsConfig
133
-     */
134
-    public function colors(): MapColorsConfig
135
-    {
136
-        return $this->colors_config ?? new MapColorsConfig(
137
-            new Rgb(245, 245, 245),
138
-            new Rgb(213, 213, 213),
139
-            new Rgb(4, 147, 171),
140
-            new Rgb(255, 102, 0)
141
-        );
142
-    }
143
-
144
-    /**
145
-     * Returns a map view with a new color scheme configuration
146
-     *
147
-     * @param MapColorsConfig $config
148
-     * @return static
149
-     */
150
-    public function withColors(?MapColorsConfig $config): self
151
-    {
152
-        $new = clone $this;
153
-        $new->colors_config = $config;
154
-        return $new;
155
-    }
32
+	private ?MapColorsConfig $colors_config = null;
33
+
34
+	public function type(): string
35
+	{
36
+		return I18N::translateContext('GEODISPERSION', 'Map');
37
+	}
38
+
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon()
42
+	 */
43
+	public function icon(ModuleInterface $module): string
44
+	{
45
+		return view($module->name() . '::icons/view-map', ['type' => $this->type()]);
46
+	}
47
+
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent()
51
+	 */
52
+	public function globalSettingsContent(ModuleInterface $module): string
53
+	{
54
+		return view($module->name() . '::admin/view-edit-map', [
55
+			'module_name'   =>  $module->name(),
56
+			'view'          =>  $this,
57
+			'colors'        =>  $this->colors(),
58
+			'map_adapters'  =>  app(MapAdapterDataService::class)->allForView($this, true)
59
+		]);
60
+	}
61
+
62
+	/**
63
+	 * {@inheritDoc}
64
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate()
65
+	 * @return static
66
+	 */
67
+	public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
68
+	{
69
+		$params = (array) $request->getParsedBody();
70
+
71
+		$default_color  = $params['view_map_color_default'] ?? '';
72
+		$stroke_color   = $params['view_map_color_stroke'] ?? '';
73
+		$maxvalue_color  = $params['view_map_color_maxvalue'] ?? '';
74
+		$hover_color  = $params['view_map_color_hover'] ?? '';
75
+
76
+		try {
77
+			return $this->withColors(new MapColorsConfig(
78
+				Hex::fromString($default_color),
79
+				Hex::fromString($stroke_color),
80
+				Hex::fromString($maxvalue_color),
81
+				Hex::fromString($hover_color)
82
+			));
83
+		} catch (InvalidColorValue $ex) {
84
+		}
85
+
86
+		return $this;
87
+	}
88
+
89
+	/**
90
+	 * {@inheritDoc}
91
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent()
92
+	 */
93
+	public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
94
+	{
95
+		$map_adapters = app(MapAdapterDataService::class)->allForView($this);
96
+
97
+		$adapter_result = null;
98
+		foreach ($map_adapters as $map_adapter) {
99
+			$adapter_result_tmp = $map_adapter->convert($result);
100
+			$adapter_result = $adapter_result === null ?
101
+				$adapter_result_tmp :
102
+				$adapter_result->merge($adapter_result_tmp);
103
+		}
104
+
105
+		if ($adapter_result === null) {
106
+			return view($module->name() . '::errors/tab-error', [
107
+				'message'   =>  I18N::translate('The map could not be loaded.'),
108
+			]);
109
+		}
110
+
111
+		//phpcs:disable Generic.Files.LineLength.TooLong
112
+		$basemap_provider = [
113
+			'url'    => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
114
+			'options' => [
115
+				'attribution' => '<a href="https://www.openstreetmap.org/copyright">&copy; OpenStreetMap</a> contributors',
116
+				'max_zoom'    => 19
117
+			]
118
+		];
119
+		//phpcs:enable
120
+
121
+		return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [
122
+			'result'            =>  $adapter_result->geoAnalysisResult(),
123
+			'features'          =>  $adapter_result->features(),
124
+			'colors'            =>  $this->colors(),
125
+			'basemap_provider'  =>  $basemap_provider
126
+		]);
127
+	}
128
+
129
+	/**
130
+	 * Get the color scheme configuration for the map view
131
+	 *
132
+	 * @return MapColorsConfig
133
+	 */
134
+	public function colors(): MapColorsConfig
135
+	{
136
+		return $this->colors_config ?? new MapColorsConfig(
137
+			new Rgb(245, 245, 245),
138
+			new Rgb(213, 213, 213),
139
+			new Rgb(4, 147, 171),
140
+			new Rgb(255, 102, 0)
141
+		);
142
+	}
143
+
144
+	/**
145
+	 * Returns a map view with a new color scheme configuration
146
+	 *
147
+	 * @param MapColorsConfig $config
148
+	 * @return static
149
+	 */
150
+	public function withColors(?MapColorsConfig $config): self
151
+	{
152
+		$new = clone $this;
153
+		$new->colors_config = $config;
154
+		return $new;
155
+	}
156 156
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -9 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function icon(ModuleInterface $module): string
44 44
     {
45
-        return view($module->name() . '::icons/view-map', ['type' => $this->type()]);
45
+        return view($module->name().'::icons/view-map', ['type' => $this->type()]);
46 46
     }
47 47
 
48 48
     /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function globalSettingsContent(ModuleInterface $module): string
53 53
     {
54
-        return view($module->name() . '::admin/view-edit-map', [
54
+        return view($module->name().'::admin/view-edit-map', [
55 55
             'module_name'   =>  $module->name(),
56 56
             'view'          =>  $this,
57 57
             'colors'        =>  $this->colors(),
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
67 67
     {
68
-        $params = (array) $request->getParsedBody();
68
+        $params = (array)$request->getParsedBody();
69 69
 
70 70
         $default_color  = $params['view_map_color_default'] ?? '';
71 71
         $stroke_color   = $params['view_map_color_stroke'] ?? '';
72
-        $maxvalue_color  = $params['view_map_color_maxvalue'] ?? '';
73
-        $hover_color  = $params['view_map_color_hover'] ?? '';
72
+        $maxvalue_color = $params['view_map_color_maxvalue'] ?? '';
73
+        $hover_color = $params['view_map_color_hover'] ?? '';
74 74
 
75 75
         try {
76 76
             return $this->withColors(new MapColorsConfig(
@@ -97,12 +97,11 @@  discard block
 block discarded – undo
97 97
         foreach ($map_adapters as $map_adapter) {
98 98
             $adapter_result_tmp = $map_adapter->convert($result);
99 99
             $adapter_result = $adapter_result === null ?
100
-                $adapter_result_tmp :
101
-                $adapter_result->merge($adapter_result_tmp);
100
+                $adapter_result_tmp : $adapter_result->merge($adapter_result_tmp);
102 101
         }
103 102
 
104 103
         if ($adapter_result === null) {
105
-            return view($module->name() . '::errors/tab-error', [
104
+            return view($module->name().'::errors/tab-error', [
106 105
                 'message'   =>  I18N::translate('The map could not be loaded.'),
107 106
             ]);
108 107
         }
@@ -117,7 +116,7 @@  discard block
 block discarded – undo
117 116
         ];
118 117
         //phpcs:enable
119 118
 
120
-        return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [
119
+        return view($module->name().'::geoanalysisview-tab-glb-map', $params + [
121 120
             'result'            =>  $adapter_result->geoAnalysisResult(),
122 121
             'features'          =>  $adapter_result->features(),
123 122
             'colors'            =>  $this->colors(),
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Schema/Migration1.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -24,35 +24,35 @@
 block discarded – undo
24 24
 class Migration1 implements MigrationInterface
25 25
 {
26 26
 
27
-    /**
28
-     * {@inheritDoc}
29
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
30
-     */
31
-    public function upgrade(): void
32
-    {
33
-        DB::schema()->create('maj_geodisp_views', static function (Blueprint $table): void {
34
-            $table->integer('majgv_id')->autoIncrement();
35
-            $table->integer('majgv_gedcom_id')->index();
36
-            $table->string('majgv_view_class', 255);
37
-            $table->enum('majgv_status', ['enabled', 'disabled'])->default('enabled');
38
-            $table->string('majgv_descr', 248);
39
-            $table->string('majgv_analysis', 255);
40
-            $table->tinyInteger('majgv_place_depth')->default(1);
41
-            $table->tinyInteger('majgv_top_places')->default(0);
42
-            $table->json('majgv_colors')->nullable();
43
-
44
-            $table->foreign('majgv_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade');
45
-        });
46
-
47
-        DB::schema()->create('maj_geodisp_mapviews', static function (Blueprint $table): void {
48
-            $table->integer('majgm_id')->autoIncrement();
49
-            $table->integer('majgm_majgv_id')->index();
50
-            $table->string('majgm_map_id', 127);
51
-            $table->string('majgm_mapper', 255);
52
-            $table->string('majgm_feature_prop', 31);
53
-            $table->json('majgm_config')->nullable();
54
-
55
-            $table->foreign('majgm_majgv_id')->references('majgv_id')->on('maj_geodisp_views')->onDelete('cascade');
56
-        });
57
-    }
27
+	/**
28
+	 * {@inheritDoc}
29
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
30
+	 */
31
+	public function upgrade(): void
32
+	{
33
+		DB::schema()->create('maj_geodisp_views', static function (Blueprint $table): void {
34
+			$table->integer('majgv_id')->autoIncrement();
35
+			$table->integer('majgv_gedcom_id')->index();
36
+			$table->string('majgv_view_class', 255);
37
+			$table->enum('majgv_status', ['enabled', 'disabled'])->default('enabled');
38
+			$table->string('majgv_descr', 248);
39
+			$table->string('majgv_analysis', 255);
40
+			$table->tinyInteger('majgv_place_depth')->default(1);
41
+			$table->tinyInteger('majgv_top_places')->default(0);
42
+			$table->json('majgv_colors')->nullable();
43
+
44
+			$table->foreign('majgv_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade');
45
+		});
46
+
47
+		DB::schema()->create('maj_geodisp_mapviews', static function (Blueprint $table): void {
48
+			$table->integer('majgm_id')->autoIncrement();
49
+			$table->integer('majgm_majgv_id')->index();
50
+			$table->string('majgm_map_id', 127);
51
+			$table->string('majgm_mapper', 255);
52
+			$table->string('majgm_feature_prop', 31);
53
+			$table->json('majgm_config')->nullable();
54
+
55
+			$table->foreign('majgm_majgv_id')->references('majgv_id')->on('maj_geodisp_views')->onDelete('cascade');
56
+		});
57
+	}
58 58
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      */
31 31
     public function upgrade(): void
32 32
     {
33
-        DB::schema()->create('maj_geodisp_views', static function (Blueprint $table): void {
33
+        DB::schema()->create('maj_geodisp_views', static function(Blueprint $table): void {
34 34
             $table->integer('majgv_id')->autoIncrement();
35 35
             $table->integer('majgv_gedcom_id')->index();
36 36
             $table->string('majgv_view_class', 255);
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             $table->foreign('majgv_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade');
45 45
         });
46 46
 
47
-        DB::schema()->create('maj_geodisp_mapviews', static function (Blueprint $table): void {
47
+        DB::schema()->create('maj_geodisp_mapviews', static function(Blueprint $table): void {
48 48
             $table->integer('majgm_id')->autoIncrement();
49 49
             $table->integer('majgm_majgv_id')->index();
50 50
             $table->string('majgm_map_id', 127);
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Schema/Migration2.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 
92 92
         foreach ($existing_views as $old_view) {
93 93
             try {
94
-                $tree = $tree_service->find((int) $old_view->majgd_file);
94
+                $tree = $tree_service->find((int)$old_view->majgd_file);
95 95
             } catch (RuntimeException $ex) {
96 96
                 continue;
97 97
             }
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
             $old_view->majgd_status === 'enabled',
135 135
             $old_view->majgd_descr,
136 136
             app(SosaByGenerationGeoAnalysis::class),
137
-            (int) $old_view->majgd_sublevel,
138
-            (int) $old_view->majgd_detailsgen
137
+            (int)$old_view->majgd_sublevel,
138
+            (int)$old_view->majgd_detailsgen
139 139
         );
140 140
 
141 141
         return $geoview_data_service->insertGetId($new_view) > 0;
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
             $old_view->majgd_status === 'enabled',
166 166
             $old_view->majgd_descr,
167 167
             app(SosaByGenerationGeoAnalysis::class),
168
-            (int) $old_view->majgd_sublevel,
169
-            (int) $old_view->majgd_detailsgen
168
+            (int)$old_view->majgd_sublevel,
169
+            (int)$old_view->majgd_detailsgen
170 170
         );
171 171
 
172 172
         $view_id = $geoview_data_service->insertGetId($new_view);
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
     private function mapIdsFromOld(string $map_xml): array
204 204
     {
205 205
         $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? [];
206
-        return is_array($mapping) ? $mapping : [ $mapping ];
206
+        return is_array($mapping) ? $mapping : [$mapping];
207 207
     }
208 208
 
209 209
     /**
Please login to merge, or discard this patch.
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -39,213 +39,213 @@
 block discarded – undo
39 39
  */
40 40
 class Migration2 implements MigrationInterface
41 41
 {
42
-    /**
43
-     * Mapping from old map definitions to new ones
44
-     * @var array<string,mixed> MAPS_XML_MAPPING
45
-     */
46
-    private const MAPS_XML_MAPPING = [
47
-        'aubracmargeridebycommunes.xml' =>  'fr-area-aubrac-lot-margeride-planeze-communes',
48
-        'calvadosbycommunes.xml'        =>  'fr-dpt-14-communes',
49
-        'cantalbycommunes.xml'          =>  'fr-dpt-15-communes',
50
-        'cotesdarmorbycommunes.xml'     =>  'fr-dpt-22-communes',
51
-        'essonnebycommunes.xml'         =>  'fr-dpt-91-communes',
52
-        'eurebycommunes.xml'            =>  'fr-dpt-27-communes',
53
-        'eureetloirbycommunes.xml'      =>  'fr-dpt-28-communes',
54
-        'francebydepartements.xml'      =>  'fr-metropole-departements',
55
-        'francebyregions1970.xml'       =>  'fr-metropole-regions-1970',
56
-        'francebyregions2016.xml'       =>  'fr-metropole-regions-2016',
57
-        'hauteloirebycommunes.xml'      =>  'fr-dpt-43-communes',
58
-        'illeetvilainebycommunes.xml'   =>  'fr-dpt-35-communes',
59
-        'loiretbycommunes.xml'          =>  'fr-dpt-45-communes',
60
-        'lozerebycodepostaux.xml'       =>  'fr-dpt-48-codespostaux',
61
-        'lozerebycommunes.xml'          =>  'fr-dpt-48-communes',
62
-        'mayennebycommunes.xml'         =>  'fr-dpt-53-communes',
63
-        'oisebycommunes.xml'            =>  'fr-dpt-60-communes',
64
-        'ornebycommunes.xml'            =>  'fr-dpt-61-communes',
65
-        'puydedomebycommunes.xml'       =>  'fr-dpt-63-communes',
66
-        'sarthebycommunes.xml'          =>  'fr-dpt-72-communes',
67
-        'seinemaritimebycommunes.xml'   =>  'fr-dpt-76-communes',
68
-        'seinesommeoisebycommunes.xml'  =>  ['fr-dpt-60-communes', 'fr-dpt-76-communes', 'fr-dpt-80-communes'],
69
-        'valdoisebycommunes.xml'        =>  'fr-dpt-95-communes',
70
-        'yvelinesbycommunes.xml'        =>  'fr-dpt-78-communes'
71
-    ];
72
-
73
-    /**
74
-     * {@inheritDoc}
75
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
76
-     */
77
-    public function upgrade(): void
78
-    {
79
-        if (!DB::schema()->hasTable('maj_geodispersion')) {
80
-            return;
81
-        }
82
-
83
-        /** @var TreeService $tree_service */
84
-        $tree_service = app(TreeService::class);
85
-        /** @var GeoAnalysisViewDataService $geoview_data_service */
86
-        $geoview_data_service = app(GeoAnalysisViewDataService::class);
87
-
88
-        $existing_views = DB::table('maj_geodispersion')
89
-            ->select()
90
-            ->get();
91
-
92
-        foreach ($existing_views as $old_view) {
93
-            try {
94
-                $tree = $tree_service->find((int) $old_view->majgd_file);
95
-            } catch (RuntimeException $ex) {
96
-                continue;
97
-            }
98
-
99
-            if ($old_view->majgd_map === null) {
100
-                $this->migrateGeoAnalysisTable($old_view, $tree, $geoview_data_service);
101
-            } else {
102
-                DB::connection()->beginTransaction();
103
-                if ($this->migrateGeoAnalysisMap($old_view, $tree, $geoview_data_service)) {
104
-                    DB::connection()->commit();
105
-                } else {
106
-                    DB::connection()->rollBack();
107
-                }
108
-            }
109
-        }
110
-
111
-        DB::schema()->drop('maj_geodispersion');
112
-
113
-        FlashMessages::addMessage(I18N::translate(
114
-            'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.'
115
-        ));
116
-    }
117
-
118
-    /**
119
-     * Create a Table geographical analysis view from a migrated item.
120
-     *
121
-     * @param stdClass $old_view
122
-     * @param Tree $tree
123
-     * @param GeoAnalysisViewDataService $geoview_data_service
124
-     * @return bool
125
-     */
126
-    private function migrateGeoAnalysisTable(
127
-        stdClass $old_view,
128
-        Tree $tree,
129
-        GeoAnalysisViewDataService $geoview_data_service
130
-    ): bool {
131
-        $new_view = new GeoAnalysisTable(
132
-            0,
133
-            $tree,
134
-            $old_view->majgd_status === 'enabled',
135
-            $old_view->majgd_descr,
136
-            app(SosaByGenerationGeoAnalysis::class),
137
-            (int) $old_view->majgd_sublevel,
138
-            (int) $old_view->majgd_detailsgen
139
-        );
140
-
141
-        return $geoview_data_service->insertGetId($new_view) > 0;
142
-    }
143
-
144
-    /**
145
-     * Create a Map geographical analysis view from a migrated item.
146
-     *
147
-     * @param stdClass $old_view
148
-     * @param Tree $tree
149
-     * @param GeoAnalysisViewDataService $geoview_data_service
150
-     * @return bool
151
-     */
152
-    private function migrateGeoAnalysisMap(
153
-        stdClass $old_view,
154
-        Tree $tree,
155
-        GeoAnalysisViewDataService $geoview_data_service
156
-    ): bool {
157
-        /** @var MapDefinitionsService $map_definition_service */
158
-        $map_definition_service = app(MapDefinitionsService::class);
159
-        /** @var MapAdapterDataService $mapadapter_data_service */
160
-        $mapadapter_data_service = app(MapAdapterDataService::class);
161
-
162
-        $new_view = new GeoAnalysisMap(
163
-            0,
164
-            $tree,
165
-            $old_view->majgd_status === 'enabled',
166
-            $old_view->majgd_descr,
167
-            app(SosaByGenerationGeoAnalysis::class),
168
-            (int) $old_view->majgd_sublevel,
169
-            (int) $old_view->majgd_detailsgen
170
-        );
171
-
172
-        $view_id = $geoview_data_service->insertGetId($new_view);
173
-        if ($view_id === 0) {
174
-            return false;
175
-        }
176
-        $new_view = $new_view->withId($view_id);
177
-
178
-        $colors = $new_view->colors();
179
-        foreach ($this->mapIdsFromOld($old_view->majgd_map) as $new_map_id) {
180
-            $map = $map_definition_service->find($new_map_id);
181
-            if ($map === null) {
182
-                return false;
183
-            }
184
-            $colors = $this->colorsFromMap($new_map_id);
185
-
186
-            /** @var SimplePlaceMapper $mapper */
187
-            $mapper = app(SimplePlaceMapper::class);
188
-            $mapview_config = new MapViewConfig($this->mappingPropertyForMap($new_map_id), $mapper->config());
189
-            $map_adapter = new GeoAnalysisMapAdapter(0, $view_id, $map, $mapper, $mapview_config);
190
-
191
-            $mapadapter_data_service->insertGetId($map_adapter);
192
-        }
193
-
194
-        return $geoview_data_service->update($new_view->withColors($colors)) > 0;
195
-    }
196
-
197
-    /**
198
-     * Get all new map definitions IDs representing an old map definition
199
-     *
200
-     * @param string $map_xml
201
-     * @return string[]
202
-     */
203
-    private function mapIdsFromOld(string $map_xml): array
204
-    {
205
-        $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? [];
206
-        return is_array($mapping) ? $mapping : [ $mapping ];
207
-    }
208
-
209
-    /**
210
-     * Get the mapping property to be used for the migrated map adapter
211
-     *
212
-     * @param string $map_id
213
-     * @return string
214
-     */
215
-    private function mappingPropertyForMap(string $map_id): string
216
-    {
217
-        switch ($map_id) {
218
-            case 'fr-metropole-regions-1970':
219
-            case 'fr-metropole-regions-2016':
220
-                return 'region_insee_libelle';
221
-            case 'fr-metropole-departements':
222
-                return 'dpt_insee_libelle';
223
-            case 'fr-dpt-48-codespostaux':
224
-                return 'code_postal';
225
-            default:
226
-                return 'commune_insee_libelle';
227
-        }
228
-    }
229
-
230
-    /**
231
-     * Get the color configuration to be used for the migrated map view
232
-     *
233
-     * @param string $map_id
234
-     * @return MapColorsConfig
235
-     */
236
-    private function colorsFromMap(string $map_id): MapColorsConfig
237
-    {
238
-        $default = Hex::fromString('#f5f5f5');
239
-        $stroke = Hex::fromString('#d5d5d5');
240
-        $hover = Hex::fromString('#ff6600');
241
-
242
-        switch ($map_id) {
243
-            case 'fr-metropole-departements':
244
-                return new MapColorsConfig($default, $stroke, Hex::fromString('#0493ab'), $hover);
245
-            case 'fr-dpt-48-codespostaux':
246
-                return new MapColorsConfig($default, $stroke, Hex::fromString('#44aa00'), $hover);
247
-            default:
248
-                return new MapColorsConfig($default, $stroke, Hex::fromString('#e2a61d'), $hover);
249
-        }
250
-    }
42
+	/**
43
+	 * Mapping from old map definitions to new ones
44
+	 * @var array<string,mixed> MAPS_XML_MAPPING
45
+	 */
46
+	private const MAPS_XML_MAPPING = [
47
+		'aubracmargeridebycommunes.xml' =>  'fr-area-aubrac-lot-margeride-planeze-communes',
48
+		'calvadosbycommunes.xml'        =>  'fr-dpt-14-communes',
49
+		'cantalbycommunes.xml'          =>  'fr-dpt-15-communes',
50
+		'cotesdarmorbycommunes.xml'     =>  'fr-dpt-22-communes',
51
+		'essonnebycommunes.xml'         =>  'fr-dpt-91-communes',
52
+		'eurebycommunes.xml'            =>  'fr-dpt-27-communes',
53
+		'eureetloirbycommunes.xml'      =>  'fr-dpt-28-communes',
54
+		'francebydepartements.xml'      =>  'fr-metropole-departements',
55
+		'francebyregions1970.xml'       =>  'fr-metropole-regions-1970',
56
+		'francebyregions2016.xml'       =>  'fr-metropole-regions-2016',
57
+		'hauteloirebycommunes.xml'      =>  'fr-dpt-43-communes',
58
+		'illeetvilainebycommunes.xml'   =>  'fr-dpt-35-communes',
59
+		'loiretbycommunes.xml'          =>  'fr-dpt-45-communes',
60
+		'lozerebycodepostaux.xml'       =>  'fr-dpt-48-codespostaux',
61
+		'lozerebycommunes.xml'          =>  'fr-dpt-48-communes',
62
+		'mayennebycommunes.xml'         =>  'fr-dpt-53-communes',
63
+		'oisebycommunes.xml'            =>  'fr-dpt-60-communes',
64
+		'ornebycommunes.xml'            =>  'fr-dpt-61-communes',
65
+		'puydedomebycommunes.xml'       =>  'fr-dpt-63-communes',
66
+		'sarthebycommunes.xml'          =>  'fr-dpt-72-communes',
67
+		'seinemaritimebycommunes.xml'   =>  'fr-dpt-76-communes',
68
+		'seinesommeoisebycommunes.xml'  =>  ['fr-dpt-60-communes', 'fr-dpt-76-communes', 'fr-dpt-80-communes'],
69
+		'valdoisebycommunes.xml'        =>  'fr-dpt-95-communes',
70
+		'yvelinesbycommunes.xml'        =>  'fr-dpt-78-communes'
71
+	];
72
+
73
+	/**
74
+	 * {@inheritDoc}
75
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
76
+	 */
77
+	public function upgrade(): void
78
+	{
79
+		if (!DB::schema()->hasTable('maj_geodispersion')) {
80
+			return;
81
+		}
82
+
83
+		/** @var TreeService $tree_service */
84
+		$tree_service = app(TreeService::class);
85
+		/** @var GeoAnalysisViewDataService $geoview_data_service */
86
+		$geoview_data_service = app(GeoAnalysisViewDataService::class);
87
+
88
+		$existing_views = DB::table('maj_geodispersion')
89
+			->select()
90
+			->get();
91
+
92
+		foreach ($existing_views as $old_view) {
93
+			try {
94
+				$tree = $tree_service->find((int) $old_view->majgd_file);
95
+			} catch (RuntimeException $ex) {
96
+				continue;
97
+			}
98
+
99
+			if ($old_view->majgd_map === null) {
100
+				$this->migrateGeoAnalysisTable($old_view, $tree, $geoview_data_service);
101
+			} else {
102
+				DB::connection()->beginTransaction();
103
+				if ($this->migrateGeoAnalysisMap($old_view, $tree, $geoview_data_service)) {
104
+					DB::connection()->commit();
105
+				} else {
106
+					DB::connection()->rollBack();
107
+				}
108
+			}
109
+		}
110
+
111
+		DB::schema()->drop('maj_geodispersion');
112
+
113
+		FlashMessages::addMessage(I18N::translate(
114
+			'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.'
115
+		));
116
+	}
117
+
118
+	/**
119
+	 * Create a Table geographical analysis view from a migrated item.
120
+	 *
121
+	 * @param stdClass $old_view
122
+	 * @param Tree $tree
123
+	 * @param GeoAnalysisViewDataService $geoview_data_service
124
+	 * @return bool
125
+	 */
126
+	private function migrateGeoAnalysisTable(
127
+		stdClass $old_view,
128
+		Tree $tree,
129
+		GeoAnalysisViewDataService $geoview_data_service
130
+	): bool {
131
+		$new_view = new GeoAnalysisTable(
132
+			0,
133
+			$tree,
134
+			$old_view->majgd_status === 'enabled',
135
+			$old_view->majgd_descr,
136
+			app(SosaByGenerationGeoAnalysis::class),
137
+			(int) $old_view->majgd_sublevel,
138
+			(int) $old_view->majgd_detailsgen
139
+		);
140
+
141
+		return $geoview_data_service->insertGetId($new_view) > 0;
142
+	}
143
+
144
+	/**
145
+	 * Create a Map geographical analysis view from a migrated item.
146
+	 *
147
+	 * @param stdClass $old_view
148
+	 * @param Tree $tree
149
+	 * @param GeoAnalysisViewDataService $geoview_data_service
150
+	 * @return bool
151
+	 */
152
+	private function migrateGeoAnalysisMap(
153
+		stdClass $old_view,
154
+		Tree $tree,
155
+		GeoAnalysisViewDataService $geoview_data_service
156
+	): bool {
157
+		/** @var MapDefinitionsService $map_definition_service */
158
+		$map_definition_service = app(MapDefinitionsService::class);
159
+		/** @var MapAdapterDataService $mapadapter_data_service */
160
+		$mapadapter_data_service = app(MapAdapterDataService::class);
161
+
162
+		$new_view = new GeoAnalysisMap(
163
+			0,
164
+			$tree,
165
+			$old_view->majgd_status === 'enabled',
166
+			$old_view->majgd_descr,
167
+			app(SosaByGenerationGeoAnalysis::class),
168
+			(int) $old_view->majgd_sublevel,
169
+			(int) $old_view->majgd_detailsgen
170
+		);
171
+
172
+		$view_id = $geoview_data_service->insertGetId($new_view);
173
+		if ($view_id === 0) {
174
+			return false;
175
+		}
176
+		$new_view = $new_view->withId($view_id);
177
+
178
+		$colors = $new_view->colors();
179
+		foreach ($this->mapIdsFromOld($old_view->majgd_map) as $new_map_id) {
180
+			$map = $map_definition_service->find($new_map_id);
181
+			if ($map === null) {
182
+				return false;
183
+			}
184
+			$colors = $this->colorsFromMap($new_map_id);
185
+
186
+			/** @var SimplePlaceMapper $mapper */
187
+			$mapper = app(SimplePlaceMapper::class);
188
+			$mapview_config = new MapViewConfig($this->mappingPropertyForMap($new_map_id), $mapper->config());
189
+			$map_adapter = new GeoAnalysisMapAdapter(0, $view_id, $map, $mapper, $mapview_config);
190
+
191
+			$mapadapter_data_service->insertGetId($map_adapter);
192
+		}
193
+
194
+		return $geoview_data_service->update($new_view->withColors($colors)) > 0;
195
+	}
196
+
197
+	/**
198
+	 * Get all new map definitions IDs representing an old map definition
199
+	 *
200
+	 * @param string $map_xml
201
+	 * @return string[]
202
+	 */
203
+	private function mapIdsFromOld(string $map_xml): array
204
+	{
205
+		$mapping = self::MAPS_XML_MAPPING[$map_xml] ?? [];
206
+		return is_array($mapping) ? $mapping : [ $mapping ];
207
+	}
208
+
209
+	/**
210
+	 * Get the mapping property to be used for the migrated map adapter
211
+	 *
212
+	 * @param string $map_id
213
+	 * @return string
214
+	 */
215
+	private function mappingPropertyForMap(string $map_id): string
216
+	{
217
+		switch ($map_id) {
218
+			case 'fr-metropole-regions-1970':
219
+			case 'fr-metropole-regions-2016':
220
+				return 'region_insee_libelle';
221
+			case 'fr-metropole-departements':
222
+				return 'dpt_insee_libelle';
223
+			case 'fr-dpt-48-codespostaux':
224
+				return 'code_postal';
225
+			default:
226
+				return 'commune_insee_libelle';
227
+		}
228
+	}
229
+
230
+	/**
231
+	 * Get the color configuration to be used for the migrated map view
232
+	 *
233
+	 * @param string $map_id
234
+	 * @return MapColorsConfig
235
+	 */
236
+	private function colorsFromMap(string $map_id): MapColorsConfig
237
+	{
238
+		$default = Hex::fromString('#f5f5f5');
239
+		$stroke = Hex::fromString('#d5d5d5');
240
+		$hover = Hex::fromString('#ff6600');
241
+
242
+		switch ($map_id) {
243
+			case 'fr-metropole-departements':
244
+				return new MapColorsConfig($default, $stroke, Hex::fromString('#0493ab'), $hover);
245
+			case 'fr-dpt-48-codespostaux':
246
+				return new MapColorsConfig($default, $stroke, Hex::fromString('#44aa00'), $hover);
247
+			default:
248
+				return new MapColorsConfig($default, $stroke, Hex::fromString('#e2a61d'), $hover);
249
+		}
250
+	}
251 251
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Schema/Migration0.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@
 block discarded – undo
22 22
 class Migration0 implements MigrationInterface
23 23
 {
24 24
 
25
-    /**
26
-     * {@inheritDoc}
27
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
28
-     */
29
-    public function upgrade(): void
30
-    {
31
-        // This migration has been superseded by migration 1.
32
-    }
25
+	/**
26
+	 * {@inheritDoc}
27
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
28
+	 */
29
+	public function upgrade(): void
30
+	{
31
+		// This migration has been superseded by migration 1.
32
+	}
33 33
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/MapDefinitionsService.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -25,46 +25,46 @@
 block discarded – undo
25 25
  */
26 26
 class MapDefinitionsService
27 27
 {
28
-    private ModuleService $module_service;
28
+	private ModuleService $module_service;
29 29
 
30
-    /**
31
-     * Constructor for MapDefinitionsService
32
-     *
33
-     * @param ModuleService $module_service
34
-     */
35
-    public function __construct(ModuleService $module_service)
36
-    {
37
-        $this->module_service = $module_service;
38
-    }
30
+	/**
31
+	 * Constructor for MapDefinitionsService
32
+	 *
33
+	 * @param ModuleService $module_service
34
+	 */
35
+	public function __construct(ModuleService $module_service)
36
+	{
37
+		$this->module_service = $module_service;
38
+	}
39 39
 
40
-    /**
41
-     * Find a map definition by ID.
42
-     *
43
-     * @param string $id
44
-     * @return MapDefinitionInterface|NULL
45
-     */
46
-    public function find(string $id): ?MapDefinitionInterface
47
-    {
48
-        return $this->all()->get($id);
49
-    }
40
+	/**
41
+	 * Find a map definition by ID.
42
+	 *
43
+	 * @param string $id
44
+	 * @return MapDefinitionInterface|NULL
45
+	 */
46
+	public function find(string $id): ?MapDefinitionInterface
47
+	{
48
+		return $this->all()->get($id);
49
+	}
50 50
 
51
-    /**
52
-     * Get all map definitions available.
53
-     *
54
-     * {@internal The list is generated based on the modules exposing ModuleMapDefinitionProviderInterface,
55
-     * and the result is cached}
56
-     *
57
-     * @param bool $include_disabled
58
-     * @return Collection<string, MapDefinitionInterface>
59
-     */
60
-    public function all(bool $include_disabled = false): Collection
61
-    {
62
-        return Registry::cache()->array()->remember(
63
-            'maj-geodisp-maps-all',
64
-            fn() => $this->module_service
65
-                ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled)
66
-                ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition())
67
-                ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ])
68
-        );
69
-    }
51
+	/**
52
+	 * Get all map definitions available.
53
+	 *
54
+	 * {@internal The list is generated based on the modules exposing ModuleMapDefinitionProviderInterface,
55
+	 * and the result is cached}
56
+	 *
57
+	 * @param bool $include_disabled
58
+	 * @return Collection<string, MapDefinitionInterface>
59
+	 */
60
+	public function all(bool $include_disabled = false): Collection
61
+	{
62
+		return Registry::cache()->array()->remember(
63
+			'maj-geodisp-maps-all',
64
+			fn() => $this->module_service
65
+				->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled)
66
+				->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition())
67
+				->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ])
68
+		);
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
             fn() => $this->module_service
65 65
                 ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled)
66 66
                 ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition())
67
-                ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ])
67
+                ->mapWithKeys(fn(MapDefinitionInterface $map) => [$map->id() => $map])
68 68
         );
69 69
     }
70 70
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/GeoAnalysisViewDataService.php 2 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -32,186 +32,186 @@
 block discarded – undo
32 32
  */
33 33
 class GeoAnalysisViewDataService
34 34
 {
35
-    /**
36
-     * Find a Geographical dispersion analysis view by ID
37
-     *
38
-     * @param Tree $tree
39
-     * @param int $id
40
-     * @return AbstractGeoAnalysisView|NULL
41
-     */
42
-    public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView
43
-    {
44
-        return $this->all($tree, $include_disabled)
45
-            ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id);
46
-    }
47
-
48
-    /**
49
-     * Get all Geographical dispersion analysis views, with or without the disabled ones.
50
-     *
51
-     * {@internal It would ignore any view for which the class could not be loaded by the container}
52
-     *
53
-     * @param Tree $tree
54
-     * @param bool $include_disabled
55
-     * @return Collection<AbstractGeoAnalysisView>
56
-     */
57
-    public function all(Tree $tree, bool $include_disabled = false): Collection
58
-    {
59
-        return Registry::cache()->array()->remember(
60
-            'all-geodispersion-views',
61
-            function () use ($tree, $include_disabled): Collection {
62
-                return DB::table('maj_geodisp_views')
63
-                    ->select('maj_geodisp_views.*')
64
-                    ->where('majgv_gedcom_id', '=', $tree->id())
65
-                    ->get()
66
-                    ->map($this->viewMapper($tree))
67
-                    ->filter()
68
-                    ->filter($this->enabledFilter($include_disabled));
69
-            }
70
-        );
71
-    }
72
-
73
-    /**
74
-     * Insert a geographical dispersion analysis view object in the database.
75
-     *
76
-     * @param AbstractGeoAnalysisView $view
77
-     * @return int
78
-     */
79
-    public function insertGetId(AbstractGeoAnalysisView $view): int
80
-    {
81
-        return DB::table('maj_geodisp_views')
82
-            ->insertGetId([
83
-                'majgv_gedcom_id' => $view->tree()->id(),
84
-                'majgv_view_class' => get_class($view),
85
-                'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled',
86
-                'majgv_descr' => mb_substr($view->description(), 0, 248),
87
-                'majgv_analysis' => get_class($view->analysis()),
88
-                'majgv_place_depth' => $view->placesDepth()
89
-            ]);
90
-    }
91
-
92
-    /**
93
-     * Update a geographical dispersion analysis view object in the database.
94
-     *
95
-     * @param AbstractGeoAnalysisView $view
96
-     * @return int
97
-     */
98
-    public function update(AbstractGeoAnalysisView $view): int
99
-    {
100
-        return DB::table('maj_geodisp_views')
101
-            ->where('majgv_id', '=', $view->id())
102
-            ->update([
103
-                'majgv_gedcom_id' => $view->tree()->id(),
104
-                'majgv_view_class' => get_class($view),
105
-                'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled',
106
-                'majgv_descr' => mb_substr($view->description(), 0, 248),
107
-                'majgv_analysis' => get_class($view->analysis()),
108
-                'majgv_place_depth' => $view->placesDepth(),
109
-                'majgv_top_places' => $view->numberTopPlaces(),
110
-                'majgv_colors' => $view instanceof GeoAnalysisMap ? json_encode($view->colors()) : null
111
-            ]);
112
-    }
113
-
114
-    /**
115
-     * Update the status of a geographical dispersion analysis view object in the database.
116
-     *
117
-     * @param AbstractGeoAnalysisView $view
118
-     * @param bool $status
119
-     * @return int
120
-     */
121
-    public function updateStatus(AbstractGeoAnalysisView $view, bool $status): int
122
-    {
123
-        return DB::table('maj_geodisp_views')
124
-            ->where('majgv_id', '=', $view->id())
125
-            ->update(['majgv_status' => $status ? 'enabled' : 'disabled']);
126
-    }
127
-
128
-    /**
129
-     * Delete a geographical dispersion analysis view object from the database.
130
-     *
131
-     * @param AbstractGeoAnalysisView $view
132
-     * @return int
133
-     */
134
-    public function delete(AbstractGeoAnalysisView $view): int
135
-    {
136
-        return DB::table('maj_geodisp_views')
137
-            ->where('majgv_id', '=', $view->id())
138
-            ->delete();
139
-    }
140
-
141
-    /**
142
-     * Get the closure to create a AbstractGeoAnalysisView object from a row in the database.
143
-     * It returns null if the classes stored in the DB cannot be loaded through the Laravel container,
144
-     * or if the types do not match with the ones expected.
145
-     *
146
-     * @param Tree $tree
147
-     * @return Closure(\stdClass $row):?AbstractGeoAnalysisView
148
-     */
149
-    private function viewMapper(Tree $tree): Closure
150
-    {
151
-        return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView {
152
-            try {
153
-                $geoanalysis = app($row->majgv_analysis);
154
-                if (!($geoanalysis instanceof GeoAnalysisInterface)) {
155
-                    return null;
156
-                }
157
-
158
-                $view = app()->makeWith($row->majgv_view_class, [
159
-                    'id'                    =>  (int) $row->majgv_id,
160
-                    'tree'                  =>  $tree,
161
-                    'enabled'               =>  $row->majgv_status === 'enabled',
162
-                    'description'           =>  $row->majgv_descr,
163
-                    'geoanalysis'           =>  $geoanalysis,
164
-                    'depth'                 =>  (int) $row->majgv_place_depth,
165
-                    'detailed_top_places'   =>  (int) $row->majgv_top_places
166
-                ]);
167
-
168
-                if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) {
169
-                    $view = $view->withColors($this->colorsDecoder($row->majgv_colors));
170
-                }
171
-
172
-                return $view instanceof AbstractGeoAnalysisView ? $view : null;
173
-            } catch (BindingResolutionException $ex) {
174
-                return null;
175
-            }
176
-        };
177
-    }
178
-
179
-    /**
180
-     * Create a MapColorsConfig object from a JSON column value.
181
-     * Returns null if the JSON string is invalid, or if the colors are not valid.
182
-     *
183
-     * @param string $colors_config
184
-     * @return MapColorsConfig|NULL
185
-     */
186
-    private function colorsDecoder(string $colors_config): ?MapColorsConfig
187
-    {
188
-        $colors = json_decode($colors_config, true);
189
-        if (!is_array($colors) && count($colors) !== 4) {
190
-            return null;
191
-        }
192
-        try {
193
-            return new MapColorsConfig(
194
-                \Spatie\Color\Factory::fromString($colors['default'] ?? ''),
195
-                \Spatie\Color\Factory::fromString($colors['stroke'] ?? ''),
196
-                \Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''),
197
-                \Spatie\Color\Factory::fromString($colors['hover'] ?? '')
198
-            );
199
-        } catch (InvalidColorValue $ex) {
200
-            return null;
201
-        }
202
-    }
203
-
204
-    /**
205
-     * Get a closure to filter views by enabled/disabled status
206
-     *
207
-     * @param bool $include_disabled
208
-     *
209
-     * @return Closure(AbstractGeoAnalysisView $view):bool
210
-     */
211
-    private function enabledFilter(bool $include_disabled): Closure
212
-    {
213
-        return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool {
214
-            return $include_disabled || $view->isEnabled();
215
-        };
216
-    }
35
+	/**
36
+	 * Find a Geographical dispersion analysis view by ID
37
+	 *
38
+	 * @param Tree $tree
39
+	 * @param int $id
40
+	 * @return AbstractGeoAnalysisView|NULL
41
+	 */
42
+	public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView
43
+	{
44
+		return $this->all($tree, $include_disabled)
45
+			->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id);
46
+	}
47
+
48
+	/**
49
+	 * Get all Geographical dispersion analysis views, with or without the disabled ones.
50
+	 *
51
+	 * {@internal It would ignore any view for which the class could not be loaded by the container}
52
+	 *
53
+	 * @param Tree $tree
54
+	 * @param bool $include_disabled
55
+	 * @return Collection<AbstractGeoAnalysisView>
56
+	 */
57
+	public function all(Tree $tree, bool $include_disabled = false): Collection
58
+	{
59
+		return Registry::cache()->array()->remember(
60
+			'all-geodispersion-views',
61
+			function () use ($tree, $include_disabled): Collection {
62
+				return DB::table('maj_geodisp_views')
63
+					->select('maj_geodisp_views.*')
64
+					->where('majgv_gedcom_id', '=', $tree->id())
65
+					->get()
66
+					->map($this->viewMapper($tree))
67
+					->filter()
68
+					->filter($this->enabledFilter($include_disabled));
69
+			}
70
+		);
71
+	}
72
+
73
+	/**
74
+	 * Insert a geographical dispersion analysis view object in the database.
75
+	 *
76
+	 * @param AbstractGeoAnalysisView $view
77
+	 * @return int
78
+	 */
79
+	public function insertGetId(AbstractGeoAnalysisView $view): int
80
+	{
81
+		return DB::table('maj_geodisp_views')
82
+			->insertGetId([
83
+				'majgv_gedcom_id' => $view->tree()->id(),
84
+				'majgv_view_class' => get_class($view),
85
+				'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled',
86
+				'majgv_descr' => mb_substr($view->description(), 0, 248),
87
+				'majgv_analysis' => get_class($view->analysis()),
88
+				'majgv_place_depth' => $view->placesDepth()
89
+			]);
90
+	}
91
+
92
+	/**
93
+	 * Update a geographical dispersion analysis view object in the database.
94
+	 *
95
+	 * @param AbstractGeoAnalysisView $view
96
+	 * @return int
97
+	 */
98
+	public function update(AbstractGeoAnalysisView $view): int
99
+	{
100
+		return DB::table('maj_geodisp_views')
101
+			->where('majgv_id', '=', $view->id())
102
+			->update([
103
+				'majgv_gedcom_id' => $view->tree()->id(),
104
+				'majgv_view_class' => get_class($view),
105
+				'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled',
106
+				'majgv_descr' => mb_substr($view->description(), 0, 248),
107
+				'majgv_analysis' => get_class($view->analysis()),
108
+				'majgv_place_depth' => $view->placesDepth(),
109
+				'majgv_top_places' => $view->numberTopPlaces(),
110
+				'majgv_colors' => $view instanceof GeoAnalysisMap ? json_encode($view->colors()) : null
111
+			]);
112
+	}
113
+
114
+	/**
115
+	 * Update the status of a geographical dispersion analysis view object in the database.
116
+	 *
117
+	 * @param AbstractGeoAnalysisView $view
118
+	 * @param bool $status
119
+	 * @return int
120
+	 */
121
+	public function updateStatus(AbstractGeoAnalysisView $view, bool $status): int
122
+	{
123
+		return DB::table('maj_geodisp_views')
124
+			->where('majgv_id', '=', $view->id())
125
+			->update(['majgv_status' => $status ? 'enabled' : 'disabled']);
126
+	}
127
+
128
+	/**
129
+	 * Delete a geographical dispersion analysis view object from the database.
130
+	 *
131
+	 * @param AbstractGeoAnalysisView $view
132
+	 * @return int
133
+	 */
134
+	public function delete(AbstractGeoAnalysisView $view): int
135
+	{
136
+		return DB::table('maj_geodisp_views')
137
+			->where('majgv_id', '=', $view->id())
138
+			->delete();
139
+	}
140
+
141
+	/**
142
+	 * Get the closure to create a AbstractGeoAnalysisView object from a row in the database.
143
+	 * It returns null if the classes stored in the DB cannot be loaded through the Laravel container,
144
+	 * or if the types do not match with the ones expected.
145
+	 *
146
+	 * @param Tree $tree
147
+	 * @return Closure(\stdClass $row):?AbstractGeoAnalysisView
148
+	 */
149
+	private function viewMapper(Tree $tree): Closure
150
+	{
151
+		return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView {
152
+			try {
153
+				$geoanalysis = app($row->majgv_analysis);
154
+				if (!($geoanalysis instanceof GeoAnalysisInterface)) {
155
+					return null;
156
+				}
157
+
158
+				$view = app()->makeWith($row->majgv_view_class, [
159
+					'id'                    =>  (int) $row->majgv_id,
160
+					'tree'                  =>  $tree,
161
+					'enabled'               =>  $row->majgv_status === 'enabled',
162
+					'description'           =>  $row->majgv_descr,
163
+					'geoanalysis'           =>  $geoanalysis,
164
+					'depth'                 =>  (int) $row->majgv_place_depth,
165
+					'detailed_top_places'   =>  (int) $row->majgv_top_places
166
+				]);
167
+
168
+				if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) {
169
+					$view = $view->withColors($this->colorsDecoder($row->majgv_colors));
170
+				}
171
+
172
+				return $view instanceof AbstractGeoAnalysisView ? $view : null;
173
+			} catch (BindingResolutionException $ex) {
174
+				return null;
175
+			}
176
+		};
177
+	}
178
+
179
+	/**
180
+	 * Create a MapColorsConfig object from a JSON column value.
181
+	 * Returns null if the JSON string is invalid, or if the colors are not valid.
182
+	 *
183
+	 * @param string $colors_config
184
+	 * @return MapColorsConfig|NULL
185
+	 */
186
+	private function colorsDecoder(string $colors_config): ?MapColorsConfig
187
+	{
188
+		$colors = json_decode($colors_config, true);
189
+		if (!is_array($colors) && count($colors) !== 4) {
190
+			return null;
191
+		}
192
+		try {
193
+			return new MapColorsConfig(
194
+				\Spatie\Color\Factory::fromString($colors['default'] ?? ''),
195
+				\Spatie\Color\Factory::fromString($colors['stroke'] ?? ''),
196
+				\Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''),
197
+				\Spatie\Color\Factory::fromString($colors['hover'] ?? '')
198
+			);
199
+		} catch (InvalidColorValue $ex) {
200
+			return null;
201
+		}
202
+	}
203
+
204
+	/**
205
+	 * Get a closure to filter views by enabled/disabled status
206
+	 *
207
+	 * @param bool $include_disabled
208
+	 *
209
+	 * @return Closure(AbstractGeoAnalysisView $view):bool
210
+	 */
211
+	private function enabledFilter(bool $include_disabled): Closure
212
+	{
213
+		return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool {
214
+			return $include_disabled || $view->isEnabled();
215
+		};
216
+	}
217 217
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView
43 43
     {
44 44
         return $this->all($tree, $include_disabled)
45
-            ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id);
45
+            ->first(fn(AbstractGeoAnalysisView $view) : bool => $view->id() === $id);
46 46
     }
47 47
 
48 48
     /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     {
59 59
         return Registry::cache()->array()->remember(
60 60
             'all-geodispersion-views',
61
-            function () use ($tree, $include_disabled): Collection {
61
+            function() use ($tree, $include_disabled): Collection {
62 62
                 return DB::table('maj_geodisp_views')
63 63
                     ->select('maj_geodisp_views.*')
64 64
                     ->where('majgv_gedcom_id', '=', $tree->id())
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      */
149 149
     private function viewMapper(Tree $tree): Closure
150 150
     {
151
-        return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView {
151
+        return function(stdClass $row) use ($tree): ?AbstractGeoAnalysisView {
152 152
             try {
153 153
                 $geoanalysis = app($row->majgv_analysis);
154 154
                 if (!($geoanalysis instanceof GeoAnalysisInterface)) {
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
                 }
157 157
 
158 158
                 $view = app()->makeWith($row->majgv_view_class, [
159
-                    'id'                    =>  (int) $row->majgv_id,
159
+                    'id'                    =>  (int)$row->majgv_id,
160 160
                     'tree'                  =>  $tree,
161 161
                     'enabled'               =>  $row->majgv_status === 'enabled',
162 162
                     'description'           =>  $row->majgv_descr,
163 163
                     'geoanalysis'           =>  $geoanalysis,
164
-                    'depth'                 =>  (int) $row->majgv_place_depth,
165
-                    'detailed_top_places'   =>  (int) $row->majgv_top_places
164
+                    'depth'                 =>  (int)$row->majgv_place_depth,
165
+                    'detailed_top_places'   =>  (int)$row->majgv_top_places
166 166
                 ]);
167 167
 
168 168
                 if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) {
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
      */
211 211
     private function enabledFilter(bool $include_disabled): Closure
212 212
     {
213
-        return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool {
213
+        return function(AbstractGeoAnalysisView $view) use ($include_disabled): bool {
214 214
             return $include_disabled || $view->isEnabled();
215 215
         };
216 216
     }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/PlacesReferenceTableService.php 2 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -21,102 +21,102 @@
 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();
79
-        if (count($columns_select) === 0) {
80
-            return $target_format;
81
-        }
78
+		$mapping = (array) $rows->first();
79
+		if (count($columns_select) === 0) {
80
+			return $target_format;
81
+		}
82 82
 
83
-        return str_replace(
84
-            array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
85
-            array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
86
-            $target_format
87
-        );
88
-    }
83
+		return str_replace(
84
+			array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
85
+			array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
86
+			$target_format
87
+		);
88
+	}
89 89
 
90
-    /**
91
-     * Get the column name for a format placeholder tag
92
-     *
93
-     * @param string $placeholder
94
-     * @return string
95
-     */
96
-    private function columnName(string $placeholder): string
97
-    {
98
-        return self::COLUMN_MAPPING[$placeholder] ?? '';
99
-    }
90
+	/**
91
+	 * Get the column name for a format placeholder tag
92
+	 *
93
+	 * @param string $placeholder
94
+	 * @return string
95
+	 */
96
+	private function columnName(string $placeholder): string
97
+	{
98
+		return self::COLUMN_MAPPING[$placeholder] ?? '';
99
+	}
100 100
 
101
-    /**
102
-     * Get the placeholder tag for a column_name
103
-     *
104
-     * @param string $column_name
105
-     * @return string
106
-     */
107
-    private function tagName(string $column_name): string
108
-    {
109
-        return array_flip(self::COLUMN_MAPPING)[$column_name] ?? '';
110
-    }
101
+	/**
102
+	 * Get the placeholder tag for a column_name
103
+	 *
104
+	 * @param string $column_name
105
+	 * @return string
106
+	 */
107
+	private function tagName(string $column_name): string
108
+	{
109
+		return array_flip(self::COLUMN_MAPPING)[$column_name] ?? '';
110
+	}
111 111
 
112
-    /**
113
-     * Sanitize string for use in a SQL query.
114
-     *
115
-     * @param string $string
116
-     * @return string
117
-     */
118
-    private function sanitizeString(string $string): string
119
-    {
120
-        return DB::connection()->getPdo()->quote($string);
121
-    }
112
+	/**
113
+	 * Sanitize string for use in a SQL query.
114
+	 *
115
+	 * @param string $string
116
+	 * @return string
117
+	 */
118
+	private function sanitizeString(string $string): string
119
+	{
120
+		return DB::connection()->getPdo()->quote($string);
121
+	}
122 122
 }
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,13 +75,13 @@  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
         if (count($columns_select) === 0) {
80 80
             return $target_format;
81 81
         }
82 82
 
83 83
         return str_replace(
84
-            array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
84
+            array_map(fn($tag) => '{'.$tag.'}', $columns_select[1]),
85 85
             array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
86 86
             $target_format
87 87
         );
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/GeoAnalysisDataService.php 2 patches
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.
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.