DocumentCleaner::deleteDocuments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Elasticsearch\Business\Model\Document;
5
6
7
use DataProvider\DocumentListDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\DocumentListDataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Elastica\Client;
9
use Elastica\Document;
10
11
class DocumentCleaner implements DocumentCleanerInterface
12
{
13
    /**
14
     * @var \Elastica\Client
15
     */
16
    private $client;
17
18
    /**
19
     * DocumentBuilder constructor.
20
     *
21
     * @param \Elastica\Client $client
22
     */
23 1
    public function __construct(Client $client)
24
    {
25 1
        $this->client = $client;
26 1
    }
27
28
    /**
29
     * @param \DataProvider\DocumentListDataProvider $listDataProvider
30
     */
31 1
    public function deleteDocuments(DocumentListDataProvider $listDataProvider): void
32
    {
33 1
        $documents = $this->getDocumentsFromDataProvider($listDataProvider);
34
35
        $type = $this
36 1
            ->client
37 1
            ->getIndex($listDataProvider->getIndex())
38 1
            ->getType($listDataProvider->getType());
39
40 1
        $type->deleteDocuments($documents);
41
42 1
        $type->getIndex()->refresh();
43 1
    }
44
45
    /**
46
     * @param \DataProvider\DocumentListDataProvider $listDataProvider
47
     * @param array $document
48
     *
49
     * @return array
50
     */
51 1
    protected function getDocumentsFromDataProvider(DocumentListDataProvider $listDataProvider): array
52
    {
53 1
        $documents = [];
54
55 1
        foreach ($listDataProvider->getDocuments() as $documentDataProvider) {
56 1
            $documents[] = new Document(
57 1
                $documentDataProvider->getIdent(),
58 1
                $documentDataProvider->getContent()
59
            );
60
        }
61
62 1
        return $documents;
63
    }
64
}