Completed
Push — master ( a59d38...b7ac7f )
by Vladimir
05:36 queued 15s
created

UserAgentHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @link https://github.com/yiimaker/yii2-helpers
4
 * @copyright Copyright (c) 2017 Yii Maker
5
 * @license BSD 3-Clause License
6
 */
7
8
namespace ymaker\helpers;
9
10
use Yii;
11
12
/**
13
 * User agent helper.
14
 *
15
 * @author Vladimir Kuprienko <[email protected]>
16
 * @since 1.0
17
 */
18
class UserAgentHelper
19
{
20
    /**
21
     * @var null|string
22
     */
23
    private static $_cache;
24
25
26
    /**
27
     * This class should not be instantiated.
28
     */
29
    private function __construct()
30
    {
31
    }
32
33
    /**
34
     * Check whether user agent is a Google Page Speed Insights.
35
     * @see https://stackoverflow.com/questions/29162881
36
     *
37
     * @param bool $useCache
38
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
39
     */
40
    public static function isGooglePageSpeed($useCache = true)
41
    {
42
        if (null === self::$_cache || false === $useCache) {
43
            $userAgent = Yii::$app->getRequest()->getUserAgent();
44
            self::$_cache = (null !== $userAgent) && (false !== stripos($userAgent, 'Speed Insights'));
0 ignored issues
show
Documentation Bug introduced by
It seems like null !== $userAgent && f...gent, 'Speed Insights') of type boolean is incompatible with the declared type null|string of property $_cache.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
        }
46
47
        return self::$_cache;
48
    }
49
}
50