Skip to content

Commit b9a37db

Browse files
Typed properties
1 parent af81c91 commit b9a37db

File tree

627 files changed

+2618
-4607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

627 files changed

+2618
-4607
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Added `void` return type to `Solarium\Core\Plugin\PluginInterface::deinitPlugin()` method signature
1818
- Added `void` return type to `Solarium\Core\Plugin\AbstractPlugin::initPluginType()` method signature
1919
- Changed return type of some Facets methods from `self`to `static`
20+
- Replaced class property type hints with type declarations
21+
- Added union type declarations to method signatures
22+
- Solarium\Core\Query\Helper::formatDate() throws a `TypeError` instead of returning `false` if called with an incompatibly typed parameter
2023

2124
### Removed
2225
- Solarium\Component\Result\Stats\FacetValue::getFacets(), always returned `null`

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ composer require solarium/solarium
3232

3333
When upgrading from an earlier version, you should be aware of a number of pitfalls.
3434

35+
* [Pitfalls when upgrading to 7.0.0](https://solarium.readthedocs.io/en/stable/getting-started/#pitfalls-when-upgrading-to-700)
3536
* [Pitfall when upgrading to 6.3.6](https://solarium.readthedocs.io/en/stable/getting-started/#pitfall-when-upgrading-to-636)
3637
* [Pitfall when upgrading to 6.3.2](https://solarium.readthedocs.io/en/stable/getting-started/#pitfall-when-upgrading-to-632)
3738
* [Pitfall when upgrading to 6.3](https://solarium.readthedocs.io/en/stable/getting-started/#pitfall-when-upgrading-to-63)

docs/client-and-adapters.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ The cURL adapter supports the use of a proxy. Use `$adapter->setProxy($proxy)` t
107107
You can extend the cURL adapter and override the `createHandle()` method to set additional options you require for the cURL transfer.
108108

109109
```php
110+
use Solarium\Core\Client\Endpoint;
111+
use Solarium\Core\Client\Request;
112+
110113
class MyAdapter extends Solarium\Core\Client\Adapter\Curl
111114
{
112-
public function createHandle($request, $endpoint)
115+
public function createHandle(Request $request, Endpoint $endpoint): \CurlHandle
113116
{
114117
$handle = parent::createHandle($request, $endpoint);
115118

@@ -151,9 +154,12 @@ The HTTP adapter supports the use of a proxy. Use `$adapter->setProxy($proxy)` t
151154
You can extend the HTTP adapter and override the `createContext()` method to set additional options you require for the stream.
152155

153156
```php
157+
use Solarium\Core\Client\Endpoint;
158+
use Solarium\Core\Client\Request;
159+
154160
class MyAdapter extends Solarium\Core\Client\Adapter\Http
155161
{
156-
public function createContext($request, $endpoint)
162+
public function createContext(Request $request, Endpoint $endpoint)
157163
{
158164
$context = parent::createContext($request, $endpoint);
159165

docs/customizing-solarium.md

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -100,73 +100,75 @@ This example shows all available events and how to use the events to create a ve
100100
```php
101101
<?php
102102

103-
require_once(__DIR__.'/init.php');
104103
use Solarium\Core\Event\Events;
104+
use Solarium\Core\Event\PreExecuteRequest;
105+
106+
require_once(__DIR__.'/init.php');
105107

106108
// this very simple plugin shows a timing for each event and display some request debug info
107109
class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
108110
{
109-
protected $start;
110-
protected $output = array();
111+
protected float $start;
112+
protected array $output = [];
111113

112114
// This method is called when the plugin is registered with the client.
113115
protected function initPluginType(): void
114116
{
115117
$this->start = microtime(true);
116118

117119
$dispatcher = $this->client->getEventDispatcher();
118-
$dispatcher->addListener(Events::PRE_CREATE_REQUEST, array($this, 'preCreateRequest'));
119-
$dispatcher->addListener(Events::POST_CREATE_REQUEST, array($this, 'postCreateRequest'));
120-
$dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'));
121-
$dispatcher->addListener(Events::POST_EXECUTE_REQUEST, array($this, 'postExecuteRequest'));
122-
$dispatcher->addListener(Events::PRE_CREATE_RESULT, array($this, 'preCreateResult'));
123-
$dispatcher->addListener(Events::POST_CREATE_RESULT, array($this, 'postCreateResult'));
124-
$dispatcher->addListener(Events::PRE_EXECUTE, array($this, 'preExecute'));
125-
$dispatcher->addListener(Events::POST_EXECUTE, array($this, 'postExecute'));
126-
$dispatcher->addListener(Events::PRE_CREATE_QUERY, array($this, 'preCreateQuery'));
127-
$dispatcher->addListener(Events::POST_CREATE_QUERY, array($this, 'postCreateQuery'));
120+
$dispatcher->addListener(Events::PRE_CREATE_REQUEST, [$this, 'preCreateRequest']);
121+
$dispatcher->addListener(Events::POST_CREATE_REQUEST, [$this, 'postCreateRequest']);
122+
$dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, [$this, 'preExecuteRequest']);
123+
$dispatcher->addListener(Events::POST_EXECUTE_REQUEST, [$this, 'postExecuteRequest']);
124+
$dispatcher->addListener(Events::PRE_CREATE_RESULT, [$this, 'preCreateResult']);
125+
$dispatcher->addListener(Events::POST_CREATE_RESULT, [$this, 'postCreateResult']);
126+
$dispatcher->addListener(Events::PRE_EXECUTE, [$this, 'preExecute']);
127+
$dispatcher->addListener(Events::POST_EXECUTE, [$this, 'postExecute']);
128+
$dispatcher->addListener(Events::PRE_CREATE_QUERY, [$this, 'preCreateQuery']);
129+
$dispatcher->addListener(Events::POST_CREATE_QUERY, [$this, 'postCreateQuery']);
128130
}
129131

130132
// This method is called if the plugin is removed from the client.
131133
public function deinitPlugin(): void
132134
{
133135
$dispatcher = $this->client->getEventDispatcher();
134-
$dispatcher->removeListener(Events::PRE_CREATE_REQUEST, array($this, 'preCreateRequest'));
135-
$dispatcher->removeListener(Events::POST_CREATE_REQUEST, array($this, 'postCreateRequest'));
136-
$dispatcher->removeListener(Events::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'));
137-
$dispatcher->removeListener(Events::POST_EXECUTE_REQUEST, array($this, 'postExecuteRequest'));
138-
$dispatcher->removeListener(Events::PRE_CREATE_RESULT, array($this, 'preCreateResult'));
139-
$dispatcher->removeListener(Events::POST_CREATE_RESULT, array($this, 'postCreateResult'));
140-
$dispatcher->removeListener(Events::PRE_EXECUTE, array($this, 'preExecute'));
141-
$dispatcher->removeListener(Events::POST_EXECUTE, array($this, 'postExecute'));
142-
$dispatcher->removeListener(Events::PRE_CREATE_QUERY, array($this, 'preCreateQuery'));
143-
$dispatcher->removeListener(Events::POST_CREATE_QUERY, array($this, 'postCreateQuery'));
136+
$dispatcher->removeListener(Events::PRE_CREATE_REQUEST, [$this, 'preCreateRequest']);
137+
$dispatcher->removeListener(Events::POST_CREATE_REQUEST, [$this, 'postCreateRequest']);
138+
$dispatcher->removeListener(Events::PRE_EXECUTE_REQUEST, [$this, 'preExecuteRequest']);
139+
$dispatcher->removeListener(Events::POST_EXECUTE_REQUEST, [$this, 'postExecuteRequest']);
140+
$dispatcher->removeListener(Events::PRE_CREATE_RESULT, [$this, 'preCreateResult']);
141+
$dispatcher->removeListener(Events::POST_CREATE_RESULT, [$this, 'postCreateResult']);
142+
$dispatcher->removeListener(Events::PRE_EXECUTE, [$this, 'preExecute']);
143+
$dispatcher->removeListener(Events::POST_EXECUTE, [$this, 'postExecute']);
144+
$dispatcher->removeListener(Events::PRE_CREATE_QUERY, [$this, 'preCreateQuery']);
145+
$dispatcher->removeListener(Events::POST_CREATE_QUERY, [$this, 'postCreateQuery']);
144146
}
145147

146-
protected function timer($event)
148+
protected function timer(string $event): void
147149
{
148150
$time = round(microtime(true) - $this->start, 5);
149151
$this->output[] = '['.$time.'] ' . $event;
150152
}
151153

152-
public function display()
154+
public function display(): void
153155
{
154156
echo implode('<br/>', $this->output);
155157
}
156158

157-
public function preCreateRequest()
159+
public function preCreateRequest(): void
158160
{
159161
$this->timer('preCreateRequest');
160162
}
161163

162-
public function postCreateRequest()
164+
public function postCreateRequest(): void
163165
{
164166
$this->timer('postCreateRequest');
165167
}
166168

167169
// This method uses the available param(s) (see plugin abstract class).
168170
// You can access or modify data this way.
169-
public function preExecuteRequest($event)
171+
public function preExecuteRequest(PreExecuteRequest $event): void
170172
{
171173
$this->timer('preExecuteRequest');
172174

@@ -176,37 +178,37 @@ class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
176178
$this->output[] = 'Request URI: ' . $event->getRequest()->getUri();
177179
}
178180

179-
public function postExecuteRequest()
181+
public function postExecuteRequest(): void
180182
{
181183
$this->timer('postExecuteRequest');
182184
}
183185

184-
public function preCreateResult()
186+
public function preCreateResult(): void
185187
{
186188
$this->timer('preCreateResult');
187189
}
188190

189-
public function postCreateResult()
191+
public function postCreateResult(): void
190192
{
191193
$this->timer('postCreateResult');
192194
}
193195

194-
public function preExecute()
196+
public function preExecute(): void
195197
{
196198
$this->timer('preExecute');
197199
}
198200

199-
public function postExecute()
201+
public function postExecute(): void
200202
{
201203
$this->timer('postExecute');
202204
}
203205

204-
public function preCreateQuery()
206+
public function preCreateQuery(): void
205207
{
206208
$this->timer('preCreateResult');
207209
}
208210

209-
public function postCreateQuery()
211+
public function postCreateQuery(): void
210212
{
211213
$this->timer('postCreateResult');
212214
}
@@ -252,11 +254,12 @@ The second example shows how to replace the built-in select querytype with a cus
252254
```php
253255
<?php
254256

255-
require_once(__DIR__.'/init.php');
256257
use Solarium\Client;
257258
use Solarium\Core\Plugin\AbstractPlugin;
258259
use Solarium\QueryType\Select\Query\Query as Select;
259260

261+
require_once(__DIR__.'/init.php');
262+
260263
// This is a custom query class that could have some customized logic
261264
class MyQuery extends Select
262265
{
@@ -266,7 +269,7 @@ class MyQuery extends Select
266269
// this very simple plugin that modifies the default querytype mapping
267270
class QueryCustomizer extends AbstractPlugin
268271
{
269-
public function initPlugin($client, $options)
272+
public function initPlugin($client, array $options): void
270273
{
271274
$client->registerQueryType(
272275
Client::QUERY_SELECT,

docs/documents.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ $doc2->name = 'testdoc-2';
112112
$doc2->price = 340;
113113

114114
// add the documents and a commit command to the update query
115-
$update->addDocuments(array($doc1, $doc2));
115+
$update->addDocuments([$doc1, $doc2]);
116116
$update->addCommit();
117117

118118
// this executes the query and returns the result
@@ -158,36 +158,36 @@ $update = $client->createUpdate();
158158
$doc1 = $update->createDocument();
159159
$doc1->id = 123;
160160
$doc1->name = 'testdoc-1';
161-
$doc1->childdocs = array(
162-
array(
161+
$doc1->childdocs = [
162+
[
163163
'id' => 1230,
164164
'name' => 'childdoc-1-1',
165165
'price' => 465,
166-
),
167-
array(
166+
],
167+
[
168168
'id' => 1231,
169169
'name' => 'childdoc-1-2',
170170
'price' => 545,
171-
),
172-
);
171+
],
172+
];
173173

174174
// and a second one where child documents are added one by one
175175
$doc2 = $update->createDocument();
176176
$doc2->setField('id', 124);
177177
$doc2->setField('name', 'testdoc-2');
178-
$doc2->addField('childdocs', array(
178+
$doc2->addField('childdocs', [
179179
'id' => 1240,
180180
'name' => 'childdoc-2-1',
181181
'price' => 360,
182-
));
183-
$doc2->addField('childdocs', array(
182+
]);
183+
$doc2->addField('childdocs', [
184184
'id' => 1241,
185185
'name' => 'childdoc-2-2',
186186
'price' => 398,
187-
));
187+
]);
188188

189189
// add the documents and a commit command to the update query
190-
$update->addDocuments(array($doc1, $doc2));
190+
$update->addDocuments([$doc1, $doc2]);
191191
$update->addCommit();
192192

193193
// this executes the query and returns the result

docs/getting-started.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,28 @@ Upgrading
9090

9191
When upgrading from an earlier version, you should be aware of a number of pitfalls.
9292

93-
### Pitfall when upgrading to 6.3.8
93+
### Pitfalls when upgrading to 7.0.0
94+
95+
Solarium 7.0.0 added type declarations throughout the codebase for:
96+
- class properties
97+
- union types in method signatures
98+
- `void` return types
9499

95100
Plugins extending from `Solarium\Core\Plugin\AbstractPlugin` must add `void` return types to the signatures for
96101
the following methods (when defined):
97102
- `initPlugin()`
98103
- `deinitPlugin()`
99104
- `initPluginType()`
100105

106+
Any other classes extending from the codebase will run into fatal errors if they violate PHP's
107+
[variance](https://www.php.net/manual/en/language.oop5.variance.php) rules. Inherited properties
108+
must add an invariant type declaration. Inherited methods that didn't declare a return type must
109+
add one that's covariant. Method parameters don't need to have a type declaration, but if they
110+
do have one it must be contravariant.
111+
112+
Code that calls a method with parameters of an incompatible type will result in a `TypeError` where
113+
they were previously coerced into a compatible type by PHP's type juggling.
114+
101115
### Pitfall when upgrading to 6.3.6
102116

103117
Using a config object is no longer supported. You have to convert it to an array before passing
@@ -289,9 +303,9 @@ The `$config` array has the following contents:
289303
```php
290304
<?php
291305

292-
$config = array(
293-
'endpoint' => array(
294-
'localhost' => array(
306+
$config = [
307+
'endpoint' => [
308+
'localhost' => [
295309
'host' => '127.0.0.1',
296310
'port' => 8983,
297311
'path' => '/',
@@ -300,9 +314,9 @@ $config = array(
300314
// 'collection' => 'techproducts',
301315
// Set the `hostContext` for the Solr web application if it's not the default 'solr':
302316
// 'context' => 'solr',
303-
)
304-
)
305-
);
317+
],
318+
],
319+
];
306320
```
307321

308322
### Selecting documents
@@ -491,7 +505,7 @@ $doc2->name = 'testdoc-2';
491505
$doc2->price = 340;
492506

493507
// add the documents and a commit command to the update query
494-
$update->addDocuments(array($doc1, $doc2));
508+
$update->addDocuments([$doc1, $doc2]);
495509
$update->addCommit();
496510

497511
// this executes the query and returns the result

0 commit comments

Comments
 (0)