Completed
Pull Request — master (#710)
by
unknown
02:28
created

Manager::remove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Service;
13
14
use Elasticsearch\Client;
15
use Elasticsearch\Common\Exceptions\Missing404Exception;
16
use ONGR\ElasticsearchBundle\Event\Events;
17
use ONGR\ElasticsearchBundle\Event\BulkEvent;
18
use ONGR\ElasticsearchBundle\Event\CommitEvent;
19
use ONGR\ElasticsearchBundle\Exception\BulkWithErrorsException;
20
use ONGR\ElasticsearchBundle\Mapping\MetadataCollector;
21
use ONGR\ElasticsearchBundle\Result\AbstractResultsIterator;
22
use ONGR\ElasticsearchBundle\Result\Converter;
23
use ONGR\ElasticsearchBundle\Result\DocumentIterator;
24
use ONGR\ElasticsearchBundle\Result\RawIterator;
25
use ONGR\ElasticsearchBundle\Result\Result;
26
use ONGR\ElasticsearchDSL\Search;
27
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
28
use Symfony\Component\Stopwatch\Stopwatch;
29
30
/**
31
 * Manager class.
32
 */
33
class Manager
34
{
35
    /**
36
     * @var string Manager name
37
     */
38
    private $name;
39
40
    /**
41
     * @var array Manager configuration
42
     */
43
    private $config = [];
44
45
    /**
46
     * @var Client
47
     */
48
    private $client;
49
50
    /**
51
     * @var Converter
52
     */
53
    private $converter;
54
55
    /**
56
     * @var array Container for bulk queries
57
     */
58
    private $bulkQueries = [];
59
60
    /**
61
     * @var array Holder for consistency, refresh and replication parameters
62
     */
63
    private $bulkParams = [];
64
65
    /**
66
     * @var array
67
     */
68
    private $indexSettings;
69
70
    /**
71
     * @var MetadataCollector
72
     */
73
    private $metadataCollector;
74
75
    /**
76
     * After commit to make data available the refresh or flush operation is needed
77
     * so one of those methods has to be defined, the default is refresh.
78
     *
79
     * @var string
80
     */
81
    private $commitMode = 'refresh';
82
83
    /**
84
     * The size that defines after how much document inserts call commit function.
85
     *
86
     * @var int
87
     */
88
    private $bulkCommitSize = 100;
89
90
    /**
91
     * Container to count how many documents was passed to the bulk query.
92
     *
93
     * @var int
94
     */
95
    private $bulkCount = 0;
96
97
    /**
98
     * @var Repository[] Repository local cache
99
     */
100
    private $repositories;
101
102
    /**
103
     * @var EventDispatcherInterface
104
     */
105
    private $eventDispatcher;
106
107
    /**
108
     * @var Stopwatch
109
     */
110
    private $stopwatch;
111
112
    /**
113
     * @param string            $name              Manager name
114
     * @param array             $config            Manager configuration
115
     * @param Client            $client
116
     * @param array             $indexSettings
117
     * @param MetadataCollector $metadataCollector
118
     * @param Converter         $converter
119
     */
120
    public function __construct(
121
        $name,
122
        array $config,
123
        $client,
124
        array $indexSettings,
125
        $metadataCollector,
126
        $converter
127
    ) {
128
        $this->name = $name;
129
        $this->config = $config;
130
        $this->client = $client;
131
        $this->indexSettings = $indexSettings;
132
        $this->metadataCollector = $metadataCollector;
133
        $this->converter = $converter;
134
    }
135
136
    /**
137
     * Returns Elasticsearch connection.
138
     *
139
     * @return Client
140
     */
141
    public function getClient()
142
    {
143
        return $this->client;
144
    }
145
146
    /**
147
     * @return string
148
     */
149
    public function getName()
150
    {
151
        return $this->name;
152
    }
153
154
    /**
155
     * @return array
156
     */
157
    public function getConfig()
158
    {
159
        return $this->config;
160
    }
161
162
    /**
163
     * @param EventDispatcherInterface $eventDispatcher
164
     */
165
    public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
166
    {
167
        $this->eventDispatcher = $eventDispatcher;
168
    }
169
170
    /**
171
     * @param Stopwatch $stopwatch
172
     */
173
    public function setStopwatch(Stopwatch $stopwatch)
174
    {
175
        $this->stopwatch = $stopwatch;
176
    }
177
178
    /**
179
     * Returns repository by document class.
180
     *
181
     * @param string $className FQCN or string in Bundle:Document format
182
     *
183
     * @return Repository
184
     */
185
    public function getRepository($className)
186
    {
187
        if (!is_string($className)) {
188
            throw new \InvalidArgumentException('Document class must be a string.');
189
        }
190
191
        $namespace = $this->getMetadataCollector()->getClassName($className);
192
193
        if (isset($this->repositories[$namespace])) {
194
            return $this->repositories[$namespace];
195
        }
196
197
        $repository = $this->createRepository($namespace);
198
        $this->repositories[$namespace] = $repository;
199
200
        return $repository;
201
    }
202
203
    /**
204
     * @return MetadataCollector
205
     */
206
    public function getMetadataCollector()
207
    {
208
        return $this->metadataCollector;
209
    }
210
211
    /**
212
     * @return Converter
213
     */
214
    public function getConverter()
215
    {
216
        return $this->converter;
217
    }
218
219
    /**
220
     * @return string
221
     */
222
    public function getCommitMode()
223
    {
224
        return $this->commitMode;
225
    }
226
227
    /**
228
     * @param string $commitMode
229
     */
230
    public function setCommitMode($commitMode)
231
    {
232
        if ($commitMode === 'refresh' || $commitMode === 'flush' || $commitMode === 'none') {
233
            $this->commitMode = $commitMode;
234
        } else {
235
            throw new \LogicException('The commit method must be either refresh, flush or none.');
236
        }
237
    }
238
239
    /**
240
     * @return int
241
     */
242
    public function getBulkCommitSize()
243
    {
244
        return $this->bulkCommitSize;
245
    }
246
247
    /**
248
     * @param int $bulkCommitSize
249
     */
250
    public function setBulkCommitSize($bulkCommitSize)
251
    {
252
        $this->bulkCommitSize = $bulkCommitSize;
253
    }
254
255
    /**
256
     * Creates a repository.
257
     *
258
     * @param string $className
259
     *
260
     * @return Repository
261
     */
262
    private function createRepository($className)
263
    {
264
        return new Repository($this, $className);
265
    }
266
267
    /**
268
     * Executes search query in the index.
269
     *
270
     * @param array $types             List of types to search in.
271
     * @param array $query             Query to execute.
272
     * @param array $queryStringParams Query parameters.
273
     *
274
     * @return array
275
     */
276
    public function search(array $types, array $query, array $queryStringParams = [])
277
    {
278
        $params = [];
279
        $params['index'] = $this->getIndexName();
280
        
281
        if (!empty($types)) {
282
            $params['type'] = implode(',', $types);
283
        }
284
        
285
        $params['body'] = $query;
286
287
        if (!empty($queryStringParams)) {
288
            $params = array_merge($queryStringParams, $params);
289
        }
290
291
        $this->stopwatch('start', 'search');
292
        $result = $this->client->search($params);
293
        $this->stopwatch('stop', 'search');
294
295
        return $result;
296
    }
297
298
    /**
299
     * Adds document to next flush.
300
     *
301
     * @param object $document
302
     */
303
    public function persist($document)
304
    {
305
        $documentArray = $this->converter->convertToArray($document);
306
        $type = $this->getMetadataCollector()->getDocumentType(get_class($document));
307
308
        $this->bulk('index', $type, $documentArray);
309
    }
310
311
    /**
312
     * Adds document for removal.
313
     *
314
     * @param object $document
315
     */
316
    public function remove($document)
317
    {
318
        $data = $this->converter->convertToArray($document, [], ['_id', '_routing']);
319
320
        if (!isset($data['_id'])) {
321
            throw new \LogicException(
322
                'In order to use remove() method document class must have property with @Id annotation.'
323
            );
324
        }
325
326
        $type = $this->getMetadataCollector()->getDocumentType(get_class($document));
327
328
        $this->bulk('delete', $type, $data);
329
    }
330
331
    /**
332
     * Flushes elasticsearch index.
333
     *
334
     * @param array $params
335
     *
336
     * @return array
337
     */
338
    public function flush(array $params = [])
339
    {
340
        return $this->client->indices()->flush(array_merge(['index' => $this->getIndexName()], $params));
341
    }
342
343
    /**
344
     * Refreshes elasticsearch index.
345
     *
346
     * @param array $params
347
     *
348
     * @return array
349
     */
350
    public function refresh(array $params = [])
351
    {
352
        return $this->client->indices()->refresh(array_merge(['index' => $this->getIndexName()], $params));
353
    }
354
355
    /**
356
     * Inserts the current query container to the index, used for bulk queries execution.
357
     *
358
     * @param array $params Parameters that will be passed to the flush or refresh queries.
359
     *
360
     * @return null|array
361
     *
362
     * @throws BulkWithErrorsException
363
     */
364
    public function commit(array $params = [])
365
    {
366
        if (!empty($this->bulkQueries)) {
367
            $bulkQueries = array_merge($this->bulkQueries, $this->bulkParams);
368
            $bulkQueries['index']['_index'] = $this->getIndexName();
369
            $this->eventDispatcher->dispatch(
370
                Events::PRE_COMMIT,
371
                new CommitEvent($this->getCommitMode(), $bulkQueries)
372
            );
373
374
            $this->stopwatch('start', 'bulk');
375
            $bulkResponse = $this->client->bulk($bulkQueries);
376
            $this->stopwatch('stop', 'bulk');
377
378
            if ($bulkResponse['errors']) {
379
                throw new BulkWithErrorsException(
380
                    json_encode($bulkResponse),
381
                    0,
382
                    null,
383
                    $bulkResponse
0 ignored issues
show
Documentation introduced by
$bulkResponse is of type callable, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
384
                );
385
            }
386
387
            $this->bulkQueries = [];
388
            $this->bulkCount = 0;
389
390
            $this->stopwatch('start', 'refresh');
391
392
            switch ($this->getCommitMode()) {
393
                case 'flush':
394
                    $this->flush($params);
395
                    break;
396
                case 'refresh':
397
                    $this->refresh($params);
398
                    break;
399
            }
400
401
            $this->eventDispatcher->dispatch(
402
                Events::POST_COMMIT,
403
                new CommitEvent($this->getCommitMode(), $bulkResponse)
0 ignored issues
show
Documentation introduced by
$bulkResponse is of type callable, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
404
            );
405
406
            $this->stopwatch('stop', 'refresh');
407
408
            return $bulkResponse;
409
        }
410
411
        return null;
412
    }
413
414
    /**
415
     * Adds query to bulk queries container.
416
     *
417
     * @param string       $operation One of: index, update, delete, create.
418
     * @param string|array $type      Elasticsearch type name.
419
     * @param array        $query     DSL to execute.
420
     *
421
     * @throws \InvalidArgumentException
422
     *
423
     * @return null|array
424
     */
425
    public function bulk($operation, $type, array $query)
426
    {
427
        if (!in_array($operation, ['index', 'create', 'update', 'delete'])) {
428
            throw new \InvalidArgumentException('Wrong bulk operation selected');
429
        }
430
431
        $this->eventDispatcher->dispatch(
432
            Events::BULK,
433
            new BulkEvent($operation, $type, $query)
434
        );
435
436
        $this->bulkQueries['body'][] = [
437
            $operation => array_filter(
438
                [
439
                    '_type' => $type,
440
                    '_id' => isset($query['_id']) ? $query['_id'] : null,
441
                    '_ttl' => isset($query['_ttl']) ? $query['_ttl'] : null,
442
                    '_routing' => isset($query['_routing']) ? $query['_routing'] : null,
443
                    '_parent' => isset($query['_parent']) ? $query['_parent'] : null,
444
                ]
445
            ),
446
        ];
447
        unset($query['_id'], $query['_ttl'], $query['_parent'], $query['_routing']);
448
449
        switch ($operation) {
450
            case 'index':
451
            case 'create':
452
            case 'update':
453
                $this->bulkQueries['body'][] = $query;
454
                break;
455
            case 'delete':
456
                // Body for delete operation is not needed to apply.
457
            default:
458
                // Do nothing.
459
                break;
460
        }
461
462
        // We are using counter because there is to difficult to resolve this from bulkQueries array.
463
        $this->bulkCount++;
464
465
        $response = null;
466
467
        if ($this->bulkCommitSize === $this->bulkCount) {
468
            $response = $this->commit();
469
        }
470
471
        return $response;
472
    }
473
474
    /**
475
     * Optional setter to change bulk query params.
476
     *
477
     * @param array $params Possible keys:
478
     *                      ['consistency'] = (enum) Explicit write consistency setting for the operation.
479
     *                      ['refresh']     = (boolean) Refresh the index after performing the operation.
480
     *                      ['replication'] = (enum) Explicitly set the replication type.
481
     */
482
    public function setBulkParams(array $params)
483
    {
484
        $this->bulkParams = $params;
485
    }
486
487
    /**
488
     * Creates fresh elasticsearch index.
489
     *
490
     * @param bool $noMapping Determines if mapping should be included.
491
     * @param bool $noArrayMappings Determines if array mapping should be included.
492
     *
493
     * @return array
494
     */
495
    public function createIndex($noMapping = false, $noArrayMappings = false)
496
    {
497
        if ($noMapping) {
498
            unset($this->indexSettings['body']['mappings']);
499
        }
500
        if ($noArrayMappings) {
501
            $this->removeArrayPropertyMappings();
502
        }
503
        return $this->getClient()->indices()->create($this->indexSettings);
504
    }
505
506
    /**
507
     * Array style mappings are causing a number of issues for our index - this works around that
508
     */
509
    private function removeArrayPropertyMappings()
510
    {
511
        foreach ($this->indexSettings['body']['mappings'] as $indexId => $index) {
512
            foreach ($index['properties'] as $propertyId => $property) {
513
                // exclude array types from the mapping - let ES work them out
514
                if ($property['type'] == 'array') {
515
                    unset($this->indexSettings['body']['mappings'][$indexId]['properties'][$propertyId]);
516
                }
517
            }
518
        }
519
    }
520
521
    /**
522
     * Drops elasticsearch index.
523
     */
524
    public function dropIndex()
525
    {
526
        return $this->getClient()->indices()->delete(['index' => $this->getIndexName()]);
527
    }
528
529
    /**
530
     * Tries to drop and create fresh elasticsearch index.
531
     *
532
     * @param bool $noMapping Determines if mapping should be included.
533
     *
534
     * @return array
535
     */
536
    public function dropAndCreateIndex($noMapping = false)
537
    {
538
        try {
539
            $this->dropIndex();
540
        } catch (\Exception $e) {
541
            // Do nothing, our target is to create new index.
542
        }
543
544
        return $this->createIndex($noMapping);
545
    }
546
547
    /**
548
     * Checks if connection index is already created.
549
     *
550
     * @return bool
551
     */
552
    public function indexExists()
553
    {
554
        return $this->getClient()->indices()->exists(['index' => $this->getIndexName()]);
555
    }
556
557
    /**
558
     * Returns index name this connection is attached to.
559
     *
560
     * @return string
561
     */
562
    public function getIndexName()
563
    {
564
        return $this->indexSettings['index'];
565
    }
566
567
    /**
568
     * Sets index name for this connection.
569
     *
570
     * @param string $name
571
     */
572
    public function setIndexName($name)
573
    {
574
        $this->indexSettings['index'] = $name;
575
    }
576
577
    /**
578
     * Returns mappings of the index for this connection.
579
     *
580
     * @return array
581
     */
582
    public function getIndexMappings()
583
    {
584
        return $this->indexSettings['body']['mappings'];
585
    }
586
587
    /**
588
     * Returns Elasticsearch version number.
589
     *
590
     * @return string
591
     */
592
    public function getVersionNumber()
593
    {
594
        return $this->client->info()['version']['number'];
595
    }
596
597
    /**
598
     * Clears elasticsearch client cache.
599
     */
600
    public function clearCache()
601
    {
602
        $this->getClient()->indices()->clearCache(['index' => $this->getIndexName()]);
603
    }
604
605
    /**
606
     * Returns a single document by ID. Returns NULL if document was not found.
607
     *
608
     * @param string $className Document class name or Elasticsearch type name
609
     * @param string $id        Document ID to find
610
     * @param string $routing   Custom routing for the document
611
     *
612
     * @return object
613
     */
614
    public function find($className, $id, $routing = null)
615
    {
616
        $type = $this->resolveTypeName($className);
617
618
        $params = [
619
            'index' => $this->getIndexName(),
620
            'type' => $type,
621
            'id' => $id,
622
        ];
623
624
        if ($routing) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $routing of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
625
            $params['routing'] = $routing;
626
        }
627
628
        try {
629
            $result = $this->getClient()->get($params);
630
        } catch (Missing404Exception $e) {
631
            return null;
632
        }
633
634
        return $this->getConverter()->convertToDocument($result, $this);
0 ignored issues
show
Documentation introduced by
$result is of type callable, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
635
    }
636
637
    /**
638
     * Executes given search.
639
     *
640
     * @deprecated use strict return type functions from Repository instead.
641
     *
642
     * @param array  $types
643
     * @param Search $search
644
     * @param string $resultsType
645
     *
646
     * @return DocumentIterator|RawIterator|array
647
     */
648
    public function execute($types, Search $search, $resultsType = Result::RESULTS_OBJECT)
649
    {
650
        foreach ($types as &$type) {
651
            $type = $this->resolveTypeName($type);
652
        }
653
654
        $results = $this->search($types, $search->toArray(), $search->getQueryParams());
655
656
        return $this->parseResult($results, $resultsType, $search->getScroll());
0 ignored issues
show
Documentation introduced by
$results is of type callable, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method ONGR\ElasticsearchBundle...\Manager::parseResult() has been deprecated with message: use strict return type functions from Repository class instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
657
    }
658
659
    /**
660
     * Parses raw result.
661
     *
662
     * @deprecated use strict return type functions from Repository class instead.
663
     *
664
     * @param array  $raw
665
     * @param string $resultsType
666
     * @param string $scrollDuration
667
     *
668
     * @return DocumentIterator|RawIterator|array
669
     *
670
     * @throws \Exception
671
     */
672
    private function parseResult($raw, $resultsType, $scrollDuration = null)
673
    {
674
        $scrollConfig = [];
675 View Code Duplication
        if (isset($raw['_scroll_id'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
676
            $scrollConfig['_scroll_id'] = $raw['_scroll_id'];
677
            $scrollConfig['duration'] = $scrollDuration;
678
        }
679
680
        switch ($resultsType) {
681
            case Result::RESULTS_OBJECT:
682
                return new DocumentIterator($raw, $this, $scrollConfig);
683
            case Result::RESULTS_ARRAY:
684
                return $this->convertToNormalizedArray($raw);
0 ignored issues
show
Deprecated Code introduced by
The method ONGR\ElasticsearchBundle...vertToNormalizedArray() has been deprecated with message: Use ArrayIterator from Result namespace instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
685
            case Result::RESULTS_RAW:
686
                return $raw;
687
            case Result::RESULTS_RAW_ITERATOR:
688
                return new RawIterator($raw, $this, $scrollConfig);
689
            default:
690
                throw new \Exception('Wrong results type selected');
691
        }
692
    }
693
694
    /**
695
     * Normalizes response array.
696
     *
697
     * @deprecated Use ArrayIterator from Result namespace instead.
698
     *
699
     * @param array $data
700
     *
701
     * @return array
702
     */
703
    private function convertToNormalizedArray($data)
704
    {
705
        if (array_key_exists('_source', $data)) {
706
            $data['_source']['_id'] = $data['_id'];
707
            return $data['_source'];
708
        }
709
710
        $output = [];
711
712
        if (isset($data['hits']['hits'][0]['_source'])) {
713
            foreach ($data['hits']['hits'] as $item) {
714
                $item['_source']['_id'] = $item['_id'];
715
                $output[] = $item['_source'];
716
            }
717
        } elseif (isset($data['hits']['hits'][0]['fields'])) {
718
            foreach ($data['hits']['hits'] as $item) {
719
                $output[] = array_map('reset', $item['fields']);
720
            }
721
        }
722
723
        return $output;
724
    }
725
726
    /**
727
     * Fetches next set of results.
728
     *
729
     * @param string $scrollId
730
     * @param string $scrollDuration
731
     * @param string $resultsType
732
     *
733
     * @return mixed
734
     *
735
     * @throws \Exception
736
     */
737
    public function scroll(
738
        $scrollId,
739
        $scrollDuration = '5m',
740
        $resultsType = Result::RESULTS_OBJECT
741
    ) {
742
        $results = $this->getClient()->scroll(['scroll_id' => $scrollId, 'scroll' => $scrollDuration]);
743
744
        if ($resultsType == Result::RESULTS_RAW) {
745
            return $results;
746
        } else {
747
            trigger_error(
748
                '$resultsType parameter was deprecated in scroll() fucntion. ' .
749
                'Use strict type findXXX functions from repository instead. Will be removed in 3.0',
750
                E_USER_DEPRECATED
751
            );
752
            return $this->parseResult($results, $resultsType, $scrollDuration);
0 ignored issues
show
Documentation introduced by
$results is of type callable, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method ONGR\ElasticsearchBundle...\Manager::parseResult() has been deprecated with message: use strict return type functions from Repository class instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
753
        }
754
    }
755
756
    /**
757
     * Clears scroll.
758
     *
759
     * @param string $scrollId
760
     */
761
    public function clearScroll($scrollId)
762
    {
763
        $this->getClient()->clearScroll(['scroll_id' => $scrollId]);
764
    }
765
766
    /**
767
     * Resolves type name by class name.
768
     *
769
     * @param string $className
770
     *
771
     * @return string
772
     */
773
    private function resolveTypeName($className)
774
    {
775
        if (strpos($className, ':') !== false || strpos($className, '\\') !== false) {
776
            return $this->getMetadataCollector()->getDocumentType($className);
777
        }
778
779
        return $className;
780
    }
781
782
    /**
783
     * Starts and stops an event in the stopwatch
784
     *
785
     * @param string $action   only 'start' and 'stop'
786
     * @param string $name     name of the event
787
     */
788
    private function stopwatch($action, $name)
789
    {
790
        if (isset($this->stopwatch)) {
791
            $this->stopwatch->$action('ongr_es: '.$name, 'ongr_es');
792
        }
793
    }
794
}
795