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

MigrationInstructionJsonConverter::toJsonObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
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\Migration\MigrationInstructionImpl;
6
use Jabe\Engine\Impl\Util\JsonUtil;
7
use Jabe\Engine\Migration\MigrationInstructionInterface;
8
9
class MigrationInstructionJsonConverter extends JsonObjectConverter
10
{
11
    private static $INSTANCE;// = new MigrationInstructionJsonConverter();
0 ignored issues
show
introduced by
The private property $INSTANCE is not used, and could be removed.
Loading history...
12
13
    public const SOURCE_ACTIVITY_IDS = "sourceActivityIds";
14
    public const TARGET_ACTIVITY_IDS = "targetActivityIds";
15
    public const UPDATE_EVENT_TRIGGER = "updateEventTrigger";
16
17
    public function toJsonObject(/*MigrationInstructionInterface*/$instruction, bool $isOrQueryActive = false): ?\stdClass
18
    {
19
        $json = JsonUtil::createObject();
20
21
        JsonUtil::addArrayField($json, self::SOURCE_ACTIVITY_IDS, [$instruction->getSourceActivityId()]);
22
        JsonUtil::addArrayField($json, self::TARGET_ACTIVITY_IDS, [$instruction->getTargetActivityId()]);
23
        JsonUtil::addField($json, self::UPDATE_EVENT_TRIGGER, $instruction->isUpdateEventTrigger());
24
25
        return $json;
26
    }
27
28
    public function toObject(\stdClass $json, bool $isOrQuery = false)
29
    {
30
        return new MigrationInstructionImpl(
31
            $this->readSourceActivityId($json),
32
            $this->readTargetActivityId($json),
33
            JsonUtil::getBoolean($json, self::UPDATE_EVENT_TRIGGER)
34
        );
35
    }
36
37
    protected function readSourceActivityId($son): string
0 ignored issues
show
Unused Code introduced by
The parameter $son is not used and could be removed. ( Ignorable by Annotation )

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

37
    protected function readSourceActivityId(/** @scrutinizer ignore-unused */ $son): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        return JsonUtil::getString(JsonUtil::getArray($json, self::SOURCE_ACTIVITY_IDS));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $json does not exist. Did you maybe mean $son?
Loading history...
40
    }
41
42
    protected function readTargetActivityId($json): string
43
    {
44
        return JsonUtil::getString(JsonUtil::getArray($json, self::TARGET_ACTIVITY_IDS));
45
    }
46
}
47