CurrentDataTrackerInputFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 1
A createFromCurrentDataTracker() 0 9 1
1
<?php
2
3
namespace Locastic\Loggastic\Factory;
4
5
use Locastic\Loggastic\Model\Input\CurrentDataTrackerInput;
6
use Locastic\Loggastic\Model\Output\CurrentDataTrackerInterface;
7
use Locastic\Loggastic\Util\ClassUtils;
8
9
final class CurrentDataTrackerInputFactory implements CurrentDataTrackerInputFactoryInterface
10
{
11
    public function create($item, ?array $normalizedData = []): CurrentDataTrackerInput
12
    {
13
        $currentDataTracker = new CurrentDataTrackerInput();
14
15
        $currentDataTracker->setObjectId($item->getId());
16
        $currentDataTracker->setData(json_encode($normalizedData, JSON_THROW_ON_ERROR));
17
        $currentDataTracker->setObjectClass(ClassUtils::getClass($item));
18
19
        return $currentDataTracker;
20
    }
21
22
    public function createFromCurrentDataTracker(CurrentDataTrackerInterface $currentDataTracker): CurrentDataTrackerInput
23
    {
24
        $currentDataTrackerInput = new CurrentDataTrackerInput();
25
26
        $currentDataTrackerInput->setObjectId($currentDataTracker->getObjectId());
27
        $currentDataTrackerInput->setData(json_encode($currentDataTracker->getData(), JSON_THROW_ON_ERROR));
28
        $currentDataTrackerInput->setObjectClass($currentDataTracker->getObjectClass());
29
30
        return $currentDataTrackerInput;
31
    }
32
}
33