Completed
Push — master ( 94d3aa...1e9c69 )
by Iman
05:12
created

CacheNormalizer::normalize()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 4
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\Widgets\Utils\Normalizers;
4
5
class CacheNormalizer
6
{
7
    /**
8
     * ّFigures out how long the cache life time should be.
9
     * @param object $widget
10
     * @return null
11
     */
12 16
    public function normalize($widget)
13
    {
14 16
        if (! property_exists($widget, 'cacheLifeTime')) {
15 13
            $widget->cacheLifeTime = (int) (config('widgetize.default_cache_lifetime', 0));
16
        }
17
18 16
        if ($widget->cacheLifeTime === 'forever' || $widget->cacheLifeTime < 0) {
19
            // 20.000 minutes is about 2 weeks which is long enough !
20 2
            $widget->cacheLifeTime = 20000;
21
        }
22 16
    }
23
}
24