CurrentDataTrackerProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getCurrentDataTrackerByClassAndId() 0 13 1
1
<?php
2
3
namespace Locastic\Loggastic\DataProvider;
4
5
use Locastic\Loggastic\Bridge\Elasticsearch\Context\ElasticsearchContextFactoryInterface;
6
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService;
7
use Locastic\Loggastic\Model\Output\CurrentDataTracker;
8
use Locastic\Loggastic\Model\Output\CurrentDataTrackerInterface;
9
10
final class CurrentDataTrackerProvider implements CurrentDataTrackerProviderInterface
11
{
12
    public function __construct(private readonly ElasticsearchService $elasticsearchService, private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory)
13
    {
14
    }
15
16
    public function getCurrentDataTrackerByClassAndId(string $className, $objectId): ?CurrentDataTrackerInterface
17
    {
18
        $elasticContext = $this->elasticsearchContextFactory->create($className);
19
20
        $body = [
21
            'query' => ['term' => ['objectId' => $objectId]],
22
        ];
23
24
        //todo move class to config
25
        return $this->elasticsearchService->getItemByQuery(
26
            $elasticContext->getCurrentDataTrackerIndex(),
27
            CurrentDataTracker::class,
28
            $body
29
        );
30
    }
31
}
32