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

instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 0
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 SetExternalTaskRetriesBatchConfigurationJsonConverter extends JsonObjectConverter
14
{
15
    public static $INSTANCE;
16
    public const EXTERNAL_TASK_IDS = "externalTaskIds";
17
    public const EXTERNAL_TASK_ID_MAPPINGS = "externalTaskIdMappingss";
18
    public const RETRIES = "retries";
19
20
    public static function instance(): SetExternalTaskRetriesBatchConfigurationJsonConverter
21
    {
22
        if (self::$INSTANCE == null) {
23
            self::$INSTANCE = new SetExternalTaskRetriesBatchConfigurationJsonConverter();
24
        }
25
        return self::$INSTANCE;
26
    }
27
28
    public function toJsonObject($configuration): \stdClass
29
    {
30
        $json = JsonUtil::createObject();
31
        JsonUtil::addListField($json, self::EXTERNAL_TASK_IDS, $configuration->getIds());
32
        JsonUtil::addListField($json, self::EXTERNAL_TASK_ID_MAPPINGS, DeploymentMappingJsonConverter::instance(), $configuration->getIdMappings());
33
        JsonUtil::addField($json, self::RETRIES, $configuration->getRetries());
34
        return $json;
35
    }
36
37
    public function toObject(\stdClass $json)
38
    {
39
        return new SetRetriesBatchConfiguration($this->readExternalTaskIds($json), $this->readIdMappings($json), JsonUtil::getInt($json, self::RETRIES));
40
    }
41
42
    protected function readExternalTaskIds(\stdClass $json): array
43
    {
44
        return JsonUtil::asStringList(JsonUtil::getArray($json, self::EXTERNAL_TASK_IDS));
45
    }
46
47
    protected function readIdMappings(\stdClass $json): DeploymentMappings
48
    {
49
        return JsonUtil::asList(JsonUtil::getArray($json, self::EXTERNAL_TASK_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...
50
    }
51
}
52