ElasticsearchContextFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 15
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndexName() 0 5 1
A create() 0 6 1
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