GenericPlaceMapperConfig   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 103
rs 10
c 0
b 0
f 0
wmc 11

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfig() 0 4 1
A has() 0 3 1
A get() 0 3 1
A config() 0 3 1
A jsonSerializeConfig() 0 3 1
A jsonDeserialize() 0 9 3
A configContent() 0 3 1
A withConfigUpdate() 0 3 1
A jsonSerialize() 0 6 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) 2021-2022, 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\Common\GeoDispersion\Config;
16
17
use Fisharebest\Webtrees\Tree;
18
use Fisharebest\Webtrees\Module\ModuleInterface;
19
use MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface;
20
use Psr\Http\Message\ServerRequestInterface;
21
22
/**
23
 * Generic Place Mapper configuration.
24
 * This configuration is based on an associate array holding the configuration.
25
 */
26
class GenericPlaceMapperConfig implements PlaceMapperConfigInterface
27
{
28
    /** @var array<string, mixed> $config */
29
    private array $config = [];
30
31
    /**
32
     * Get the generic mapper's config
33
     *
34
     * @return array<string, mixed>
35
     */
36
    public function config(): array
37
    {
38
        return $this->config;
39
    }
40
41
    /**
42
     * Set the generic mapper's config
43
     *
44
     * @param array<string, mixed> $config
45
     * @return $this
46
     */
47
    public function setConfig(array $config): self
48
    {
49
        $this->config = $config;
50
        return $this;
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get()
56
     */
57
    public function get(string $key, $default = null)
58
    {
59
        return $this->config[$key] ?? $default;
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has()
65
     */
66
    public function has(string $key): bool
67
    {
68
        return key_exists($key, $this->config);
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     * @see \JsonSerializable::jsonSerialize()
74
     */
75
    #[\ReturnTypeWillChange]
76
    public function jsonSerialize()
77
    {
78
        return [
79
            'class'     =>  get_class($this),
80
            'config'    =>  $this->jsonSerializeConfig()
81
        ];
82
    }
83
84
    /**
85
     * Returns a representation of the mapper config compatible with Json serialisation
86
     *
87
     * @return mixed
88
     */
89
    public function jsonSerializeConfig()
90
    {
91
        return $this->config;
92
    }
93
94
    /**
95
     * {@inheritDoc}
96
     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize()
97
     *
98
     * @param mixed $config
99
     * @return $this
100
     */
101
    public function jsonDeserialize($config): self
102
    {
103
        if (is_string($config)) {
104
            return $this->jsonDeserialize((array) json_decode($config));
105
        }
106
        if (is_array($config)) {
107
            return $this->setConfig($config);
108
        }
109
        return $this;
110
    }
111
112
    /**
113
     * {@inheritDoc}
114
     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent()
115
     */
116
    public function configContent(ModuleInterface $module, Tree $tree): string
117
    {
118
        return '';
119
    }
120
121
    /**
122
     * {@inheritDoc}
123
     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate()
124
     * @return $this
125
     */
126
    public function withConfigUpdate(ServerRequestInterface $request): self
127
    {
128
        return $this;
129
    }
130
}
131