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

SimpleTopFilteredPlaceMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 2
A map() 0 6 2
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) 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\PlaceMappers;
16
17
use Fisharebest\Webtrees\Place;
18
use MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface;
19
20
/**
21
 * Extension of the Simple Place Mapper, allowing to filter on a defined list of higher level places.
22
 * Depending on the map, this can help mitigate potential duplicates.
23
 *
24
 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper
25
 */
26
class SimpleTopFilteredPlaceMapper extends SimplePlaceMapper implements PlaceMapperInterface
27
{
28
    use TopFilteredPlaceMapperTrait;
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
    }
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
    }
46
}
47