Passed
Push — main ( 6fd589...d01f4c )
by Bingo
05:51
created

toObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 8
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Jabe\Engine\Impl\Batch\ExternalTask;
4
5
use Jabe\Engine\Impl\Batch\{
6
    DeploymentMappingJsonConverter,
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Batch\D...entMappingJsonConverter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
    DeploymentMappings,
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Batch\DeploymentMappings was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
    SetRetriesBatchConfiguration
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Batch\S...triesBatchConfiguration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
};
10
use Jabe\Engine\Impl\Json\JsonObjectConverter;
11
use Jabe\Engine\Impl\Util\JsonUtil;
12
13
class SetJobRetriesBatchConfigurationJsonConverter extends JsonObjectConverter
14
{
15
    public static $INSTANCE;
16
17
    public const JOB_IDS = "jobIds";
18
    public const JOB_ID_MAPPINGS = "jobIdMappings";
19
    public const RETRIES = "retries";
20
21
    public static function instance(): SetJobRetriesBatchConfigurationJsonConverter
22
    {
23
        if (self::$INSTANCE == null) {
24
            self::$INSTANCE = new SetJobRetriesBatchConfigurationJsonConverter();
25
        }
26
        return self::$INSTANCE;
27
    }
28
29
    public function toJsonObject($configuration): \stdClass
30
    {
31
        $json = JsonUtil::createObject();
32
        JsonUtil::addListField($json, self::JOB_IDS, $configuration->getIds());
33
        JsonUtil::addListField($json, self::JOB_ID_MAPPINGS, DeploymentMappingJsonConverter::instance(), $configuration->getIdMappings());
34
        JsonUtil::addField($json, self::RETRIES, $configuration->getRetries());
35
        return $json;
36
    }
37
38
    public function toObject(\stdClass $json)
39
    {
40
        $configuration = new SetRetriesBatchConfiguration(
41
            $this->readJobIds($json),
42
            $this->readIdMappings($json),
43
            JsonUtil::getInt($json, self::RETRIES)
44
        );
45
        return $configuration;
46
    }
47
48
    protected function readJobIds(\stdClass $jsonObject): array
49
    {
50
        return JsonUtil::asStringList(JsonUtil::getArray($jsonObject, self::JOB_IDS));
51
    }
52
53
    protected function readIdMappings(\stdClass $jsonObject): DeploymentMappings
54
    {
55
        return JsonUtil::asList(JsonUtil::getArray($jsonObject, self::JOB_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...
56
    }
57
}
58