Issues (2551)

src/Impl/Batch/DeleteBatchCmd.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Jabe\Impl\Batch;
4
5
use Jabe\History\UserOperationLogEntryInterface;
6
use Jabe\Impl\Interceptor\{
7
    CommandInterface,
8
    CommandContext
9
};
10
use Jabe\Impl\Persistence\Entity\PropertyChange;
11
use Jabe\Impl\Util\EnsureUtil;
12
13
class DeleteBatchCmd implements CommandInterface
14
{
15
    protected $cascadeToHistory;
16
    protected $batchId;
17
18
    public function __construct(string $batchId, bool $cascadeToHistory)
19
    {
20
        $this->batchId = $batchId;
21
        $this->cascadeToHistory = $cascadeToHistory;
22
    }
23
24
    public function execute(CommandContext $commandContext)
25
    {
26
        EnsureUtil::ensureNotNull("Batch id must not be null", "batch id", $this->batchId);
27
28
        $batchEntity = $commandContext->getBatchManager()->findBatchById($this->batchId);
29
        EnsureUtil::ensureNotNull("Batch for id '" . $this->batchId . "' cannot be found", "batch", $batchEntity);
30
31
        $this->checkAccess($commandContext, $batchEntity);
32
        $this->writeUserOperationLog($commandContext);
33
        $batchEntity->delete($this->cascadeToHistory, true);
34
35
        return null;
36
    }
37
38
    protected function checkAccess(CommandContext $commandContext, BatchEntity $batch): void
39
    {
40
        foreach ($commandContext->getProcessEngineConfiguration()->getCommandCheckers() as $checker) {
0 ignored issues
show
The method getCommandCheckers() does not exist on Jabe\Impl\Cfg\ProcessEngineConfigurationImpl. ( Ignorable by Annotation )

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

40
        foreach ($commandContext->getProcessEngineConfiguration()->/** @scrutinizer ignore-call */ getCommandCheckers() as $checker) {

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...
41
            $checker->checkDeleteBatch($batch);
42
        }
43
    }
44
45
    protected function writeUserOperationLog(CommandContext $commandContext): void
46
    {
47
        $commandContext->getOperationLogManager()
48
            ->logBatchOperation(
49
                UserOperationLogEntryInterface::OPERATION_TYPE_DELETE,
50
                $this->batchId,
51
                new PropertyChange("cascadeToHistory", null, $this->cascadeToHistory)
52
            );
53
    }
54
}
55