ScheduleInSecondInterval   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 24
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldBeScheduled() 0 4 1
A createCronJob() 0 11 2
getScheduleInterval() 0 1 ?
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace JMS\JobQueueBundle\Console;
6
7
use JMS\JobQueueBundle\Entity\Job;
8
use Symfony\Component\Console\Command\Command;
9
10
trait ScheduleInSecondInterval
11
{
12
    public function shouldBeScheduled(\DateTime $lastRunAt): bool
13
    {
14
        return time() - $lastRunAt->getTimestamp() >= $this->getScheduleInterval();
15
    }
16
17
    public function createCronJob(\DateTime $_): Job
0 ignored issues
show
Unused Code introduced by
The parameter $_ is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
        if ( ! $this instanceof Command) {
20
            throw new \LogicException('This trait must be used in Symfony console commands only.');
21
        }
22
23
        $job = new Job($this->getName());
24
        $job->setMaxRuntime((integer)min(300, $this->getScheduleInterval()));
0 ignored issues
show
Bug introduced by
The method getScheduleInterval() does not seem to exist on object<Symfony\Component\Console\Command\Command>.

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...
25
26
        return $job;
27
    }
28
29
    /**
30
     * @return integer
31
     */
32
    abstract protected function getScheduleInterval(): int;
33
}