Passed
Push — master ( b2168e...f1daef )
by Paweł
03:26
created

NextUpdateCalculator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A getNextUpdateDate() 0 16 4
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 2019-02-13
6
 */
7
8
namespace app\components\traits;
9
10
11
use yii\db\ActiveRecord;
12
use yii\db\Expression;
13
14
trait NextUpdateCalculator
15
{
16
    /**
17
     * If true, then will be automatically calculate from invalidation_count.
18
     *
19
     * @param \app\models\Account|\app\models\Tag|ActiveRecord $model
20
     * @param int $interval
21
     * @return null|\yii\db\Expression
22
     */
23
    protected function getNextUpdateDate(ActiveRecord $model, $interval = null)
24
    {
25
        if ($interval === true) { // auto calculate
0 ignored issues
show
introduced by
The condition $interval === true is always false.
Loading history...
26
            $interval = 1;
27
            for ($i = 1; $i <= (int)$model->invalidation_count; $i++) {
28
                $interval *= $i;
29
            }
30
        }
31
32
        if (is_integer($interval)) {
33
            return new Expression('DATE_ADD(NOW(), INTERVAL :interval HOUR)', [
34
                'interval' => $interval,
35
            ]);
36
        }
37
38
        return $interval;
39
    }
40
}