Passed
Push — master ( 498335...52b5ef )
by Rafael
42:19
created

SearchRequest   F

Complexity

Total Complexity 71

Size/Duplication

Total Lines 722
Duplicated Lines 0 %

Test Coverage

Coverage 76.28%

Importance

Changes 0
Metric Value
wmc 71
eloc 177
c 0
b 0
f 0
dl 0
loc 722
ccs 164
cts 215
cp 0.7628
rs 2.7199

48 Methods

Rating   Name   Duplication   Size   Complexity  
A getHasFacetValue() 0 3 1
A prefixWithNamespace() 0 3 1
A getSortingDirection() 0 3 1
A getActiveFacetValuesByName() 0 3 1
A getId() 0 3 1
A removeAllFacets() 0 8 2
A getRawUserQueryIsNull() 0 5 1
A addFacetValue() 0 10 2
A getRawUserQueryIsEmptyString() 0 14 3
A getHasSorting() 0 4 1
A getActiveFacetsUrlParameterStyle() 0 3 1
A getAdditionalFilters() 0 4 1
A reset() 0 20 4
A sortActiveFacets() 0 3 1
A setActiveFacets() 0 5 1
A removeSorting() 0 6 1
A __construct() 0 25 4
A getContextTypoScriptConfiguration() 0 3 1
A getRawUserQuery() 0 5 2
A setRawQueryString() 0 6 1
A removeFacetValue() 0 9 2
A setResultsPerPage() 0 7 1
A setPage() 0 10 2
A getAsArray() 0 3 1
A removeAllGroupItemPages() 0 6 1
A getContextSystemLanguageUid() 0 3 1
A getActiveFacetNames() 0 3 1
A getSortingName() 0 3 1
A getCopyForSubRequest() 0 25 4
A getPage() 0 4 1
A setSorting() 0 7 1
A isActiveFacetsSorted() 0 3 1
A removeAllFacetValuesByName() 0 8 2
A getResultsPerPage() 0 4 1
A getSorting() 0 4 1
A getContextPageUid() 0 3 1
A getSortingPart() 0 9 3
A setAdditionalFilters() 0 7 1
A getActiveFacetCount() 0 3 1
A getHighestGroupPage() 0 15 5
A setGroupItemPage() 0 7 1
A getArgumentNamespace() 0 3 1
A getActiveFacets() 0 3 1
A getArguments() 0 3 1
A getEscapedGroupItemValue() 0 3 1
A getStateChanged() 0 3 1
A mergeArguments() 0 10 1
A getGroupItemPage() 0 5 1

How to fix   Complexity   

Complex Class

Complex classes like SearchRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use SearchRequest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\Domain\Search;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2015-2016 Timo Schmidt <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\UrlFacetContainer;
29
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
30
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
31
use TYPO3\CMS\Core\Utility\ArrayUtility;
32
33
/**
34
 * The searchRequest is used to act as an api to the arguments that have been passed
35
 * with GET and POST.
36
 *
37
 * @author Timo Schmidt <[email protected]>
38
 */
39
class SearchRequest
40
{
41
    /**
42
     * The default plugin namespace.
43
     *
44
     * @var string
45
     */
46
    const DEFAULT_PLUGIN_NAMESPACE = 'tx_solr';
47
48
    /**
49
     * @var string
50
     */
51
    protected $id;
52
53
    /**
54
     * Default namespace overwritten with the configured plugin namespace.
55
     *
56
     * @var string
57
     */
58
    protected $argumentNameSpace = self::DEFAULT_PLUGIN_NAMESPACE;
59
60
    /**
61
     * Arguments that should be kept for sub requests.
62
     *
63
     * Default values, overwritten in the constructor with the namespaced arguments
64
     *
65
     * @var array
66
     */
67
    protected $persistentArgumentsPaths = ['tx_solr:q', 'tx_solr:filter', 'tx_solr:sort'];
68
69
    /**
70
     * @var bool
71
     */
72
    protected $stateChanged = false;
73
74
    /**
75
     * @var ArrayAccessor
76
     */
77
    protected $argumentsAccessor;
78
79
    /**
80
     * The sys_language_uid that was used in the context where the request was build.
81
     * This could be different from the "L" parameter and and not relevant for urls,
82
     * because typolink itself will handle it.
83
     *
84
     * @var int
85
     */
86
    protected $contextSystemLanguageUid;
87
88
    /**
89
     * The page_uid that was used in the context where the request was build.
90
     *
91
     * The pageUid is not relevant for the typolink additionalArguments and therefore
92
     * a separate property.
93
     *
94
     * @var int
95
     */
96
    protected $contextPageUid;
97
98
    /**
99
     * @var TypoScriptConfiguration
100
     */
101
    protected $contextTypoScriptConfiguration;
102
103
    /**
104
     * Container for all active facets inside of the URL(TYPO3/FE)
105
     *
106
     * @var UrlFacetContainer
107
     */
108
    protected $activeFacetContainer;
109
110
    /**
111
     * @var array
112
     */
113
    protected $persistedArguments = [];
114
115
    /**
116
     * @param array $argumentsArray
117
     * @param int $pageUid
118
     * @param int $sysLanguageUid
119
     * @param TypoScriptConfiguration|null $typoScriptConfiguration
120
     */
121 46
    public function __construct(array $argumentsArray = [], int $pageUid = 0, int $sysLanguageUid = 0, TypoScriptConfiguration $typoScriptConfiguration = null)
122
    {
123 46
        $this->stateChanged = true;
124 46
        $this->persistedArguments = $argumentsArray;
125 46
        $this->contextPageUid = $pageUid;
126 46
        $this->contextSystemLanguageUid = $sysLanguageUid;
127 46
        $this->contextTypoScriptConfiguration = $typoScriptConfiguration;
128 46
        $this->id = spl_object_hash($this);
129
130
        // overwrite the plugin namespace and the persistentArgumentsPaths
131 46
        if (!is_null($typoScriptConfiguration)) {
132 44
            $this->argumentNameSpace = $typoScriptConfiguration->getSearchPluginNamespace() ?? self::DEFAULT_PLUGIN_NAMESPACE;
133
        }
134
135 46
        $this->persistentArgumentsPaths = [$this->argumentNameSpace . ':q', $this->argumentNameSpace . ':filter', $this->argumentNameSpace . ':sort', $this->argumentNameSpace . ':groupPage'];
136
137 46
        if (!is_null($typoScriptConfiguration)) {
138 44
            $additionalPersistentArgumentsNames = $typoScriptConfiguration->getSearchAdditionalPersistentArgumentNames();
139 44
            foreach ($additionalPersistentArgumentsNames ?? [] as $additionalPersistentArgumentsName) {
140
                $this->persistentArgumentsPaths[] = $this->argumentNameSpace . ':' . $additionalPersistentArgumentsName;
141
            }
142 44
            $this->persistentArgumentsPaths = array_unique($this->persistentArgumentsPaths);
143
        }
144
145 46
        $this->reset();
146 46
    }
147
148
    /**
149
     * @return string
150
     */
151 31
    public function getId()
152
    {
153 31
        return $this->id;
154
    }
155
156
    /**
157
     * Can be used do merge arguments into the request arguments
158
     *
159
     * @param array $argumentsToMerge
160
     * @return SearchRequest
161
     */
162
    public function mergeArguments(array $argumentsToMerge)
163
    {
164
        ArrayUtility::mergeRecursiveWithOverrule(
165
            $this->persistedArguments,
166
            $argumentsToMerge
167
        );
168
169
        $this->reset();
170
171
        return $this;
172
    }
173
174
    /**
175
     * Helper method to prefix an accessor with the arguments namespace.
176
     *
177
     * @param string $path
178
     * @return string
179
     */
180 44
    protected function prefixWithNamespace($path)
181
    {
182 44
        return $this->argumentNameSpace . ':' . $path;
183
    }
184
185
    /**
186
     * @return array
187
     */
188 30
    public function getActiveFacetNames()
189
    {
190 30
        return $this->activeFacetContainer->getActiveFacetNames();
191
    }
192
193
    /**
194
     * Returns all facet values for a certain facetName
195
     * @param string $facetName
196
     * @return array
197
     */
198 35
    public function getActiveFacetValuesByName(string $facetName)
199
    {
200 35
        return $this->activeFacetContainer->getActiveFacetValuesByName($facetName);
201
    }
202
203
    /**
204
     * @return array
205
     */
206 30
    public function getActiveFacets()
207
    {
208 30
        return $this->activeFacetContainer->getActiveFacets();
209
    }
210
211
    /**
212
     * Enable sorting of URL parameters
213
     */
214
    public function sortActiveFacets(): void
215
    {
216
        $this->activeFacetContainer->enableSort();
217
    }
218
219
    /**
220
     * @return bool
221
     */
222 30
    public function isActiveFacetsSorted(): bool
223
    {
224 30
        return $this->activeFacetContainer->isSorted();
225
    }
226
227
    /**
228
     * @return string
229
     */
230
    public function getActiveFacetsUrlParameterStyle(): string
231
    {
232
        return $this->activeFacetContainer->getParameterStyle();
233
    }
234
235
    /**
236
     * Returns the active count of facets
237
     *
238
     * @return int
239
     */
240
    public function getActiveFacetCount()
241
    {
242
        return $this->activeFacetContainer->count();
243
    }
244
245
    /**
246
     * @param array $activeFacets
247
     *
248
     * @return SearchRequest
249
     */
250
    protected function setActiveFacets($activeFacets = [])
251
    {
252
        $this->activeFacetContainer->setActiveFacets($activeFacets);
253
254
        return $this;
255
    }
256
257
    /**
258
     * Adds a facet value to the request.
259
     *
260
     * @param string $facetName
261
     * @param mixed $facetValue
262
     *
263
     * @return SearchRequest
264
     */
265 30
    public function addFacetValue(string $facetName, $facetValue)
266
    {
267 30
        $this->activeFacetContainer->addFacetValue($facetName, $facetValue);
268
269 30
        if ($this->activeFacetContainer->hasChanged()) {
270 30
            $this->stateChanged = true;
271 30
            $this->activeFacetContainer->acknowledgeChange();
272
        }
273
274 30
        return $this;
275
    }
276
277
    /**
278
     * Removes a facet value from the request.
279
     *
280
     * @param string $facetName
281
     * @param mixed $facetValue
282
     *
283
     * @return SearchRequest
284
     */
285 4
    public function removeFacetValue(string $facetName, $facetValue)
286
    {
287 4
        $this->activeFacetContainer->removeFacetValue($facetName, $facetValue);
288 4
        if ($this->activeFacetContainer->hasChanged()) {
289 4
            $this->stateChanged = true;
290 4
            $this->activeFacetContainer->acknowledgeChange();
291
        }
292
293 4
        return $this;
294
    }
295
296
    /**
297
     * Removes all facet values from the request by a certain facet name
298
     *
299
     * @param string $facetName
300
     *
301
     * @return SearchRequest
302
     */
303 1
    public function removeAllFacetValuesByName(string $facetName)
304
    {
305 1
        $this->activeFacetContainer->removeAllFacetValuesByName($facetName);
306 1
        if ($this->activeFacetContainer->hasChanged()) {
307 1
            $this->stateChanged = true;
308 1
            $this->activeFacetContainer->acknowledgeChange();
309
        }
310 1
        return $this;
311
    }
312
313
    /**
314
     * Removes all active facets from the request.
315
     *
316
     * @return SearchRequest
317
     */
318 4
    public function removeAllFacets()
319
    {
320 4
        $this->activeFacetContainer->removeAllFacets();
321 4
        if ($this->activeFacetContainer->hasChanged()) {
322 4
            $this->stateChanged = true;
323 4
            $this->activeFacetContainer->acknowledgeChange();
324
        }
325 4
        return $this;
326
    }
327
328
    /**
329
     * Check if an active facet has a given value
330
     *
331
     * @param string $facetName
332
     * @param mixed $facetValue
333
     * @return bool
334
     */
335 30
    public function getHasFacetValue(string $facetName, $facetValue): bool
336
    {
337 30
        return $this->activeFacetContainer->hasFacetValue($facetName, $facetValue);
338
    }
339
340
    /**
341
     * @return bool
342
     */
343 41
    public function getHasSorting()
344
    {
345 41
        $path = $this->prefixWithNamespace('sort');
346 41
        return $this->argumentsAccessor->has($path);
347
    }
348
349
    /**
350
     * Returns the sorting string in the url e.g. title asc.
351
     *
352
     * @return string
353
     */
354 41
    public function getSorting()
355
    {
356 41
        $path = $this->prefixWithNamespace('sort');
357 41
        return $this->argumentsAccessor->get($path, '');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->argumentsAccessor->get($path, '') also could return the type array which is incompatible with the documented return type string.
Loading history...
358
    }
359
360
    /**
361
     * Helper function to get the sorting configuration name or direction.
362
     *
363
     * @param int $index
364
     * @return string
365
     */
366 41
    protected function getSortingPart($index)
367
    {
368 41
        $sorting = $this->getSorting();
369 41
        if ($sorting === '') {
370 41
            return null;
371
        }
372
373
        $parts = explode(' ', $sorting);
374
        return isset($parts[$index]) ? $parts[$index] : null;
375
    }
376
377
    /**
378
     * Returns the sorting configuration name that is currently used.
379
     *
380
     * @return string
381
     */
382 41
    public function getSortingName()
383
    {
384 41
        return $this->getSortingPart(0);
385
    }
386
387
    /**
388
     * Returns the sorting direction that is currently used.
389
     *
390
     * @return string
391
     */
392 41
    public function getSortingDirection()
393
    {
394 41
        return mb_strtolower($this->getSortingPart(1));
395
    }
396
397
    /**
398
     * @return SearchRequest
399
     */
400 32
    public function removeSorting()
401
    {
402 32
        $path = $this->prefixWithNamespace('sort');
403 32
        $this->argumentsAccessor->reset($path);
404 32
        $this->stateChanged = true;
405 32
        return $this;
406
    }
407
408
    /**
409
     * @param string $sortingName
410
     * @param string $direction (asc or desc)
411
     *
412
     * @return SearchRequest
413
     */
414 32
    public function setSorting($sortingName, $direction = 'asc')
415
    {
416 32
        $value = $sortingName . ' ' . $direction;
417 32
        $path = $this->prefixWithNamespace('sort');
418 32
        $this->argumentsAccessor->set($path, $value);
419 32
        $this->stateChanged = true;
420 32
        return $this;
421
    }
422
423
    /**
424
     * Method to set the paginated page of the search
425
     *
426
     * @param int $page
427
     * @return SearchRequest
428
     */
429 13
    public function setPage($page)
430
    {
431 13
        $this->stateChanged = true;
432 13
        $path = $this->prefixWithNamespace('page');
433 13
        $this->argumentsAccessor->set($path, $page);
434
        // use initial url by switching back to page 0
435 13
        if ($page === 0) {
436 13
            $this->argumentsAccessor->reset($path);
437
        }
438 13
        return $this;
439
    }
440
441
    /**
442
     * Returns the passed page.
443
     *
444
     * @return int|null
445
     */
446 43
    public function getPage()
447
    {
448 43
        $path = $this->prefixWithNamespace('page');
449 43
        return $this->argumentsAccessor->get($path);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->argumentsAccessor->get($path) also could return the type array which is incompatible with the documented return type integer|null.
Loading history...
450
    }
451
452
    /**
453
     * Can be used to reset all groupPages.
454
     *
455
     * @return SearchRequest
456
     */
457 31
    public function removeAllGroupItemPages(): SearchRequest
458
    {
459 31
        $path = $this->prefixWithNamespace('groupPage');
460 31
        $this->argumentsAccessor->reset($path);
461
462 31
        return $this;
463
    }
464
465
    /**
466
     * Can be used to paginate within a groupItem.
467
     *
468
     * @param string $groupName e.g. type
469
     * @param string $groupItemValue e.g. pages
470
     * @param int $page
471
     * @return SearchRequest
472
     */
473
    public function setGroupItemPage(string $groupName, string $groupItemValue, int $page): SearchRequest
474
    {
475
        $this->stateChanged = true;
476
        $escapedValue = $this->getEscapedGroupItemValue($groupItemValue);
477
        $path = $this->prefixWithNamespace('groupPage:' . $groupName . ':' . $escapedValue);
478
        $this->argumentsAccessor->set($path, $page);
479
        return $this;
480
    }
481
482
    /**
483
     * Retrieves the current page for this group item.
484
     *
485
     * @param string $groupName
486
     * @param string $groupItemValue
487
     * @return int
488
     */
489
    public function getGroupItemPage(string $groupName, string $groupItemValue): int
490
    {
491
        $escapedValue = $this->getEscapedGroupItemValue($groupItemValue);
492
        $path = $this->prefixWithNamespace('groupPage:' . $groupName . ':' . $escapedValue);
493
        return max(1, (int)$this->argumentsAccessor->get($path));
494
    }
495
496
    /**
497
     * Removes all non alphanumeric values from the groupItem value to have a valid array key.
498
     *
499
     * @param string $groupItemValue
500
     * @return string
501
     */
502
    protected function getEscapedGroupItemValue(string $groupItemValue)
503
    {
504
        return preg_replace("/[^A-Za-z0-9]/", '', $groupItemValue);
505
    }
506
507
    /**
508
     * Retrieves the highest page of the groups.
509
     *
510
     * @return int
511
     */
512
    public function getHighestGroupPage()
513
    {
514
        $max = 1;
515
        $path = $this->prefixWithNamespace('groupPage');
516
        $groupPages = $this->argumentsAccessor->get($path, []);
517
        foreach ($groupPages as $groups) {
518
            if (!is_array($groups)) continue;
519
            foreach ($groups as $groupItemPage) {
520
                if ($groupItemPage > $max) {
521
                    $max = $groupItemPage;
522
                }
523
            }
524
        }
525
526
        return $max;
527
    }
528
529
    /**
530
     * Method to overwrite the query string.
531
     *
532
     * @param string $rawQueryString
533
     * @return SearchRequest
534
     */
535 41
    public function setRawQueryString($rawQueryString)
536
    {
537 41
        $this->stateChanged = true;
538 41
        $path = $this->prefixWithNamespace('q');
539 41
        $this->argumentsAccessor->set($path, $rawQueryString);
540 41
        return $this;
541
    }
542
543
    /**
544
     * Returns the passed rawQueryString.
545
     *
546
     * @return string|null
547
     */
548 43
    public function getRawUserQuery()
549
    {
550 43
        $path = $this->prefixWithNamespace('q');
551 43
        $query = $this->argumentsAccessor->get($path, null);
552 43
        return is_null($query) ? $query : (string)$query;
553
    }
554
555
    /**
556
     * Method to check if the query string is an empty string
557
     * (also empty string or whitespaces only are handled as empty).
558
     *
559
     * When no query string is set (null) the method returns false.
560
     * @return bool
561
     */
562 42
    public function getRawUserQueryIsEmptyString()
563
    {
564 42
        $path = $this->prefixWithNamespace('q');
565 42
        $query = $this->argumentsAccessor->get($path, null);
566
567 42
        if ($query === null) {
568 4
            return false;
569
        }
570
571 38
        if (trim($query) === '') {
0 ignored issues
show
Bug introduced by
It seems like $query can also be of type array; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

571
        if (trim(/** @scrutinizer ignore-type */ $query) === '') {
Loading history...
572
            return true;
573
        }
574
575 38
        return false;
576
    }
577
578
    /**
579
     * This method returns true when no querystring is present at all.
580
     * Which means no search by the user was triggered
581
     *
582
     * @return bool
583
     */
584 43
    public function getRawUserQueryIsNull()
585
    {
586 43
        $path = $this->prefixWithNamespace('q');
587 43
        $query = $this->argumentsAccessor->get($path, null);
588 43
        return $query === null;
589
    }
590
591
    /**
592
     * Sets the results per page that are used during search.
593
     *
594
     * @param int $resultsPerPage
595
     * @return SearchRequest
596
     */
597 43
    public function setResultsPerPage($resultsPerPage)
598
    {
599 43
        $path = $this->prefixWithNamespace('resultsPerPage');
600 43
        $this->argumentsAccessor->set($path, $resultsPerPage);
601 43
        $this->stateChanged = true;
602
603 43
        return $this;
604
    }
605
606
    /**
607
     * @return bool
608
     */
609
    public function getStateChanged()
610
    {
611
        return $this->stateChanged;
612
    }
613
614
    /**
615
     * Returns the passed resultsPerPage value
616
     * @return int|null
617
     */
618 43
    public function getResultsPerPage()
619
    {
620 43
        $path = $this->prefixWithNamespace('resultsPerPage');
621 43
        return $this->argumentsAccessor->get($path);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->argumentsAccessor->get($path) also could return the type array which is incompatible with the documented return type integer|null.
Loading history...
622
    }
623
624
    /**
625
     * Allows to set additional filters that are used on time and not transported during the request.
626
     *
627
     * @param array $additionalFilters
628
     * @return SearchRequest
629
     */
630 2
    public function setAdditionalFilters($additionalFilters)
631
    {
632 2
        $path = $this->prefixWithNamespace('additionalFilters');
633 2
        $this->argumentsAccessor->set($path, $additionalFilters);
634 2
        $this->stateChanged = true;
635
636 2
        return $this;
637
    }
638
639
    /**
640
     * Retrieves the addtional filters that have been set
641
     *
642
     * @return array
643
     */
644 42
    public function getAdditionalFilters()
645
    {
646 42
        $path = $this->prefixWithNamespace('additionalFilters');
647 42
        return $this->argumentsAccessor->get($path, []);
648
    }
649
650
    /**
651
     * @return int
652
     */
653 34
    public function getContextSystemLanguageUid()
654
    {
655 34
        return $this->contextSystemLanguageUid;
656
    }
657
658
    /**
659
     * @return int
660
     */
661 34
    public function getContextPageUid()
662
    {
663 34
        return $this->contextPageUid;
664
    }
665
666
    /**
667
     * Get contextTypoScriptConfiguration
668
     *
669
     * @return TypoScriptConfiguration
670
     */
671 44
    public function getContextTypoScriptConfiguration(): ?TypoScriptConfiguration
672
    {
673 44
        return $this->contextTypoScriptConfiguration;
674
    }
675
676
    /**
677
     * Assigns the last known persistedArguments and restores their state.
678
     *
679
     * @return SearchRequest
680
     */
681 44
    public function reset(): SearchRequest
682
    {
683 44
        $this->argumentsAccessor = new ArrayAccessor($this->persistedArguments);
684 44
        $this->stateChanged = false;
685 44
        $this->activeFacetContainer = new UrlFacetContainer(
686 44
            $this->argumentsAccessor,
687 44
            $this->argumentNameSpace ?? self::DEFAULT_PLUGIN_NAMESPACE,
688 44
            $this->contextTypoScriptConfiguration === null ?
689
                UrlFacetContainer::PARAMETER_STYLE_INDEX :
690 44
                $this->contextTypoScriptConfiguration->getSearchFacetingUrlParameterStyle()
691
        );
692
693
        // If the default of sorting parameter should be true, a modification of this condition is needed.
694
        // If instance of contextTypoScriptConfiguration is not TypoScriptConfiguration the sort should be enabled too
695 44
        if ($this->contextTypoScriptConfiguration instanceof TypoScriptConfiguration &&
696 44
                $this->contextTypoScriptConfiguration->getSearchFacetingUrlParameterSort(false)) {
697 1
            $this->activeFacetContainer->enableSort();
698
        }
699
700 44
        return $this;
701
    }
702
703
    /**
704
     * This can be used to start a new sub request, e.g. for a faceted search.
705
     *
706
     * @param bool $onlyPersistentArguments
707
     * @return SearchRequest
708
     */
709 35
    public function getCopyForSubRequest(bool $onlyPersistentArguments = true): SearchRequest
710
    {
711 35
        if (!$onlyPersistentArguments) {
712
            // create a new request with all data
713
            $argumentsArray = $this->argumentsAccessor->getData();
714
            return new SearchRequest(
715
                $argumentsArray,
716
                $this->contextPageUid,
717
                $this->contextSystemLanguageUid,
718
                $this->contextTypoScriptConfiguration
719
            );
720
        }
721
722 35
        $arguments = new ArrayAccessor();
723 35
        foreach ($this->persistentArgumentsPaths as $persistentArgumentPath) {
724 35
            if ($this->argumentsAccessor->has($persistentArgumentPath)) {
725 31
                $arguments->set($persistentArgumentPath, $this->argumentsAccessor->get($persistentArgumentPath));
726
            }
727
        }
728
729 35
        return new SearchRequest(
730 35
            $arguments->getData(),
731 35
            $this->contextPageUid,
732 35
            $this->contextSystemLanguageUid,
733 35
            $this->contextTypoScriptConfiguration
734
        );
735
    }
736
737
    /**
738
     * @return string
739
     */
740 28
    public function getArgumentNamespace(): string
741
    {
742 28
        return $this->argumentNameSpace;
743
    }
744
745
    /**
746
     * @return array
747
     */
748 35
    public function getAsArray(): array
749
    {
750 35
        return $this->argumentsAccessor->getData();
751
    }
752
753
    /**
754
     * Returns only the arguments as array.
755
     *
756
     * @return array
757
     */
758 36
    public function getArguments(): array
759
    {
760 36
        return $this->argumentsAccessor->get($this->argumentNameSpace) ?? [];
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->argumentsA...ntNameSpace) ?? array() could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
761
    }
762
}
763