Test Failed
Push — main ( f1b82a...d2d042 )
by Bingo
06:24
created

MessageCorrelationBatchConfigurationJsonConverter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A readProcessInstanceIds() 0 3 1
A readIdMappings() 0 3 1
A toObject() 0 7 1
A instance() 0 6 2
A toJsonObject() 0 10 1
1
<?php
2
3
namespace Jabe\Engine\Impl\Json;
4
5
use Jabe\Engine\Impl\Batch\{
6
    DeploymentMappingJsonConverter,
7
    DeploymentMappings
8
};
9
use Jabe\Engine\Impl\Batch\Message\MessageCorrelationBatchConfiguration;
10
use Jabe\Engine\Impl\Util\JsonUtil;
11
12
class MessageCorrelationBatchConfigurationJsonConverter extends JsonObjectConverter
13
{
14
    private static $INSTANCE;
15
    public const MESSAGE_NAME = "messageName";
16
    public const PROCESS_INSTANCE_IDS = "processInstanceIds";
17
    public const PROCESS_INSTANCE_ID_MAPPINGS = "processInstanceIdMappings";
18
    public const BATCH_ID = "batchId";
19
20
    public static function instance(): MessageCorrelationBatchConfigurationJsonConverter
21
    {
22
        if (self::$INSTANCE === null) {
23
            self::$INSTANCE = new MessageCorrelationBatchConfigurationJsonConverter();
24
        }
25
        return self::$INSTANCE;
26
    }
27
28
    public function toJsonObject(/*(MessageCorrelationBatchConfiguration*/$configuration, bool $isOrQueryActive = false): ?\stdClass
29
    {
30
        $json = JsonUtil::createObject();
31
32
        JsonUtil::addField($json, self::MESSAGE_NAME, $configuration->getMessageName());
33
        JsonUtil::addListField($json, self::PROCESS_INSTANCE_IDS, $configuration->getIds());
34
        JsonUtil::addListField($json, self::PROCESS_INSTANCE_ID_MAPPINGS, DeploymentMappingJsonConverter::instance(), $configuration->getIdMappings());
35
        JsonUtil::addField($json, self::BATCH_ID, $configuration->getBatchId());
36
37
        return $json;
38
    }
39
40
    public function toObject(\stdClass $json, bool $isOrQuery = false)
41
    {
42
        return new MessageCorrelationBatchConfiguration(
43
            $this->readProcessInstanceIds($json),
44
            $this->readIdMappings($json),
45
            JsonUtil::getString($json, self::MESSAGE_NAME, null),
46
            JsonUtil::getString($json, self::BATCH_ID)
47
        );
48
    }
49
50
    protected function readProcessInstanceIds($jsonObject): array
51
    {
52
        return JsonUtil::asStringList(JsonUtil::getArray($jsonObject, self::PROCESS_INSTANCE_IDS));
53
    }
54
55
    protected function readIdMappings(\stdClass $json): DeploymentMappings
56
    {
57
        return JsonUtil::asList(JsonUtil::getArray($json, self::PROCESS_INSTANCE_ID_MAPPINGS), DeploymentMappingJsonConverter::instance(), DeploymentMappings::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Jabe\Engine\Impl\...loymentMappings::class) could return the type array which is incompatible with the type-hinted return Jabe\Engine\Impl\Batch\DeploymentMappings. Consider adding an additional type-check to rule them out.
Loading history...
58
    }
59
}
60