GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Nip_Mobile_Detect   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 79
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 16 7
A __call() 0 8 2
A isMobile() 0 3 1
A isDevice() 0 10 4
1
<?php
2
3
/**
4
 * Nip Framework
5
 *
6
 * @category   Nip
7
 * @copyright  2009 Nip Framework
8
 * @license    http://www.opensource.org/licenses/mit-license.php The MIT License
9
 * @version    SVN: $Id: Mobile_Detect.php 115 2009-05-21 12:48:26Z victor.stanciu $
10
 */
11
12
class Nip_Mobile_Detect {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
    
14
    protected $accept;
15
    protected $userAgent;
16
    
17
    protected $isMobile     = false;
18
    protected $isAndroid    = null;
19
    protected $isBlackberry = null;
20
    protected $isOpera      = null;
21
    protected $isPalm       = null;
22
    protected $isWindows    = null;
23
    protected $isGeneric    = null;
24
25
    protected $devices = array(
26
        "android"       => "android",
27
        "blackberry"    => "blackberry",
28
        "iphone"        => "(iphone|ipod)",
29
        "opera"         => "opera mini",
30
        "palm"          => "(avantgo|blazer|elaine|hiptop|palm|plucker|xiino)",
31
        "windows"       => "windows ce; (iemobile|ppc|smartphone)",
32
        "generic"       => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap)"
33
    );
34
35
36
    public function __construct() {
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
37
        $this->userAgent = $_SERVER['HTTP_USER_AGENT'];
38
        $this->accept    = $_SERVER['HTTP_ACCEPT'];
39
40
        if (isset($_SERVER['HTTP_X_WAP_PROFILE'])|| isset($_SERVER['HTTP_PROFILE'])) {
41
            $this->isMobile = true;
42
        } elseif (strpos($this->accept,'text/vnd.wap.wml') > 0 || strpos($accept,'application/vnd.wap.xhtml+xml') > 0) {
0 ignored issues
show
Bug introduced by
The variable $accept does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
43
            $this->isMobile = true;
44
        } else {
45
            foreach ($this->devices as $device => $regexp) {
46
                if ($this->isDevice($device)) {
47
                    $this->isMobile = true;
48
                }
49
            }
50
        }
51
    }
52
53
54
    /**
55
     * Overloads isAndroid() | isBlackberry() | isOpera() | isPalm() | isWindows() | isGeneric() through isDevice()
56
     *
57
     * @param string $name
58
     * @param array $arguments
59
     * @return bool
60
     */
61
    public function __call($name, $arguments) {
62
        $device = substr($name, 2);
63
        if ($name == "is" . ucfirst($device)) {
64
            return $this->isDevice($device);
65
        } else {
66
            trigger_error("Method $name not defined", E_USER_ERROR);
67
        }
68
    }
69
70
71
    /**
72
     * Returns true if any type of mobile device detected, including special ones
73
     * @return bool
74
     */
75
    public function isMobile() {
76
        return $this->isMobile;
77
    }
78
79
80
    protected function isDevice($device) {
81
        $var    = "is" . ucfirst($device);
82
        $return = $this->$var === null ? (bool) preg_match("/" . $this->devices[$device] . "/i", $this->userAgent) : $this->$var;
83
84
        if ($device != 'generic' && $return == true) {
85
            $this->isGeneric = false;
86
        }
87
88
        return $return;
89
    }
90
}