Issues (2551)

src/Impl/Cmd/DeleteJobsCmd.php (2 issues)

1
<?php
2
3
namespace Jabe\Impl\Cmd;
4
5
use Jabe\Impl\Context\Context;
6
use Jabe\Impl\Interceptor\{
7
    CommandInterface,
8
    CommandContext
9
};
10
11
class DeleteJobsCmd implements CommandInterface
12
{
13
    protected $jobIds = [];
14
    protected $cascade;
15
16
    public function __construct($jobIds, ?bool $cascade = false)
17
    {
18
        if (is_string($jobIds)) {
19
            $this->jobIds[] = $jobIds;
20
        } elseif (is_array($jobIds)) {
21
            $this->jobIds = $jobIds;
22
        }
23
        $this->cascade = $cascade;
24
    }
25
26
    public function execute(CommandContext $commandContext)
27
    {
28
        $jobToDelete = null;
0 ignored issues
show
The assignment to $jobToDelete is dead and can be removed.
Loading history...
29
        foreach ($this->jobIds as $jobId) {
30
            $jobToDelete = Context::getCommandContext()
31
            ->getJobManager()
32
            ->findJobById($jobId);
33
34
            if ($jobToDelete !== null) {
35
                // When given job doesn't exist, ignore
36
                $jobToDelete->delete();
37
38
                if ($this->cascade) {
39
                    $commandContext
40
                    ->getHistoricJobLogManager()
41
                    ->deleteHistoricJobLogByJobId($this->jobId);
0 ignored issues
show
The property jobId does not exist on Jabe\Impl\Cmd\DeleteJobsCmd. Did you mean jobIds?
Loading history...
42
                }
43
            }
44
        }
45
        return null;
46
    }
47
}
48