Passed
Pull Request — master (#857)
by Georges
04:15 queued 02:15
created

Config::getEndpointName()

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
1
<?php
2
3
/**
4
 *
5
 * This file is part of Phpfastcache.
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
10
 *
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 * @author Contributors  https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phpfastcache\Drivers\Solr;
18
19
use Phpfastcache\Config\ConfigurationOption;
20
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
21
use Phpfastcache\Core\Pool\TaggableCacheItemPoolInterface;
22
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
23
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
24
use Psr\EventDispatcher\EventDispatcherInterface;
0 ignored issues
show
Bug introduced by
The type Psr\EventDispatcher\EventDispatcherInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
26
class Config extends ConfigurationOption
27
{
28
    public const DEFAULT_MAPPING_SCHEMA = [
29
        Driver::SOLR_DEFAULT_ID_FIELD => Driver::SOLR_DEFAULT_ID_FIELD,
30
        Driver::SOLR_DISCRIMINATOR_FIELD => Driver::SOLR_DISCRIMINATOR_FIELD . '_s',
31
        ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX . '_s',
32
        ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX . '_s',
33
        ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX . '_s',
34
        ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX . '_s',
35
        ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX . '_s',
36
        TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX => TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX . '_ss',
37
    ];
38
    protected string $host = '127.0.0.1';
39
    protected int $port = 8983;
40
    protected string $coreName = 'phpfastcache';
41
    protected string $endpointName = 'phpfastcache';
42
    protected string $scheme = 'http';
43
    protected string $path = '/';
44
// Override of ConfigurationOption
45
46
    protected array $mappingSchema = self::DEFAULT_MAPPING_SCHEMA;
47
    protected EventDispatcherInterface $eventDispatcher;
48
    public function __construct(array $parameters = [])
49
    {
50
        $this->eventDispatcher = $this->getDefaultEventDispatcher();
51
        parent::__construct($parameters);
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getHost(): string
58
    {
59
        return $this->host;
60
    }
61
62
    /**
63
     * @param string $host
64
     * @return Config
65
     * @throws PhpfastcacheLogicException
66
     */
67
    public function setHost(string $host): Config
68
    {
69
        $this->enforceLockedProperty(__FUNCTION__);
70
        $this->host = $host;
71
        return $this;
72
    }
73
74
    /**
75
     * @return int
76
     */
77
    public function getPort(): int
78
    {
79
        return $this->port;
80
    }
81
82
    /**
83
     * @param int $port
84
     * @return Config
85
     * @throws PhpfastcacheLogicException
86
     */
87
    public function setPort(int $port): Config
88
    {
89
        $this->enforceLockedProperty(__FUNCTION__);
90
        $this->port = $port;
91
        return $this;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getCoreName(): string
98
    {
99
        return $this->coreName;
100
    }
101
102
    /**
103
     * @param string $coreName
104
     * @return Config
105
     * @throws PhpfastcacheLogicException
106
     */
107
    public function setCoreName(string $coreName): Config
108
    {
109
        $this->enforceLockedProperty(__FUNCTION__);
110
        $this->coreName = $coreName;
111
        return $this;
112
    }
113
114
    /**
115
     * @return string
116
     */
117
    public function getScheme(): string
118
    {
119
        return $this->scheme;
120
    }
121
122
    /**
123
     * @param string $scheme
124
     * @return Config
125
     * @throws PhpfastcacheLogicException
126
     */
127
    public function setScheme(string $scheme): Config
128
    {
129
        $this->enforceLockedProperty(__FUNCTION__);
130
        $this->scheme = $scheme;
131
        return $this;
132
    }
133
134
    /**
135
     * @return EventDispatcherInterface
136
     */
137
    public function getEventDispatcher(): EventDispatcherInterface
138
    {
139
        return $this->eventDispatcher;
140
    }
141
142
    /**
143
     * @return EventDispatcherInterface
144
     */
145
    protected function getDefaultEventDispatcher(): EventDispatcherInterface
146
    {
147
        return new class implements EventDispatcherInterface {
148
            public function dispatch(object $event): object
149
            {
150
                return $event;
151
            }
152
        };
153
    }
154
155
    /**
156
     * @param EventDispatcherInterface $eventDispatcher
157
     * @return Config
158
     * @throws PhpfastcacheLogicException
159
     */
160
    public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): Config
161
    {
162
        $this->enforceLockedProperty(__FUNCTION__);
163
        $this->eventDispatcher = $eventDispatcher;
164
        return $this;
165
    }
166
167
    /**
168
     * @return string[]
169
     */
170
    public function getMappingSchema(): array
171
    {
172
        return $this->mappingSchema;
173
    }
174
175
    /**
176
     * @param string[] $mappingSchema
177
     * @return Config
178
     * @throws PhpfastcacheLogicException
179
     * @throws PhpfastcacheInvalidArgumentException
180
     */
181
    public function setMappingSchema(array $mappingSchema): Config
182
    {
183
        $this->enforceLockedProperty(__FUNCTION__);
184
        $diff = array_diff(array_keys(self::DEFAULT_MAPPING_SCHEMA), array_keys($mappingSchema));
185
        if ($diff) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $diff of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
186
            throw new PhpfastcacheInvalidArgumentException('Missing keys for the solr mapping schema: ' . \implode(', ', $diff));
187
        }
188
189
        $this->mappingSchema = $mappingSchema;
190
        return $this;
191
    }
192
193
    /**
194
     * @return string
195
     */
196
    public function getEndpointName(): string
197
    {
198
        return $this->endpointName;
199
    }
200
201
    /**
202
     * @param string $endpointName
203
     * @return Config
204
     * @throws PhpfastcacheLogicException
205
     */
206
    public function setEndpointName(string $endpointName): Config
207
    {
208
        $this->enforceLockedProperty(__FUNCTION__);
209
        $this->endpointName = $endpointName;
210
        return $this;
211
    }
212
}
213