Skip to content

Commit a52e34f

Browse files
Style analysis for examples
1 parent d6a55d2 commit a52e34f

File tree

171 files changed

+1496
-1455
lines changed

Some content is hidden

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

171 files changed

+1496
-1455
lines changed

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ preset: symfony
22

33
finder:
44
path:
5+
- "examples"
56
- "src"
67
- "tests"
78

docs/client-and-adapters.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ Since Solarium 5.2 any [PSR-14](https://www.php-fig.org/psr/psr-14/) compatible
5252
```php
5353
<?php
5454

55-
require_once(__DIR__.'/init.php');
55+
require_once __DIR__.'/init.php';
56+
5657
htmlHeader();
5758

5859
// create a Symfony EventDispatcher instance
@@ -85,7 +86,8 @@ This is the standard Solarium adapter. It supports the most features (for instan
8586
```php
8687
<?php
8788

88-
require_once(__DIR__.'/init.php');
89+
require_once __DIR__.'/init.php';
90+
8991
htmlHeader();
9092

9193
// create a cURL adapter instance
@@ -132,7 +134,8 @@ This adapter has no dependencies on other classes or any special PHP extensions
132134
```php
133135
<?php
134136

135-
require_once(__DIR__.'/init.php');
137+
require_once __DIR__.'/init.php';
138+
136139
htmlHeader();
137140

138141
// create an HTTP adapter instance
@@ -184,7 +187,8 @@ composer require nyholm/psr7
184187
```php
185188
<?php
186189

187-
require_once(__DIR__.'/init.php');
190+
require_once __DIR__.'/init.php';
191+
188192
htmlHeader();
189193

190194
// create a PSR-18 adapter instance

docs/customizing-solarium.md

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ The example code shows how to do this. It also shows how to generate the URI for
2828
```php
2929
<?php
3030

31-
require_once(__DIR__.'/init.php');
31+
require_once __DIR__.'/init.php';
32+
3233
htmlHeader();
3334

3435
// This example shows how to manually execute the query flow.
3536
// By doing this manually you can customize data in between any step (although a plugin might be better for this)
3637
// And you can use only a part of the flow. You could for instance use the query object and request builder,
3738
// but execute the request in your own code.
3839

39-
4040
// create a client instance
4141
$client = new Solarium\Client($adapter, $eventDispatcher, $config);
4242

@@ -48,7 +48,7 @@ $request = $client->createRequest($query);
4848

4949
// you can now use the request object for getting an uri (e.g. to use in your own code)
5050
// or you could modify the request object
51-
echo 'Request URI: ' . $request->getUri() . '<br/>';
51+
echo 'Request URI: '.$request->getUri().'<br/>';
5252

5353
// you can still execute the request using the client and get a 'raw' response object
5454
$response = $client->executeRequest($request);
@@ -61,7 +61,6 @@ echo 'NumFound: '.$result->getNumFound();
6161

6262
// show documents using the resultset iterator
6363
foreach ($result as $document) {
64-
6564
echo '<hr/><table>';
6665

6766
// the documents are also iterable, to get all fields
@@ -71,7 +70,7 @@ foreach ($result as $document) {
7170
$value = implode(', ', $value);
7271
}
7372

74-
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
73+
echo '<tr><th>'.$field.'</th><td>'.$value.'</td></tr>';
7574
}
7675

7776
echo '</table>';
@@ -100,54 +99,55 @@ This example shows all available events and how to use the events to create a ve
10099
```php
101100
<?php
102101

103-
require_once(__DIR__.'/init.php');
104102
use Solarium\Core\Event\Events;
105103
use Solarium\Core\Event\PreExecuteRequest;
106104

105+
require_once __DIR__.'/init.php';
106+
107107
// this very simple plugin shows a timing for each event and display some request debug info
108108
class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
109109
{
110110
protected float $start;
111-
protected array $output = array();
111+
protected array $output = [];
112112

113113
// This method is called when the plugin is registered with the client.
114114
protected function initPluginType(): void
115115
{
116116
$this->start = microtime(true);
117117

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

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

147147
protected function timer(string $event): void
148148
{
149149
$time = round(microtime(true) - $this->start, 5);
150-
$this->output[] = '['.$time.'] ' . $event;
150+
$this->output[] = '['.$time.'] '.$event;
151151
}
152152

153153
public function display(): void
@@ -174,7 +174,7 @@ class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
174174
// this dummy param will be visible in the debug output but will also be used in the actual Solr request
175175
$event->getRequest()->addParam('dummyparam', 'dummyvalue');
176176

177-
$this->output[] = 'Request URI: ' . $event->getRequest()->getUri();
177+
$this->output[] = 'Request URI: '.$event->getRequest()->getUri();
178178
}
179179

180180
public function postExecuteRequest(): void
@@ -213,7 +213,6 @@ class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
213213
}
214214
}
215215

216-
217216
htmlHeader();
218217

219218
// create a client instance and register the plugin
@@ -227,15 +226,14 @@ $resultset = $client->select($query);
227226

228227
echo 'NumFound: '.$resultset->getNumFound();
229228
foreach ($resultset as $document) {
230-
231229
echo '<hr/><table>';
232230

233231
foreach ($document as $field => $value) {
234232
if (is_array($value)) {
235233
$value = implode(', ', $value);
236234
}
237235

238-
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
236+
echo '<tr><th>'.$field.'</th><td>'.$value.'</td></tr>';
239237
}
240238

241239
echo '</table>';
@@ -253,11 +251,12 @@ The second example shows how to replace the built-in select querytype with a cus
253251
```php
254252
<?php
255253

256-
require_once(__DIR__.'/init.php');
257254
use Solarium\Client;
258255
use Solarium\Core\Plugin\AbstractPlugin;
259256
use Solarium\QueryType\Select\Query\Query as Select;
260257

258+
require_once __DIR__.'/init.php';
259+
261260
// This is a custom query class that could have some customized logic
262261
class MyQuery extends Select
263262
{
@@ -276,7 +275,6 @@ class QueryCustomizer extends AbstractPlugin
276275
}
277276
}
278277

279-
280278
htmlHeader();
281279

282280
// create a client instance and register the plugin
@@ -287,21 +285,20 @@ $client->registerPlugin('querycustomizer', 'QueryCustomizer');
287285
$query = $client->createSelect();
288286

289287
// check the query class, it should be our custom query class
290-
echo 'Query class: ' . get_class($query) . '<br/>';
288+
echo 'Query class: '.get_class($query).'<br/>';
291289

292290
// execute the query and display the results
293291
$resultset = $client->select($query);
294292
echo 'NumFound: '.$resultset->getNumFound();
295293
foreach ($resultset as $document) {
296-
297294
echo '<hr/><table>';
298295

299296
foreach ($document as $field => $value) {
300297
if (is_array($value)) {
301298
$value = implode(', ', $value);
302299
}
303300

304-
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
301+
echo '<tr><th>'.$field.'</th><td>'.$value.'</td></tr>';
305302
}
306303

307304
echo '</table>';

0 commit comments

Comments
 (0)