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

toObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 2
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\Migration\Batch\MigrationBatchConfiguration;
10
use Jabe\Engine\Impl\Util\JsonUtil;
11
12
class MigrationBatchConfigurationJsonConverter extends JsonObjectConverter
13
{
14
    private static $INSTANCE;
15
16
    public const MIGRATION_PLAN = "migrationPlan";
17
    public const PROCESS_INSTANCE_IDS = "processInstanceIds";
18
    public const PROCESS_INSTANCE_ID_MAPPINGS = "processInstanceIdMappings";
19
    public const SKIP_LISTENERS = "skipListeners";
20
    public const SKIP_IO_MAPPINGS = "skipIoMappings";
21
    public const BATCH_ID = "batchId";
22
23
    public static function instance(): MigrationBatchConfigurationJsonConverter
24
    {
25
        if (self::$INSTANCE == null) {
26
            self::$INSTANCE = new MigrationBatchConfigurationJsonConverter();
27
        }
28
        return self::$INSTANCE;
29
    }
30
31
    public function toJsonObject(/*MigrationBatchConfiguration*/$configuration, bool $isOrQueryActive = false): ?\stdClass
32
    {
33
        $json = JsonUtil::createObject();
34
35
        JsonUtil::addField($json, self::MIGRATION_PLAN, MigrationPlanJsonConverter::instance(), $configuration->getMigrationPlan());
36
        JsonUtil::addListField($json, self::PROCESS_INSTANCE_IDS, $configuration->getIds());
37
        JsonUtil::addListField($json, self::PROCESS_INSTANCE_ID_MAPPINGS, DeploymentMappingJsonConverter::instance(), $configuration->getIdMappings());
38
        JsonUtil::addField($json, self::SKIP_LISTENERS, $configuration->isSkipCustomListeners());
39
        JsonUtil::addField($json, self::SKIP_IO_MAPPINGS, $configuration->isSkipIoMappings());
40
        JsonUtil::addField($json, self::BATCH_ID, $configuration->getBatchId());
41
42
        return $json;
43
    }
44
45
    public function toObject(\stdClass $json, bool $isOrQuery = false)
46
    {
47
        return new MigrationBatchConfiguration(
48
            $this->readProcessInstanceIds($json),
49
            $this->readIdMappings($json),
50
            JsonUtil::asJavaObject(JsonUtil::getObject($json, self::MIGRATION_PLAN), MigrationPlanJsonConverter::instance()),
0 ignored issues
show
Bug introduced by
The method asJavaObject() does not exist on Jabe\Engine\Impl\Util\JsonUtil. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            JsonUtil::/** @scrutinizer ignore-call */ 
51
                      asJavaObject(JsonUtil::getObject($json, self::MIGRATION_PLAN), MigrationPlanJsonConverter::instance()),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
            JsonUtil::getBoolean($json, self::SKIP_LISTENERS),
52
            JsonUtil::getBoolean($json, self::SKIP_IO_MAPPINGS),
53
            JsonUtil::getString($json, self::BATCH_ID)
54
        );
55
    }
56
57
    protected function readProcessInstanceIds($jsonObject): array
58
    {
59
        return JsonUtil::asStringList(JsonUtil::getArray($jsonObject, self::PROCESS_INSTANCE_IDS));
60
    }
61
62
    protected function readIdMappings(\stdClass $json): DeploymentMappings
63
    {
64
        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...
65
    }
66
}
67