Passed
Push — master ( 6b49ff...b93f48 )
by Paweł
05:24
created

UserAgent   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A random() 0 12 1
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 11.01.2018
6
 */
7
8
namespace app\components\http;
9
10
11
use yii\base\Component;
12
use yii\caching\Cache;
13
use yii\di\Instance;
14
15
class UserAgent extends Component
16
{
17
    public $cache = 'cache';
18
19
    /**
20
     * @return mixed
21
     * @throws \yii\base\InvalidConfigException
22
     */
23
    public function random()
24
    {
25
        /** @var \yii\caching\Cache $cache */
26
        $cache = Instance::ensure($this->cache);
27
28
        $items = $cache->getOrSet(__METHOD__, function(Cache $cache) {
0 ignored issues
show
Unused Code introduced by
The parameter $cache is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
        $items = $cache->getOrSet(__METHOD__, function(/** @scrutinizer ignore-unused */ Cache $cache) {

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

Loading history...
29
            return (new \jakim\ua\UserAgent())->fetch();
30
        }, 60 * 60 * 24 * 30);
31
32
        shuffle($items);
33
34
        return $items['0'];
35
    }
36
}