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

CacheNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 16
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 9 4
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