Skip to content

Commit bbe6f42

Browse files
committed
[TASK] adapt for EXT:solr 11.1.x
1 parent 0d5d89c commit bbe6f42

File tree

3 files changed

+67
-34
lines changed

3 files changed

+67
-34
lines changed

Classes/Configuration/PluginConfiguration.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,30 @@ class PluginConfiguration
4444
* PluginConfiguration constructor.
4545
* @param array $pluginData
4646
*/
47-
public function __construct($pluginData)
47+
public function __construct(array $pluginData)
4848
{
4949
$this->pluginData = $pluginData;
5050
}
5151

5252
/**
5353
* Returns the flexform value of the plugin that was passed as context plugin.
5454
*
55-
* @param $fieldName
56-
* @return NULL|string
55+
* @param string $fieldName
56+
* @return mixed
5757
*/
58-
protected function getFlexFormValueFromPluginContentObject($fieldName)
58+
protected function getFlexFormValueFromPluginContentObject(string $fieldName)
5959
{
6060
return $this->pluginData[$fieldName];
6161
}
6262

6363
/**
6464
* Returns the maximum items to be shown.
6565
*
66-
* @return integer
66+
* @return int
6767
*/
68-
public function getMaxItems()
68+
public function getMaxItems(): int
6969
{
70-
return $this->getFlexFormValueFromPluginContentObject('maxItems');
70+
return (int)$this->getFlexFormValueFromPluginContentObject('maxItems');
7171
}
7272

7373
/**
@@ -76,7 +76,7 @@ public function getMaxItems()
7676
* @see Configuration/FlexForms/MoreLikeThis.xml//queryStringCreationType
7777
* @return NULL|string
7878
*/
79-
public function getQueryStringCreationType()
79+
public function getQueryStringCreationType(): ?string
8080
{
8181
return $this->getFlexFormValueFromPluginContentObject('queryStringCreationType');
8282
}
@@ -88,7 +88,7 @@ public function getQueryStringCreationType()
8888
*
8989
* @return array
9090
*/
91-
public function getSimilarityFields()
91+
public function getSimilarityFields(): array
9292
{
9393
return GeneralUtility::trimExplode(
9494
',',
@@ -102,11 +102,11 @@ public function getSimilarityFields()
102102
*
103103
* Used to fill: 'mlt.mintf'
104104
*
105-
* @return string
105+
* @return int
106106
*/
107-
public function getMinTermFrequency()
107+
public function getMinTermFrequency(): int
108108
{
109-
return $this->getFlexFormValueFromPluginContentObject('minTermFrequency');
109+
return (int)$this->getFlexFormValueFromPluginContentObject('minTermFrequency');
110110
}
111111

112112
/**
@@ -115,46 +115,46 @@ public function getMinTermFrequency()
115115
*
116116
* Used to fill: 'mlt.mindf'
117117
*
118-
* @return string
118+
* @return int
119119
*/
120-
public function getMinDocumentFrequency()
120+
public function getMinDocumentFrequency(): int
121121
{
122-
return $this->getFlexFormValueFromPluginContentObject('minDocumentFrequency');
122+
return (int)$this->getFlexFormValueFromPluginContentObject('minDocumentFrequency');
123123
}
124124

125125
/**
126126
* Minimum word length below which words will be ignored.
127127
*
128128
* Used to fill: 'mlt.minwl'
129129
*
130-
* @return string
130+
* @return int
131131
*/
132-
public function getMinWordLength()
132+
public function getMinWordLength(): int
133133
{
134-
return $this->getFlexFormValueFromPluginContentObject('minWordLength');
134+
return (int)$this->getFlexFormValueFromPluginContentObject('minWordLength');
135135
}
136136

137137
/**
138138
* Maximum word length above which words will be ignored.
139139
*
140140
* Used to fill: 'mlt.maxwl'
141141
*
142-
* @return string
142+
* @return int
143143
*/
144-
public function getMaxWordLength()
144+
public function getMaxWordLength(): int
145145
{
146-
return $this->getFlexFormValueFromPluginContentObject('maxWordLength');
146+
return (int)$this->getFlexFormValueFromPluginContentObject('maxWordLength');
147147
}
148148

149149
/**
150150
* Maximum number of query terms that will be included in any generated query.
151151
*
152152
* Used to fill: 'mlt.maxqt'
153153
*
154-
* @return string
154+
* @return int
155155
*/
156-
public function getMaxQueryTerms()
156+
public function getMaxQueryTerms(): int
157157
{
158-
return $this->getFlexFormValueFromPluginContentObject('maxQueryTerms');
158+
return (int)$this->getFlexFormValueFromPluginContentObject('maxQueryTerms');
159159
}
160160
}

Classes/Controller/MoreLikeThisController.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
2020
use ApacheSolrForTypo3\Solrmlt\Configuration\PluginConfiguration;
2121
use ApacheSolrForTypo3\Solrmlt\Query\Builder;
22+
use Exception;
2223
use TYPO3\CMS\Core\Context\Context;
2324
use TYPO3\CMS\Core\Utility\GeneralUtility;
2425
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
@@ -61,7 +62,7 @@ class MoreLikeThisController extends ActionController
6162
private $contentObjectRenderer;
6263

6364
/**
64-
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
65+
* @param ConfigurationManagerInterface $configurationManager
6566
* @return void
6667
*/
6768
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
@@ -73,7 +74,7 @@ public function injectConfigurationManager(ConfigurationManagerInterface $config
7374
/**
7475
* @return PluginConfiguration
7576
*/
76-
protected function getPluginConfiguration()
77+
protected function getPluginConfiguration(): PluginConfiguration
7778
{
7879
if ($this->pluginConfiguration == null) {
7980
$flexFormData = $this->contentObjectRenderer->data['pi_flexform'];
@@ -88,7 +89,7 @@ protected function getPluginConfiguration()
8889
/**
8990
* @return TypoScriptFrontendController
9091
*/
91-
protected function getTSFE()
92+
protected function getTSFE(): TypoScriptFrontendController
9293
{
9394
if ($this->typoScriptFrontendController == null) {
9495
$this->typoScriptFrontendController = $GLOBALS['TSFE'];
@@ -100,7 +101,7 @@ protected function getTSFE()
100101
/**
101102
* @return Builder
102103
*/
103-
protected function getQueryBuilder()
104+
protected function getQueryBuilder(): Builder
104105
{
105106
$this->queryBuilder = $this->queryBuilder ?? GeneralUtility::makeInstance(Builder::class);
106107
return $this->queryBuilder;
@@ -109,10 +110,10 @@ protected function getQueryBuilder()
109110
/**
110111
* @return Search
111112
*/
112-
protected function getSearch()
113+
protected function getSearch(): Search
113114
{
114115
if ($this->search === null) {
115-
/** @var \ApacheSolrForTypo3\Solr\ConnectionManager $solrConnection */
116+
/** @var ConnectionManager $solrConnection */
116117
$typoScriptFrontendController = $GLOBALS['TSFE'];
117118
$context = GeneralUtility::makeInstance(Context::class);
118119
$languageUid = (int)$context->getPropertyFromAspect('language', 'id');
@@ -127,6 +128,7 @@ protected function getSearch()
127128
* Shows the results of the configured more like this query.
128129
*
129130
* @return void
131+
* @throws Exception
130132
*/
131133
public function indexAction()
132134
{

Tests/Unit/Query/BuilderTest.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ class BuilderTest extends UnitTest
4848
*/
4949
public function setUp()
5050
{
51-
$this->builder = $this->getMockBuilder(Builder::class)->setMethods(['getSiteHashFilterForTSFE'])->getMock();
51+
$this->builder = $this->getMockBuilder(Builder::class)
52+
->setMethods(
53+
[
54+
'getSiteHashFilterForTSFE'
55+
]
56+
)->getMock();
5257
}
5358

5459
/**
@@ -57,13 +62,39 @@ public function setUp()
5762
public function canSetTheQueryStringFromPageTitle()
5863
{
5964
// we avoid the usage of the Sites::getSiteByPageId()->getDomain call an return a fake domain in our testcase
60-
$this->builder->expects($this->once())->method('getSiteHashFilterForTSFE')->will($this->returnValue('siteHash:localhost'));
65+
$this->builder
66+
->expects($this->once())
67+
->method('getSiteHashFilterForTSFE')
68+
->will($this->returnValue('siteHash:localhost'));
6169

6270
$configurationMock = $this->getDumbMock(PluginConfiguration::class);
63-
$configurationMock->expects($this->once())->method('getSimilarityFields')->will($this->returnValue(array('content')));
71+
$configurationMock
72+
->expects($this->once())
73+
->method('getSimilarityFields')
74+
->will($this->returnValue(['content']));
75+
$configurationMock
76+
->expects($this->once())
77+
->method('getMinTermFrequency')
78+
->will($this->returnValue(7));
79+
$configurationMock
80+
->expects($this->once())
81+
->method('getMinDocumentFrequency')
82+
->will($this->returnValue(7));
83+
$configurationMock
84+
->expects($this->once())
85+
->method('getMinWordLength')
86+
->will($this->returnValue(7));
87+
$configurationMock
88+
->expects($this->once())
89+
->method('getMaxWordLength')
90+
->will($this->returnValue(7));
91+
$configurationMock
92+
->expects($this->once())
93+
->method('getMaxQueryTerms')
94+
->will($this->returnValue(7));
6495

6596
$tsfeMock = $this->getDumbMock(TypoScriptFrontendController::class);
66-
$tsfeMock->page = array('title' => 'fake page title');
97+
$tsfeMock->page = ['title' => 'fake page title'];
6798

6899
$query = $this->builder->build($configurationMock, $tsfeMock);
69100
$this->assertSame('fake page title', $query->getQuery(), 'Querybuilder did not assign expected querystring');

0 commit comments

Comments
 (0)