Passed
Push — trunk ( 9dfcf5...f40966 )
by Christian
12:13 queued 13s
created

IndexMappingUpdater   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A update() 0 25 5
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Elasticsearch\Framework\Indexing;
4
5
use OpenSearch\Client;
6
use Shopware\Core\Framework\Context;
7
use Shopware\Core\Framework\Feature;
8
use Shopware\Core\Framework\Log\Package;
9
use Shopware\Elasticsearch\Framework\ElasticsearchHelper;
10
use Shopware\Elasticsearch\Framework\ElasticsearchLanguageProvider;
11
use Shopware\Elasticsearch\Framework\ElasticsearchRegistry;
12
13
#[Package('core')]
14
class IndexMappingUpdater
15
{
16
    /**
17
     * @internal
18
     */
19
    public function __construct(
20
        private readonly ElasticsearchRegistry $registry,
21
        private readonly ElasticsearchHelper $elasticsearchHelper,
22
        private readonly ElasticsearchLanguageProvider $languageProvider,
23
        private readonly Client $client,
24
        private readonly IndexMappingProvider $indexMappingProvider
25
    ) {
26
    }
27
28
    public function update(Context $context): void
29
    {
30
        if (!Feature::isActive('ES_MULTILINGUAL_INDEX')) {
31
            $languages = $this->languageProvider->getLanguages($context);
32
33
            foreach ($this->registry->getDefinitions() as $definition) {
34
                foreach ($languages as $language) {
35
                    $indexName = $this->elasticsearchHelper->getIndexName($definition->getEntityDefinition(), $language->getId());
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Elasticsearch\F...hHelper::getIndexName() has been deprecated: tag:v6.6.0 - reason:new-optional-parameter - Parameter $languageId will be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

35
                    $indexName = /** @scrutinizer ignore-deprecated */ $this->elasticsearchHelper->getIndexName($definition->getEntityDefinition(), $language->getId());

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

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

Loading history...
36
37
                    $this->client->indices()->putMapping([
38
                        'index' => $indexName,
39
                        'body' => $this->indexMappingProvider->build($definition, $context),
40
                    ]);
41
                }
42
            }
43
44
            return;
45
        }
46
47
        foreach ($this->registry->getDefinitions() as $definition) {
48
            $indexName = $this->elasticsearchHelper->getIndexName($definition->getEntityDefinition());
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Elasticsearch\F...hHelper::getIndexName() has been deprecated: tag:v6.6.0 - reason:new-optional-parameter - Parameter $languageId will be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
            $indexName = /** @scrutinizer ignore-deprecated */ $this->elasticsearchHelper->getIndexName($definition->getEntityDefinition());

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

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

Loading history...
49
50
            $this->client->indices()->putMapping([
51
                'index' => $indexName,
52
                'body' => $this->indexMappingProvider->build($definition, $context),
53
            ]);
54
        }
55
    }
56
}
57