ElasticsearchContextFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Locastic\Loggastic\Bridge\Elasticsearch\Context;
4
5
use Locastic\Loggastic\Model\Output\ActivityLog;
6
use Locastic\Loggastic\Model\Output\CurrentDataTracker;
7
use Locastic\Loggastic\Util\StringConverter;
8
9
final class ElasticsearchContextFactory implements ElasticsearchContextFactoryInterface
10
{
11
    public function create(string $className): ElasticsearchContext
12
    {
13
        $activityLogIndex = $this->getIndexName($className).'_'.$this->getIndexName(ActivityLog::class);
14
        $currentDataTrackerIndex = $this->getIndexName($className).'_'.$this->getIndexName(CurrentDataTracker::class);
15
16
        return new ElasticsearchContext($className, $activityLogIndex, $currentDataTrackerIndex);
17
    }
18
19
    private function getIndexName(string $className): string
20
    {
21
        $reflectionClass = new \ReflectionClass($className);
22
23
        return StringConverter::tableize($reflectionClass->getShortName());
24
    }
25
}
26