Completed
Push — master ( 366a5b...a17b2a )
by
unknown
17:34 queued 14:29
created

Solr::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 30
rs 9.44
c 0
b 0
f 0
1
<?php
2
namespace Kitodo\Dlf\Common;
3
4
/**
5
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
6
 *
7
 * This file is part of the Kitodo and TYPO3 projects.
8
 *
9
 * @license GNU General Public License version 3 or later.
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 */
13
14
/**
15
 * Solr class for the 'dlf' extension
16
 *
17
 * @author Sebastian Meyer <[email protected]>
18
 * @author Henrik Lochmann <[email protected]>
19
 * @package TYPO3
20
 * @subpackage dlf
21
 * @access public
22
 */
23
class Solr {
24
    /**
25
     * This holds the core name
26
     *
27
     * @var string
28
     * @access protected
29
     */
30
    protected $core = '';
31
32
    /**
33
     * This holds the PID for the configuration
34
     *
35
     * @var integer
36
     * @access protected
37
     */
38
    protected $cPid = 0;
39
40
    /**
41
     * The extension key
42
     *
43
     * @var string
44
     * @access public
45
     */
46
    public static $extKey = 'dlf';
47
48
    /**
49
     * This holds the max results
50
     *
51
     * @var integer
52
     * @access protected
53
     */
54
    protected $limit = 50000;
55
56
    /**
57
     * This holds the number of hits for last search
58
     *
59
     * @var integer
60
     * @access protected
61
     */
62
    protected $numberOfHits = 0;
63
64
    /**
65
     * This holds the additional query parameters
66
     *
67
     * @var array
68
     * @access protected
69
     */
70
    protected $params = [];
71
72
    /**
73
     * Is the search instantiated successfully?
74
     *
75
     * @var boolean
76
     * @access protected
77
     */
78
    protected $ready = FALSE;
79
80
    /**
81
     * This holds the singleton search objects with their core as array key
82
     *
83
     * @var array (\Kitodo\Dlf\Common\Solr)
84
     * @access protected
85
     */
86
    protected static $registry = [];
87
88
    /**
89
     * This holds the Solr service object
90
     *
91
     * @var \Solarium\Client
92
     * @access protected
93
     */
94
    protected $service;
95
96
    /**
97
     * Escape all special characters in a query string
98
     *
99
     * @access public
100
     *
101
     * @param string $query: The query string
0 ignored issues
show
Documentation introduced by
There is no parameter named $query:. Did you maybe mean $query?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
102
     *
103
     * @return string The escaped query string
104
     */
105
    public static function escapeQuery($query) {
106
        $helper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Solarium\Core\Query\Helper::class);
107
        // Escape query phrase or term.
108
        if (preg_match('/^".*"$/', $query)) {
109
            return '"'.$helper->escapePhrase(trim($query, '"')).'"';
110
        } else {
111
            return $helper->escapeTerm($query);
112
        }
113
    }
114
115
    /**
116
     * Escape all special characters in a query string while retaining valid field queries
117
     *
118
     * @access public
119
     *
120
     * @param string $query: The query string
0 ignored issues
show
Documentation introduced by
There is no parameter named $query:. Did you maybe mean $query?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
121
     * @param integer $pid: The PID for the field configuration
0 ignored issues
show
Bug introduced by
There is no parameter named $pid:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
122
     *
123
     * @return string The escaped query string
124
     */
125
    public static function escapeQueryKeepField($query, $pid) {
126
        // Is there a field query?
127
        if (preg_match('/^[[:alnum:]]+_[tu][su]i:\(?.*\)?$/', $query)) {
128
            // Get all indexed fields.
129
            $fields = [];
130
            $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
131
                'tx_dlf_metadata.index_name,tx_dlf_metadata.index_tokenized,tx_dlf_metadata.index_stored',
132
                'tx_dlf_metadata',
133
                'tx_dlf_metadata.index_indexed=1'
134
                    .' AND tx_dlf_metadata.pid='.intval($pid)
135
                    .' AND (tx_dlf_metadata.sys_language_uid IN (-1,0) OR tx_dlf_metadata.l18n_parent=0)'
136
                    .Helper::whereClause('tx_dlf_metadata'),
137
                '',
138
                '',
139
                ''
140
            );
141
            if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
142 View Code Duplication
                while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_row($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
                    $fields[] = $resArray[0].'_'.($resArray[1] ? 't' : 'u').($resArray[2] ? 's' : 'u').'i';
144
                }
145
            }
146
            // Check if queried field is valid.
147
            $splitQuery = explode(':', $query, 2);
148
            if (in_array($splitQuery[0], $fields)) {
149
                $query = $splitQuery[0].':('.self::escapeQuery(trim($splitQuery[1], '()')).')';
150
            } else {
151
                $query = self::escapeQuery($query);
152
            }
153
        } elseif (!empty($query)
154
            && $query !== '*') {
155
            // Don't escape plain asterisk search.
156
            $query = self::escapeQuery($query);
157
        }
158
        return $query;
159
    }
160
161
    /**
162
     * This is a singleton class, thus instances must be created by this method
163
     *
164
     * @access public
165
     *
166
     * @param mixed $core: Name or UID of the core to load
0 ignored issues
show
Bug introduced by
There is no parameter named $core:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
167
     *
168
     * @return \Kitodo\Dlf\Common\Solr Instance of this class
169
     */
170
    public static function getInstance($core) {
171
        // Get core name if UID is given.
172
        if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($core)) {
173
            $core = Helper::getIndexNameFromUid($core, 'tx_dlf_solrcores');
174
        }
175
        // Check if core is set.
176
        if (empty($core)) {
177
            Helper::devLog('Invalid core name "'.$core.'" for Apache Solr', DEVLOG_SEVERITY_ERROR);
178
            return;
179
        }
180
        // Check if there is an instance in the registry already.
181
        if (is_object(self::$registry[$core])
182
            && self::$registry[$core] instanceof self) {
183
            // Return singleton instance if available.
184
            return self::$registry[$core];
185
        }
186
        // Create new instance...
187
        $instance = new self($core);
188
        // ...and save it to registry.
189 View Code Duplication
        if ($instance->ready) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
190
            self::$registry[$core] = $instance;
191
            // Return new instance.
192
            return $instance;
193
        } else {
194
            Helper::devLog('Could not connect to Apache Solr server', DEVLOG_SEVERITY_ERROR);
195
            return;
196
        }
197
    }
198
199
    /**
200
     * Returns the connection information for Solr
201
     *
202
     * @access public
203
     *
204
     * @return string The connection parameters for a specific Solr core
205
     */
206
    public static function getSolrConnectionInfo() {
207
        $solrInfo = [];
208
        // Extract extension configuration.
209
        $conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
210
        // Derive Solr scheme
211
        $solrInfo['scheme'] = empty($conf['solrHttps']) ? 'http' : 'https';
212
        // Derive Solr host name.
213
        $solrInfo['host'] = ($conf['solrHost'] ? $conf['solrHost'] : '127.0.0.1');
214
        // Set username and password.
215
        $solrInfo['username'] = $conf['solrUser'];
216
        $solrInfo['password'] = $conf['solrPass'];
217
        // Set port if not set.
218
        $solrInfo['port'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($conf['solrPort'], 1, 65535, 8983);
219
        // Append core name to path.
220
        $solrInfo['path'] = trim($conf['solrPath'], '/');
221
        // Timeout
222
        $solrInfo['timeout'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($conf['solrTimeout'], 1, intval(ini_get('max_execution_time')), 10);
223
        return $solrInfo;
224
    }
225
226
    /**
227
     * Returns the request URL for a specific Solr core
228
     *
229
     * @access public
230
     *
231
     * @param string $core: Name of the core to load
0 ignored issues
show
Bug introduced by
There is no parameter named $core:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
232
     *
233
     * @return string The request URL for a specific Solr core
234
     */
235
    public static function getSolrUrl($core = '') {
236
        // Get Solr connection information.
237
        $solrInfo = self::getSolrConnectionInfo();
238 View Code Duplication
        if ($solrInfo['username']
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
239
            && $solrInfo['password']) {
240
            $host = $solrInfo['username'].':'.$solrInfo['password'].'@'.$solrInfo['host'];
241
        } else {
242
            $host = $solrInfo['host'];
243
        }
244
        // Return entire request URL.
245
        return $solrInfo['scheme'].'://'.$host.':'.$solrInfo['port'].'/'.$solrInfo['path'].'/'.$core;
246
    }
247
248
    /**
249
     * Get next unused Solr core number
250
     *
251
     * @access public
252
     *
253
     * @param integer $start: Number to start with
0 ignored issues
show
Documentation introduced by
There is no parameter named $start:. Did you maybe mean $start?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
254
     *
255
     * @return integer First unused core number found
256
     */
257
    public static function solrGetCoreNumber($start = 0) {
258
        $start = max(intval($start), 0);
259
        // Check if core already exists.
260
        if (self::getInstance('dlfCore'.$start) === NULL) {
261
            return $start;
262
        } else {
263
            return self::solrGetCoreNumber($start + 1);
264
        }
265
    }
266
267
    /**
268
     * Processes a search request.
269
     *
270
     * @access public
271
     *
272
     * @return \Kitodo\Dlf\Common\DocumentList The result list
273
     */
274
    public function search() {
275
        $toplevel = [];
276
        // Take over query parameters.
277
        $params = $this->params;
278
        $params['filterquery'] = isset($params['filterquery']) ? $params['filterquery'] : [];
279
        // Set some query parameters.
280
        $params['start'] = 0;
281
        $params['rows'] = 0;
282
        // Perform search to determine the total number of hits without fetching them.
283
        $selectQuery = $this->service->createSelect($params);
284
        $results = $this->service->select($selectQuery);
285
        $this->numberOfHits = $results->getNumFound();
286
        // Restore query parameters
287
        $params = $this->params;
288
        $params['filterquery'] = isset($params['filterquery']) ? $params['filterquery'] : [];
289
        // Restrict the fields to the required ones.
290
        $params['fields'] = 'uid,id';
291
        // Extend filter query to get all documents with the same uids.
292 View Code Duplication
        foreach ($params['filterquery'] as $key => $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
293
            if (isset($value['query'])) {
294
                $params['filterquery'][$key]['query'] = '{!join from=uid to=uid}'.$value['query'];
295
            }
296
        }
297
        // Set filter query to just get toplevel documents.
298
        $params['filterquery'][] = ['query' => 'toplevel:true'];
299
        // Set join query to get all documents with the same uids.
300
        $params['query'] = '{!join from=uid to=uid}'.$params['query'];
301
        // Perform search to determine the total number of toplevel hits and fetch the required rows.
302
        $selectQuery = $this->service->createSelect($params);
303
        $results = $this->service->select($selectQuery);
304
        $numberOfToplevelHits = $results->getNumFound();
305
        // Process results.
306
        foreach ($results as $doc) {
307
            $toplevel[$doc->id] = [
308
                'u' => $doc->uid,
309
                'h' => '',
310
                's' => '',
311
                'p' => []
312
            ];
313
        }
314
        // Save list of documents.
315
        $list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(DocumentList::class);
316
        $list->reset();
317
        $list->add(array_values($toplevel));
318
        // Set metadata for search.
319
        $list->metadata = [
320
            'label' => '',
321
            'description' => '',
322
            'options' => [
323
                'source' => 'search',
324
                'engine' => 'solr',
325
                'select' => $this->params['query'],
326
                'userid' => 0,
327
                'params' => $this->params,
328
                'core' => $this->core,
329
                'pid' => $this->cPid,
330
                'order' => 'score',
331
                'order.asc' => TRUE,
332
                'numberOfHits' => $this->numberOfHits,
333
                'numberOfToplevelHits' => $numberOfToplevelHits
334
            ]
335
        ];
336
        return $list;
337
    }
338
339
    /**
340
     * Processes a search request and returns the raw Apache Solr Documents.
341
     *
342
     * @access public
343
     *
344
     * @param string $query: The search query
0 ignored issues
show
Documentation introduced by
There is no parameter named $query:. Did you maybe mean $query?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
345
     * @param array $parameters: Additional search parameters
0 ignored issues
show
Documentation introduced by
There is no parameter named $parameters:. Did you maybe mean $parameters?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
346
     *
347
     * @return array The Apache Solr Documents that were fetched
348
     */
349
    public function search_raw($query = '', $parameters = []) {
350
        // Set additional query parameters.
351
        $parameters['start'] = 0;
352
        $parameters['rows'] = $this->limit;
353
        // Set query.
354
        $parameters['query'] = $query;
355
        // Perform search.
356
        $selectQuery = $this->service->createSelect(array_merge($this->params, $parameters));
357
        $result = $this->service->select($selectQuery);
358
        $resultSet = [];
359
        foreach ($result as $doc) {
360
            $resultSet[] = $doc;
361
        }
362
        return $resultSet;
363
    }
364
365
    /**
366
     * This returns $this->limit via __get()
367
     *
368
     * @access protected
369
     *
370
     * @return integer The max number of results
371
     */
372
    protected function _getLimit() {
373
        return $this->limit;
374
    }
375
376
    /**
377
     * This returns $this->numberOfHits via __get()
378
     *
379
     * @access protected
380
     *
381
     * @return integer Total number of hits for last search
382
     */
383
    protected function _getNumberOfHits() {
384
        return $this->numberOfHits;
385
    }
386
387
    /**
388
     * This returns $this->ready via __get()
389
     *
390
     * @access protected
391
     *
392
     * @return boolean Is the search instantiated successfully?
393
     */
394
    protected function _getReady() {
395
        return $this->ready;
396
    }
397
398
    /**
399
     * This returns $this->service via __get()
400
     *
401
     * @access protected
402
     *
403
     * @return \Solarium\Client Apache Solr service object
404
     */
405
    protected function _getService() {
406
        return $this->service;
407
    }
408
409
    /**
410
     * This sets $this->cPid via __set()
411
     *
412
     * @access protected
413
     *
414
     * @param integer $value: The new PID for the metadata definitions
0 ignored issues
show
Documentation introduced by
There is no parameter named $value:. Did you maybe mean $value?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
415
     *
416
     * @return void
417
     */
418
    protected function _setCPid($value) {
419
        $this->cPid = max(intval($value), 0);
420
    }
421
422
    /**
423
     * This sets $this->limit via __set()
424
     *
425
     * @access protected
426
     *
427
     * @param integer $value: The max number of results
0 ignored issues
show
Documentation introduced by
There is no parameter named $value:. Did you maybe mean $value?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
428
     *
429
     * @return void
430
     */
431
    protected function _setLimit($value) {
432
        $this->limit = max(intval($value), 0);
433
    }
434
435
    /**
436
     * This sets $this->params via __set()
437
     *
438
     * @access protected
439
     *
440
     * @param array $value: The query parameters
0 ignored issues
show
Documentation introduced by
There is no parameter named $value:. Did you maybe mean $value?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
441
     *
442
     * @return void
443
     */
444
    protected function _setParams(array $value) {
445
        $this->params = $value;
446
    }
447
448
    /**
449
     * This magic method is called each time an invisible property is referenced from the object
450
     *
451
     * @access public
452
     *
453
     * @param string $var: Name of variable to get
0 ignored issues
show
Bug introduced by
There is no parameter named $var:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
454
     *
455
     * @return mixed Value of $this->$var
456
     */
457 View Code Duplication
    public function __get($var) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
458
        $method = '_get'.ucfirst($var);
459
        if (!property_exists($this, $var)
460
            || !method_exists($this, $method)) {
461
            Helper::devLog('There is no getter function for property "'.$var.'"', DEVLOG_SEVERITY_WARNING);
462
            return;
463
        } else {
464
            return $this->$method();
465
        }
466
    }
467
468
    /**
469
     * This magic method is called each time an invisible property is referenced from the object
470
     *
471
     * @access public
472
     *
473
     * @param string $var: Name of variable to set
0 ignored issues
show
Bug introduced by
There is no parameter named $var:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
474
     * @param mixed $value: New value of variable
0 ignored issues
show
Documentation introduced by
There is no parameter named $value:. Did you maybe mean $value?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
475
     *
476
     * @return void
477
     */
478 View Code Duplication
    public function __set($var, $value) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
479
        $method = '_set'.ucfirst($var);
480
        if (!property_exists($this, $var)
481
            || !method_exists($this, $method)) {
482
            Helper::devLog('There is no setter function for property "'.$var.'"', DEVLOG_SEVERITY_WARNING);
483
        } else {
484
            $this->$method($value);
485
        }
486
    }
487
488
    /**
489
     * This is a singleton class, thus the constructor should be private/protected
490
     *
491
     * @access protected
492
     *
493
     * @param string $core: The name of the core to use
0 ignored issues
show
Bug introduced by
There is no parameter named $core:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
494
     *
495
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
496
     */
497
    protected function __construct($core) {
498
        $solrInfo = self::getSolrConnectionInfo();
499
        $config = [
500
            'endpoint' => [
501
                'dlf' => [
502
                    'scheme' => $solrInfo['scheme'],
503
                    'host' => $solrInfo['host'],
504
                    'port' => $solrInfo['port'],
505
                    'path' => '/'.$solrInfo['path'].'/',
506
                    'core' => $core,
507
                    'username' => $solrInfo['username'],
508
                    'password' => $solrInfo['password'],
509
                    'timeout' => $solrInfo['timeout']
510
                ]
511
            ]
512
        ];
513
        // Instantiate Solarium\Client class.
514
        $this->service = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Solarium\Client::class, $config);
515
        // Check if connection is established.
516
        $ping = $this->service->createPing();
517
        try {
518
            $this->service->ping($ping);
519
            // Set core name.
520
            $this->core = $core;
521
            // Instantiation successful!
522
            $this->ready = TRUE;
523
        } catch (\Exception $e) {
524
            // Nothing to do here.
525
        }
526
    }
527
}
528