ApiTimeCalculator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isCallStillValid() 0 5 3
A calculateEarliestNextCall() 0 8 1
1
<?php
2
namespace Tarioch\EveapiFetcherBundle\Component\Worker;
3
4
use JMS\DiExtraBundle\Annotation as DI;
5
use Tarioch\EveapiFetcherBundle\Entity\ApiCall;
6
7
/**
8
 * @DI\Service(public=false)
9
 */
10
class ApiTimeCalculator
11
{
12
    /**
13
     * @param ApiCall|null $call
14
     * @return boolean
15
     */
16
    public function isCallStillValid(ApiCall $call = null)
17
    {
18
        $now = new \DateTime('now', new \DateTimeZone('UTC'));
19
        return $call !== null && $call->getCachedUntil() < $now && $call->getEarliestNextCall() < $now;
20
    }
21
22
    public function calculateEarliestNextCall(ApiCall $call)
23
    {
24
        $minutesToEarliestNextCall = $call->getApi()->getCallInterval() * (1 + $call->getErrorCount());
25
        $earliestNextCall = new \DateTime('now', new \DateTimeZone('UTC'));
26
        $earliestNextCall->add(new \DateInterval('PT' . $minutesToEarliestNextCall . 'M'));
27
28
        return $earliestNextCall;
29
    }
30
}
31