UserAgent   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
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\di\Instance;
13
14
class UserAgent extends Component
15
{
16
    public $cache = 'cache';
17
18
    /**
19
     * @return mixed
20
     * @throws \yii\base\InvalidConfigException
21
     */
22
    public function random()
23
    {
24
        /** @var \yii\caching\Cache $cache */
25
        $cache = Instance::ensure($this->cache);
26
27
        $items = $cache->getOrSet(__METHOD__, function() {
28
            return (new \jakim\ua\UserAgent())->fetch();
29
        }, 60 * 60 * 24 * 30);
30
31
        shuffle($items);
0 ignored issues
show
Bug introduced by
It seems like $items can also be of type false; however, parameter $array of shuffle() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

31
        shuffle(/** @scrutinizer ignore-type */ $items);
Loading history...
32
33
        return $items['0'];
34
    }
35
}