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

createJobEntities()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 22
rs 9.7666
cc 4
nc 2
nop 5
1
<?php
2
3
namespace Jabe\Engine\Impl\Batch\Deletion;
4
5
use Jabe\Engine\Batch\BatchInterface;
6
use Jabe\Engine\Impl\ProcessInstanceQueryImpl;
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\ProcessInstanceQueryImpl 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
use Jabe\Engine\Impl\Batch\{
8
    AbstractBatchJobHandler,
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Batch\AbstractBatchJobHandler 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
    BatchEntity,
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Batch\BatchEntity 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...
10
    BatchJobConfiguration,
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Batch\BatchJobConfiguration 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...
11
    BatchJobContext,
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Batch\BatchJobContext 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...
12
    BatchJobDeclaration,
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Batch\BatchJobDeclaration 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...
13
    BatchElementConfiguration
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Batch\BatchElementConfiguration 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...
14
};
15
use Jabe\Engine\Impl\Cmd\DeleteProcessInstancesCmd;
16
use Jabe\Engine\Impl\Interceptor\CommandContext;
17
use Jabe\Engine\Impl\JobExecutor\{
18
    JobDeclaration,
19
    JobHandlerConfigurationInterface
20
};
21
use Jabe\Engine\Impl\Persistence\Entity\{
22
    ByteArrayEntity,
23
    ExecutionEntity,
24
    MessageEntity
25
};
26
27
class DeleteProcessInstancesJobHandler extends AbstractBatchJobHandler
28
{
29
    public static $JOB_DECLARATION;
30
31
    public function getType(): string
32
    {
33
        return BatchInterface::TYPE_PROCESS_INSTANCE_DELETION;
34
    }
35
36
    protected function getJsonConverterInstance(): DeleteProcessInstanceBatchConfigurationJsonConverter
37
    {
38
        return DeleteProcessInstanceBatchConfigurationJsonConverter::instance();
39
    }
40
41
    public function getJobDeclaration(): JobDeclaration
42
    {
43
        if (self::$JOB_DECLARATION == null) {
44
            self::$JOB_DECLARATION = new BatchJobDeclaration(BatchInterface::TYPE_PROCESS_INSTANCE_DELETION);
45
        }
46
        return self::$JOB_DECLARATION;
47
    }
48
49
    protected function createJobConfiguration(DeleteProcessInstanceBatchConfiguration $configuration, array $processIdsForJob): DeleteProcessInstanceBatchConfiguration
50
    {
51
        return new DeleteProcessInstanceBatchConfiguration($processIdsForJob, null, $configuration->getDeleteReason(), $configuration->isSkipCustomListeners(), $configuration->isSkipSubprocesses(), $configuration->isFailIfNotExists());
52
    }
53
54
    public function execute(JobHandlerConfigurationInterface $configuration, ExecutionEntity $execution, CommandContext $commandContext, ?string $tenantId): void
55
    {
56
        $configurationEntity = $commandContext
57
            ->getDbEntityManager()
58
            ->selectById(ByteArrayEntity::class, $configuration->getConfigurationByteArrayId());
0 ignored issues
show
Bug introduced by
The method getConfigurationByteArrayId() does not exist on Jabe\Engine\Impl\JobExec...rConfigurationInterface. ( Ignorable by Annotation )

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

58
            ->selectById(ByteArrayEntity::class, $configuration->/** @scrutinizer ignore-call */ getConfigurationByteArrayId());

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...
59
60
        $batchConfiguration = $this->readConfiguration($configurationEntity->getBytes());
61
62
        $commandContext->executeWithOperationLogPrevented(
63
            new DeleteProcessInstancesCmd(
64
                $batchConfiguration->getIds(),
65
                $batchConfiguration->getDeleteReason(),
66
                $batchConfiguration->isSkipCustomListeners(),
67
                true,
68
                $batchConfiguration->isSkipSubprocesses(),
69
                $batchConfiguration->isFailIfNotExists()
70
            )
71
        );
72
73
        $commandContext->getByteArrayManager()->delete($configurationEntity);
74
    }
75
76
    protected function createJobEntities(BatchEntity $batch, DeleteProcessInstanceBatchConfiguration $configuration, ?string $deploymentId, array $processIds, int $invocationsPerBatchJob): void
77
    {
78
        // handle legacy batch entities (no up-front deployment mapping has been done)
79
        if ($deploymentId == null && ($configuration->getIdMappings() == null || $configuration->getIdMappings()->isEmpty())) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $deploymentId of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
80
            // create deployment mappings for the ids to process
81
            $elementConfiguration = new BatchElementConfiguration();
82
            $query = new ProcessInstanceQueryImpl();
83
            $query->processInstanceIds($configuration->getIds());
84
            $elementConfiguration->addDeploymentMappings($query->listDeploymentIdMappings(), $configuration->getIds());
85
            // create jobs by deployment id
86
            $parent = parent;
0 ignored issues
show
Bug introduced by
The constant parent was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
87
            $elementConfiguration->getMappings()->forEach(function ($mapping) use ($parent, $batch, $configuration, $processIds, $invocationsPerBatchJob) {
88
                $parent->createJobEntities(
89
                    $batch,
90
                    $configuration,
91
                    $mapping->getDeploymentId(),
92
                    $mapping->getIds($processIds),
93
                    $invocationsPerBatchJob
94
                );
95
            });
96
        } else {
97
            parent::createJobEntities($batch, $configuration, $deploymentId, $processIds, $invocationsPerBatchJob);
98
        }
99
    }
100
}
101