Passed
Push — dev ( eeaa0f...91a85a )
by Janko
26:10
created

EventProcessor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 28
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processEvent() 0 16 1
A __construct() 0 6 1
1
<?php
2
3
namespace Stu\Component\Event;
4
5
use Stu\Component\Concurrency\EntityLockManagerInterface;
6
use Stu\Component\Event\Strategy\EventStrategyInterface;
7
use Stu\Module\Logging\LoggerTypeEnum;
8
use Stu\Module\Logging\LoggerUtilFactoryInterface;
9
use Stu\Module\Logging\RotatingLoggerInterface;
10
use Stu\Orm\Entity\EventInterface;
11
use Stu\Orm\Transaction\SwitchableEntityManagerInterface;
12
13
class EventProcessor implements EventProcessorInterface
14
{
15
    private RotatingLoggerInterface $logger;
16
17 2
    public function __construct(
18
        private SwitchableEntityManagerInterface $switchableEntityManager,
19
        private EntityLockManagerInterface $entityLockManager,
20
        LoggerUtilFactoryInterface $loggerUtilFactory
21
    ) {
22 2
        $this->logger = $loggerUtilFactory->getRotatingLogger(LoggerTypeEnum::EVENT_AND_ENTITY_LOCK);
23
    }
24
25 2
    public function processEvent(EventInterface $event, EventStrategyInterface $eventStrategy): void
26
    {
27
        try {
28 2
            $startTime = microtime(true);
29 2
            $this->switchableEntityManager->wrapInTransaction(function () use ($event, $eventStrategy) {
30
31 2
                $startTime = microtime(true);
32 2
                $eventStrategy->processEvent($event);
33 2
                $endTime = microtime(true);
34
35 2
                $this->logger->logf('    processing took %F ms', ($endTime - $startTime) * 1000);
36 2
            });
37 1
            $endTime = microtime(true);
38 1
            $this->logger->logf('    transaction took %F ms', ($endTime - $startTime) * 1000);
39
        } finally {
40 2
            $this->entityLockManager->clearEntityLocks();
41
        }
42
    }
43
}
44