Completed
Pull Request — master (#30)
by Matthew
07:24
created

StallableJobManager   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 73.08%

Importance

Changes 0
Metric Value
wmc 13
lcom 2
cbo 2
dl 0
loc 84
ccs 19
cts 26
cp 0.7308
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
stallableSave() 0 1 ?
stallableSaveHistory() 0 1 ?
A getDefaultMaxStalls() 0 4 1
A setDefaultMaxStalls() 0 4 1
A prioritySave() 0 14 4
A retryableSaveHistory() 0 16 4
A updateJobStalled() 0 4 1
A setStallableJobDefaults() 0 6 2
1
<?php
2
3
namespace Dtc\QueueBundle\Manager;
4
5
use Dtc\QueueBundle\Model\RetryableJob;
6
use Dtc\QueueBundle\Model\Job;
7
use Dtc\QueueBundle\Model\StallableJob;
8
9
abstract class StallableJobManager extends PriorityJobManager
10
{
11
    protected $defaultMaxStalls;
12
13
    abstract protected function stallableSave(StallableJob $job);
14
15 43
    protected function prioritySave(Job $job)
16
    {
17 43
        if (!$job instanceof StallableJob) {
18
            throw new \InvalidArgumentException('Job is not instanceof '.StallableJob::class);
19
        }
20
21 43
        if (!$job->getId()) {
22 43
            if ($job instanceof StallableJob) {
23 43
                $this->setStallableJobDefaults($job);
24
            }
25
        }
26
27 43
        return $this->stallableSave($job);
28
    }
29
30
    /**
31
     * @param StallableJob $job
32
     * @param $retry true if retry
33
     *
34
     * @return bool true if retry
35
     */
36
    abstract protected function stallableSaveHistory(StallableJob $job, $retry);
37
38
    /**
39
     * @return bool true if retry
40
     *
41
     * @param Job $job
42
     */
43 8
    protected function retryableSaveHistory(RetryableJob $job, $retry)
44
    {
45 8
        if (!$job instanceof StallableJob) {
46
            throw new \InvalidArgumentException('job not instance of '.StallableJob::class);
47
        }
48
49 8
        if ($retry) {
50 4
            return $this->stallableSaveHistory($job, $retry);
51
        }
52
53 8
        if (StallableJob::STATUS_STALLED === $job->getStatus()) {
54 2
            return $this->stallableSaveHistory($job, $this->updateJobStalled($job));
55
        }
56
57 6
        return $this->stallableSaveHistory($job, false);
58
    }
59
60
    /**
61
     * @param StallableJob $job
62
     *
63
     * @return bool false if
64
     */
65 2
    private function updateJobStalled(StallableJob $job)
66
    {
67 2
        return $this->updateJobMax($job, 'Stalls', StallableJob::STATUS_MAX_STALLS, true);
68
    }
69
70 43
    protected function setStallableJobDefaults(StallableJob $job)
71
    {
72 43
        if (null === $job->getMaxStalls()) {
73 43
            $job->setMaxStalls($this->defaultMaxStalls);
74
        }
75 43
    }
76
77
    /**
78
     * @return int|null
79
     */
80
    public function getDefaultMaxStalls()
81
    {
82
        return $this->defaultMaxStalls;
83
    }
84
85
    /**
86
     * @param int|null $defaultMaxStalled
0 ignored issues
show
Documentation introduced by
There is no parameter named $defaultMaxStalled. Did you maybe mean $defaultMaxStalls?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
87
     */
88
    public function setDefaultMaxStalls($defaultMaxStalls)
89
    {
90
        $this->defaultMaxStalls = $defaultMaxStalls;
91
    }
92
}
93