UserAgentHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 34
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isGooglePageSpeed() 0 9 4
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
0 ignored issues
show
Coding Style introduced by
The property $_cache is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
19
{
20
    /**
21
     * @var bool
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
     *
36
     * @see https://stackoverflow.com/questions/29162881
37
     *
38
     * @param bool $useCache
39
     *
40
     * @return bool
41
     */
42
    public static function isGooglePageSpeed($useCache = true)
43
    {
44
        if (null === self::$_cache || false === $useCache) {
45
            $userAgent = Yii::$app->getRequest()->getUserAgent();
46
            self::$_cache = (null !== $userAgent) && (false !== stripos($userAgent, 'Speed Insights'));
47
        }
48
49
        return self::$_cache;
50
    }
51
}
52