Test Failed
Push — main ( 92cbf8...131025 )
by Bingo
08:08
created

DefaultDeploymentHandler::resourcesDiffer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Jabe\Engine\Impl\Repository;
4
5
use Jabe\Engine\{
6
    ProcessEngineInterface,
7
    RepositoryServiceInterface
8
};
9
use Jabe\Engine\Impl\Context\Context;
10
use Jabe\Engine\Repository\{
11
    CandidateDeploymentInterface,
12
    DeploymentInterface,
13
    DeploymentHandlerInterface,
14
    ProcessDefinitionInterface,
15
    ResourceInterface
16
};
17
18
class DefaultDeploymentHandler implements DeploymentHandlerInterface
19
{
20
    protected $processEngine;
21
    protected $repositoryService;
22
23
    public function __construct(ProcessEngineInterface $processEngine)
24
    {
25
        $this->processEngine = $processEngine;
26
        $this->repositoryService = $processEngine->getRepositoryService();
27
    }
28
29
    public function shouldDeployResource(ResourceInterface $newResource, ResourceInterface $existingResource): bool
30
    {
31
        return $this->resourcesDiffer($newResource, $existingResource);
32
    }
33
34
    public function determineDuplicateDeployment(CandidateDeploymentInterface $candidateDeployment): string
35
    {
36
        return Context::getCommandContext()
0 ignored issues
show
Bug Best Practice introduced by
The expression return Jabe\Engine\Impl\...nt->getName())->getId() could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
37
            ->getDeploymentManager()
38
            ->findLatestDeploymentByName($candidateDeployment->getName())
39
            ->getId();
40
    }
41
42
    public function determineDeploymentsToResumeByProcessDefinitionKey(array $processDefinitionKeys): array
43
    {
44
45
        $deploymentIds = [];
46
        $processDefinitions = Context::getCommandContext()->getProcessDefinitionManager()
47
            ->findProcessDefinitionsByKeyIn($processDefinitionKeys);
48
        foreach ($processDefinitions as $processDefinition) {
49
            $deploymentIds[] = $processDefinition->getDeploymentId();
50
        }
51
52
        return array_unique($deploymentIds);
53
    }
54
55
    public function determineDeploymentsToResumeByDeploymentName(CandidateDeploymentInterface $candidateDeployment): array
56
    {
57
        $previousDeployments = $processEngine->getRepositoryService()
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $processEngine seems to be never defined.
Loading history...
58
            ->createDeploymentQuery()
59
            ->deploymentName($candidateDeployment->getName())
60
            ->list();
61
62
        $deploymentIds = [];
63
        foreach ($previousDeployments as $deployment) {
64
            $deploymentIds[] = $deployment->getId();
65
        }
66
67
        return array_unique($deploymentIds);
68
    }
69
70
    protected function resourcesDiffer(ResourceInterface $resource, ResourceInterface $existing): bool
71
    {
72
        $bytes = $resource->getBytes();
0 ignored issues
show
Bug introduced by
The method getBytes() does not exist on Jabe\Engine\Repository\ResourceInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Engine\Repository\ResourceInterface. ( Ignorable by Annotation )

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

72
        /** @scrutinizer ignore-call */ 
73
        $bytes = $resource->getBytes();
Loading history...
73
        $savedBytes = $existing->getBytes();
74
        return $bytes != $savedBytes;
75
    }
76
}
77