Passed
Branch feature/2.1-geodispersion-dev (1d61a8)
by Jonathan
61:21
created

GeoAnalysisMap   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 82
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A colors() 0 7 1
A globalTabContent() 0 37 4
A icon() 0 3 1
A setColors() 0 4 1
1
<?php
2
3
/**
4
 * webtrees-lib: MyArtJaub library for webtrees
5
 *
6
 * @package MyArtJaub\Webtrees
7
 * @subpackage GeoDispersion
8
 * @author Jonathan Jaubart <[email protected]>
9
 * @copyright Copyright (c) 2009-2021, Jonathan Jaubart
10
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
11
 */
12
13
declare(strict_types=1);
14
15
namespace MyArtJaub\Webtrees\Module\GeoDispersion\Views;
16
17
use Fisharebest\Webtrees\I18N;
18
use Fisharebest\Webtrees\Module\ModuleInterface;
19
use MyArtJaub\Webtrees\Common\GeoDispersion\Config\MapColorsConfig;
20
use MyArtJaub\Webtrees\Common\GeoDispersion\GeoAnalysis\GeoAnalysisResult;
21
use MyArtJaub\Webtrees\Module\GeoDispersion\Services\GeoAnalysisViewDataService;
22
use Spatie\Color\Rgb;
23
24
/**
25
 * A geographical dispersion analysis view displaying on a map for its global result.
26
 */
27
class GeoAnalysisMap extends AbstractGeoAnalysisView
28
{
29
    private ?MapColorsConfig $colors_config = null;
30
31
    /**
32
     * {@inheritDoc}
33
     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon()
34
     */
35
    public function icon(ModuleInterface $module): string
36
    {
37
        return view($module->name() . '::icons/view-map');
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent()
43
     */
44
    public function globalTabContent(
45
        ModuleInterface $module,
46
        GeoAnalysisResult $result,
47
        GeoAnalysisViewDataService $geoview_data_service,
48
        array $params
49
    ): string {
50
        $map_adapters = $geoview_data_service->mapAdapters($this);
51
52
        $adapter_result = null;
53
        foreach ($map_adapters as $map_adapter) {
54
            $adapter_result_tmp = $map_adapter->convert($result);
55
            $adapter_result = $adapter_result === null ?
56
                $adapter_result_tmp :
57
                $adapter_result->merge($adapter_result_tmp);
0 ignored issues
show
Bug introduced by
The method merge() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
                $adapter_result->/** @scrutinizer ignore-call */ 
58
                                 merge($adapter_result_tmp);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
        }
59
60
        if ($adapter_result === null) {
61
            return view($module->name() . '::errors/tab-error', [
62
                'message'   =>  I18N::translate('The map could not be loaded.'),
63
            ]);
64
        }
65
66
        //phpcs:disable Generic.Files.LineLength.TooLong
67
        $basemap_provider = [
68
            'url'    => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
69
            'options' => [
70
                'attribution' => '<a href="https://www.openstreetmap.org/copyright">&copy; OpenStreetMap</a> contributors',
71
                'max_zoom'    => 19
72
            ]
73
        ];
74
        //phpcs:enable
75
76
        return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [
77
            'result'            =>  $adapter_result->geoAnalysisResult(),
78
            'features'          =>  $adapter_result->features(),
79
            'colors'            =>  $this->colors(),
80
            'basemap_provider'  =>  $basemap_provider
81
        ]);
82
    }
83
84
    /**
85
     * Get the color scheme configuration for the map view
86
     *
87
     * @return MapColorsConfig
88
     */
89
    public function colors(): MapColorsConfig
90
    {
91
        return $this->colors_config ?? new MapColorsConfig(
92
            new Rgb(245, 245, 245),
93
            new Rgb(213, 213, 213),
94
            new Rgb(4, 147, 171),
95
            new Rgb(255, 102, 0)
96
        );
97
    }
98
99
    /**
100
     * Set the color scheme configuration for the map view
101
     *
102
     * @param MapColorsConfig $config
103
     * @return self
104
     */
105
    public function setColors(?MapColorsConfig $config): self
106
    {
107
        $this->colors_config = $config;
108
        return $this;
109
    }
110
}
111