CurrentDataTrackerProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 2
rs 10
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