@@ -39,9 +39,9 @@ |
||
39 | 39 | class AlgoliaManager |
40 | 40 | { |
41 | 41 | /** |
42 | - * Size for the chunks used in reindexing methods. |
|
43 | - */ |
|
44 | - const CHUNK_SIZE = 500; |
|
42 | + * Size for the chunks used in reindexing methods. |
|
43 | + */ |
|
44 | + const CHUNK_SIZE = 500; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @var AlgoliaFactory |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @param ActiveRecordFactory $activeRecordFactory |
82 | 82 | * @param ActiveQueryChunker $activeQueryChunker |
83 | 83 | */ |
84 | - public function __construct( |
|
84 | + public function __construct ( |
|
85 | 85 | Client $client, |
86 | 86 | ActiveRecordFactory $activeRecordFactory, |
87 | 87 | ActiveQueryChunker $activeQueryChunker |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return Client |
98 | 98 | */ |
99 | - public function getClient() |
|
99 | + public function getClient () |
|
100 | 100 | { |
101 | 101 | return $this->client; |
102 | 102 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param string $env |
108 | 108 | */ |
109 | - public function setEnv($env) |
|
109 | + public function setEnv ($env) |
|
110 | 110 | { |
111 | 111 | $this->env = $env; |
112 | 112 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return null|string |
118 | 118 | */ |
119 | - public function getEnv() |
|
119 | + public function getEnv () |
|
120 | 120 | { |
121 | 121 | return $this->env; |
122 | 122 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return array |
130 | 130 | */ |
131 | - public function pushToIndices(SearchableInterface $searchableModel) |
|
131 | + public function pushToIndices (SearchableInterface $searchableModel) |
|
132 | 132 | { |
133 | 133 | $indices = $this->initIndices($searchableModel); |
134 | 134 | $record = $searchableModel->getAlgoliaRecord(); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return array |
147 | 147 | */ |
148 | - public function pushMultipleToIndices(array $searchableModels) |
|
148 | + public function pushMultipleToIndices (array $searchableModels) |
|
149 | 149 | { |
150 | 150 | $algoliaRecords = $this->getAlgoliaRecordsFromSearchableModelArray($searchableModels); |
151 | 151 | $indices = $this->initIndices($searchableModels[0]); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * |
163 | 163 | * @return array |
164 | 164 | */ |
165 | - public function updateInIndices(SearchableInterface $searchableModel) |
|
165 | + public function updateInIndices (SearchableInterface $searchableModel) |
|
166 | 166 | { |
167 | 167 | $indices = $this->initIndices($searchableModel); |
168 | 168 | $record = $searchableModel->getAlgoliaRecord(); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @return array |
182 | 182 | */ |
183 | - public function updateMultipleInIndices(array $searchableModels) |
|
183 | + public function updateMultipleInIndices (array $searchableModels) |
|
184 | 184 | { |
185 | 185 | $algoliaRecords = $this->getAlgoliaRecordsFromSearchableModelArray($searchableModels); |
186 | 186 | $indices = $this->initIndices($searchableModels[0]); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return array |
199 | 199 | * @throws \InvalidArgumentException |
200 | 200 | */ |
201 | - public function removeFromIndices(SearchableInterface $searchableModel) |
|
201 | + public function removeFromIndices (SearchableInterface $searchableModel) |
|
202 | 202 | { |
203 | 203 | $indices = $indices = $this->initIndices($searchableModel); |
204 | 204 | $objectID = $searchableModel->getObjectID(); |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @return array |
217 | 217 | * @throws \InvalidArgumentException |
218 | 218 | */ |
219 | - public function removeMultipleFromIndices(array $searchableModels) |
|
219 | + public function removeMultipleFromIndices (array $searchableModels) |
|
220 | 220 | { |
221 | 221 | $algoliaRecords = $this->getAlgoliaRecordsFromSearchableModelArray($searchableModels); |
222 | 222 | $indices = $this->initIndices($searchableModels[0]); |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @return array |
238 | 238 | */ |
239 | - public function reindex($className) |
|
239 | + public function reindex ($className) |
|
240 | 240 | { |
241 | 241 | $this->checkImplementsSearchableInterface($className); |
242 | 242 | $activeRecord = $this->activeRecordFactory->make($className); |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @throws \InvalidArgumentException |
267 | 267 | * @return array |
268 | 268 | */ |
269 | - public function reindexOnly(array $searchableModels) |
|
269 | + public function reindexOnly (array $searchableModels) |
|
270 | 270 | { |
271 | 271 | $records = $this->getAlgoliaRecordsFromSearchableModelArray($searchableModels); |
272 | 272 | $indices = $this->initIndices($searchableModels[0]); |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | * |
285 | 285 | * @return array |
286 | 286 | */ |
287 | - public function reindexByActiveQuery(ActiveQueryInterface $activeQuery) |
|
287 | + public function reindexByActiveQuery (ActiveQueryInterface $activeQuery) |
|
288 | 288 | { |
289 | 289 | $indices = null; |
290 | 290 | $records = $this->activeQueryChunker->chunk( |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @throws \InvalidArgumentException |
317 | 317 | * @return array |
318 | 318 | */ |
319 | - public function clearIndices($className) |
|
319 | + public function clearIndices ($className) |
|
320 | 320 | { |
321 | 321 | $this->checkImplementsSearchableInterface($className); |
322 | 322 | /** @var SearchableInterface $activeRecord */ |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | * |
338 | 338 | * @return array |
339 | 339 | */ |
340 | - public function search($className, $query, array $searchParameters = null) |
|
340 | + public function search ($className, $query, array $searchParameters = null) |
|
341 | 341 | { |
342 | 342 | $this->checkImplementsSearchableInterface($className); |
343 | 343 | /* @var SearchableInterface $activeRecord */ |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * |
358 | 358 | * @return mixed |
359 | 359 | */ |
360 | - public function __call($method, $parameters) |
|
360 | + public function __call ($method, $parameters) |
|
361 | 361 | { |
362 | 362 | return \call_user_func_array([$this->getClient(), $method], $parameters); |
363 | 363 | } |
@@ -367,11 +367,11 @@ discard block |
||
367 | 367 | * |
368 | 368 | * @param string $class Either name or instance of the class to be checked. |
369 | 369 | */ |
370 | - private function checkImplementsSearchableInterface($class) |
|
370 | + private function checkImplementsSearchableInterface ($class) |
|
371 | 371 | { |
372 | 372 | $reflectionClass = new \ReflectionClass($class); |
373 | 373 | |
374 | - if (! $reflectionClass->implementsInterface(SearchableInterface::class)) { |
|
374 | + if ( ! $reflectionClass->implementsInterface(SearchableInterface::class)) { |
|
375 | 375 | throw new \InvalidArgumentException("The class: {$reflectionClass->name} doesn't implement leinonen\\Yii2Algolia\\SearchableInterface"); |
376 | 376 | } |
377 | 377 | } |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * |
384 | 384 | * @return Index[] |
385 | 385 | */ |
386 | - private function initIndices(SearchableInterface $searchableModel) |
|
386 | + private function initIndices (SearchableInterface $searchableModel) |
|
387 | 387 | { |
388 | 388 | $indexNames = $searchableModel->getIndices(); |
389 | 389 | |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | * |
406 | 406 | * @return array |
407 | 407 | */ |
408 | - private function getAlgoliaRecordsFromSearchableModelArray(array $searchableModels) |
|
408 | + private function getAlgoliaRecordsFromSearchableModelArray (array $searchableModels) |
|
409 | 409 | { |
410 | 410 | if (empty($searchableModels)) { |
411 | 411 | throw new \InvalidArgumentException('The given array should not be empty'); |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $this->checkImplementsSearchableInterface($arrayType); |
417 | 417 | |
418 | 418 | $algoliaRecords = \array_map(function (SearchableInterface $searchableModel) use ($arrayType) { |
419 | - if (! $searchableModel instanceof $arrayType) { |
|
419 | + if ( ! $searchableModel instanceof $arrayType) { |
|
420 | 420 | throw new \InvalidArgumentException('The given array should not contain multiple different classes'); |
421 | 421 | } |
422 | 422 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | * |
438 | 438 | * @return mixed |
439 | 439 | */ |
440 | - private function reindexAtomically(Index $index, array $algoliaRecords) |
|
440 | + private function reindexAtomically (Index $index, array $algoliaRecords) |
|
441 | 441 | { |
442 | 442 | $temporaryIndexName = 'tmp_' . $index->indexName; |
443 | 443 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | * |
462 | 462 | * @return array The response as an array in format of ['indexName' => $responseFromAlgoliaClient] |
463 | 463 | */ |
464 | - private function processIndices($indices, callable $callback) |
|
464 | + private function processIndices ($indices, callable $callback) |
|
465 | 465 | { |
466 | 466 | $response = []; |
467 | 467 |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param null|array $hostsArray The list of hosts that you have received for the service |
33 | 33 | * @param array $options |
34 | 34 | */ |
35 | - public function __construct($applicationId, $apiKey, $hostsArray = null, $options = []) |
|
35 | + public function __construct ($applicationId, $apiKey, $hostsArray = null, $options = []) |
|
36 | 36 | { |
37 | 37 | $this->applicationId = $applicationId; |
38 | 38 | $this->apiKey = $apiKey; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * @return string |
45 | 45 | */ |
46 | - public function getApplicationId() |
|
46 | + public function getApplicationId () |
|
47 | 47 | { |
48 | 48 | return $this->applicationId; |
49 | 49 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * @return string |
53 | 53 | */ |
54 | - public function getApiKey() |
|
54 | + public function getApiKey () |
|
55 | 55 | { |
56 | 56 | return $this->apiKey; |
57 | 57 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | /** |
60 | 60 | * @return array|null |
61 | 61 | */ |
62 | - public function getHostsArray() |
|
62 | + public function getHostsArray () |
|
63 | 63 | { |
64 | 64 | return $this->hostsArray; |
65 | 65 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | /** |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public function getOptions() |
|
70 | + public function getOptions () |
|
71 | 71 | { |
72 | 72 | return $this->options; |
73 | 73 | } |
@@ -9,19 +9,19 @@ |
||
9 | 9 | * |
10 | 10 | * @return array |
11 | 11 | */ |
12 | - public function getIndices(); |
|
12 | + public function getIndices (); |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Returns the model in an Algolia friendly array form. |
16 | 16 | * |
17 | 17 | * @return array |
18 | 18 | */ |
19 | - public function getAlgoliaRecord(); |
|
19 | + public function getAlgoliaRecord (); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Returns an unique identifier for the Model. |
23 | 23 | * |
24 | 24 | * @return int |
25 | 25 | */ |
26 | - public function getObjectID(); |
|
26 | + public function getObjectID (); |
|
27 | 27 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return array |
17 | 17 | */ |
18 | - public function chunk(ActiveQueryInterface $query, $size, callable $callback) |
|
18 | + public function chunk (ActiveQueryInterface $query, $size, callable $callback) |
|
19 | 19 | { |
20 | 20 | $pageNumber = 1; |
21 | 21 | $records = $this->paginateRecords($query, $pageNumber, $size)->all(); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return ActiveQueryInterface |
55 | 55 | */ |
56 | - private function paginateRecords(ActiveQueryInterface $query, $pageNumber, $count) |
|
56 | + private function paginateRecords (ActiveQueryInterface $query, $pageNumber, $count) |
|
57 | 57 | { |
58 | 58 | $offset = ($pageNumber - 1) * $count; |
59 | 59 | $limit = $count; |
@@ -13,9 +13,9 @@ |
||
13 | 13 | * |
14 | 14 | * @return ActiveRecordInterface |
15 | 15 | */ |
16 | - public function make($className) |
|
16 | + public function make ($className) |
|
17 | 17 | { |
18 | - if (! (new \ReflectionClass($className))->implementsInterface(ActiveRecordInterface::class)) { |
|
18 | + if ( ! (new \ReflectionClass($className))->implementsInterface(ActiveRecordInterface::class)) { |
|
19 | 19 | throw new \InvalidArgumentException("Cannot initiate a class ({$className}) which doesn't implement \\yii\\db\\ActiveRecordInterface"); |
20 | 20 | } |
21 | 21 |
@@ -34,7 +34,7 @@ |
||
34 | 34 | /** |
35 | 35 | * {@inheritdoc} |
36 | 36 | */ |
37 | - public function events() |
|
37 | + public function events () |
|
38 | 38 | { |
39 | 39 | return [ |
40 | 40 | ActiveRecord::EVENT_AFTER_INSERT => function (Event $event) { |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @return Client |
15 | 15 | */ |
16 | - public function make(AlgoliaConfig $config) |
|
16 | + public function make (AlgoliaConfig $config) |
|
17 | 17 | { |
18 | 18 | return new Client( |
19 | 19 | $config->getApplicationId(), |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return SearchableInterface |
32 | 32 | */ |
33 | - public function makeSearchableObject($className) |
|
33 | + public function makeSearchableObject ($className) |
|
34 | 34 | { |
35 | - if (! (new \ReflectionClass($className))->implementsInterface(SearchableInterface::class)) { |
|
35 | + if ( ! (new \ReflectionClass($className))->implementsInterface(SearchableInterface::class)) { |
|
36 | 36 | throw new \InvalidArgumentException("Cannot initiate a class ({$className}) which doesn't implement leinonen\\Yii2Algolia\\SearchableInterface"); |
37 | 37 | } |
38 | 38 |
@@ -17,14 +17,14 @@ discard block |
||
17 | 17 | * @param array $expand |
18 | 18 | * @param bool $recursive |
19 | 19 | */ |
20 | - abstract public function toArray(array $fields = [], array $expand = [], $recursive = true); |
|
20 | + abstract public function toArray (array $fields = [], array $expand = [], $recursive = true); |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @see \yii\db\BaseActiveRecord::getPrimaryKey() |
24 | 24 | * |
25 | 25 | * @param bool $asArray |
26 | 26 | */ |
27 | - abstract public function getPrimaryKey($asArray = false); |
|
27 | + abstract public function getPrimaryKey ($asArray = false); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * An array of indices that this model uses. If none specified |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return array |
34 | 34 | */ |
35 | - public function indices() |
|
35 | + public function indices () |
|
36 | 36 | { |
37 | 37 | return []; |
38 | 38 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return array |
44 | 44 | */ |
45 | - public function getIndices() |
|
45 | + public function getIndices () |
|
46 | 46 | { |
47 | 47 | $indices = $this->indices(); |
48 | 48 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return array |
62 | 62 | */ |
63 | - public function getAlgoliaRecord() |
|
63 | + public function getAlgoliaRecord () |
|
64 | 64 | { |
65 | 65 | $record = $this->toArray(); |
66 | 66 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return int |
74 | 74 | */ |
75 | - public function getObjectID() |
|
75 | + public function getObjectID () |
|
76 | 76 | { |
77 | 77 | return $this->getPrimaryKey(); |
78 | 78 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - public function index() |
|
85 | + public function index () |
|
86 | 86 | { |
87 | 87 | $manager = $this->getAlgoliaManager(); |
88 | 88 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return array |
96 | 96 | */ |
97 | - public function removeFromIndices() |
|
97 | + public function removeFromIndices () |
|
98 | 98 | { |
99 | 99 | $manager = $this->getAlgoliaManager(); |
100 | 100 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - public function updateInIndices() |
|
109 | + public function updateInIndices () |
|
110 | 110 | { |
111 | 111 | $manager = $this->getAlgoliaManager(); |
112 | 112 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return array |
120 | 120 | */ |
121 | - public static function reindex() |
|
121 | + public static function reindex () |
|
122 | 122 | { |
123 | 123 | $manager = static::getAlgoliaManager(); |
124 | 124 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return array |
132 | 132 | */ |
133 | - public static function clearIndices() |
|
133 | + public static function clearIndices () |
|
134 | 134 | { |
135 | 135 | $manager = static::getAlgoliaManager(); |
136 | 136 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return array |
147 | 147 | */ |
148 | - public static function search($query, array $searchParameters = null) |
|
148 | + public static function search ($query, array $searchParameters = null) |
|
149 | 149 | { |
150 | 150 | $manager = static::getAlgoliaManager(); |
151 | 151 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return AlgoliaManager |
159 | 159 | * @throws \yii\base\InvalidConfigException |
160 | 160 | */ |
161 | - private static function getAlgoliaManager() |
|
161 | + private static function getAlgoliaManager () |
|
162 | 162 | { |
163 | 163 | return Yii::$container->get(AlgoliaManager::class); |
164 | 164 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @param ActiveQueryChunker $activeQueryChunker |
103 | 103 | * @param array $config |
104 | 104 | */ |
105 | - public function __construct( |
|
105 | + public function __construct ( |
|
106 | 106 | AlgoliaFactory $algoliaFactory, |
107 | 107 | ActiveRecordFactory $activeRecordFactory, |
108 | 108 | ActiveQueryChunker $activeQueryChunker, |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @param Application $app the application currently running |
122 | 122 | */ |
123 | - public function bootstrap($app) |
|
123 | + public function bootstrap ($app) |
|
124 | 124 | { |
125 | 125 | Yii::$container->set(AlgoliaManager::class, function () { |
126 | 126 | return $this->createManager(); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | /** |
131 | 131 | * {@inheritdoc} |
132 | 132 | */ |
133 | - public function init() |
|
133 | + public function init () |
|
134 | 134 | { |
135 | 135 | $this->manager = $this->createManager(); |
136 | 136 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return AlgoliaManager |
142 | 142 | */ |
143 | - protected function createManager() |
|
143 | + protected function createManager () |
|
144 | 144 | { |
145 | 145 | $config = $this->generateConfig(); |
146 | 146 | $client = $this->algoliaFactory->make($config); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return mixed |
161 | 161 | */ |
162 | - public function __call($method, $parameters) |
|
162 | + public function __call ($method, $parameters) |
|
163 | 163 | { |
164 | 164 | return \call_user_func_array([$this->manager, $method], $parameters); |
165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @return AlgoliaConfig |
171 | 171 | * @throws \Exception |
172 | 172 | */ |
173 | - private function generateConfig() |
|
173 | + private function generateConfig () |
|
174 | 174 | { |
175 | 175 | if (empty($this->applicationId) || empty($this->apiKey)) { |
176 | 176 | throw new \Exception('applicationId and apiKey are required'); |