Issues (37)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Parsers/UserAgentParser.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace Arcanedev\LaravelTracker\Parsers;
2
3
use Arcanedev\LaravelTracker\Contracts\Parsers\UserAgentParser as UserAgentParserContract;
4
5
/**
6
 * Class     UserAgentParser
7
 *
8
 * @package  Arcanedev\LaravelTracker\Parsers
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class UserAgentParser implements UserAgentParserContract
12
{
13
    /* -----------------------------------------------------------------
14
     |  Properties
15
     | -----------------------------------------------------------------
16
     */
17
18
    /** @var  \UAParser\Parser */
19
    protected $parser;
20
21
    /** @var string */
22
    public $basePath;
23
24
    /* -----------------------------------------------------------------
25
     |  Constructor
26
     | -----------------------------------------------------------------
27
     */
28
29
    /**
30
     * UserAgentParser constructor.
31
     *
32
     * @param  \UAParser\Parser  $parser
33
     * @param  string            $basePath
34
     * @param  null              $userAgent
35
     */
36 15
    public function __construct($parser, $basePath, $userAgent = null)
0 ignored issues
show
__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
    {
38 15
        if ( ! $userAgent && isset($_SERVER['HTTP_USER_AGENT'])) {
39
            $userAgent = $_SERVER['HTTP_USER_AGENT'];
40
        }
41
42 15
        $this->parser   = $parser->parse($userAgent);
0 ignored issues
show
Documentation Bug introduced by
It seems like $parser->parse($userAgent) of type object<UAParser\Result\Client> is incompatible with the declared type object<UAParser\Parser> of property $parser.

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...
43 15
        $this->basePath = $basePath;
44 15
    }
45
46
    /* -----------------------------------------------------------------
47
     |  Main Methods
48
     | -----------------------------------------------------------------
49
     */
50
51
    /**
52
     * Get the OS version.
53
     *
54
     * @return string
55
     */
56 9
    public function getOperatingSystemVersion()
57
    {
58 9
        $os = $this->getOperatingSystem();
59
60 9
        return $this->prepareVersion([$os->major, $os->minor, $os->patch]);
61
    }
62
63
    /**
64
     * Get the OS Family.
65
     *
66
     * @return string|null
67
     */
68 9
    public function getOperatingSystemFamily()
69
    {
70
        try {
71 9
            return $this->parser->os->family;
0 ignored issues
show
The property os does not seem to exist in UAParser\Parser.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
72
        }
73
        catch (\Exception $e) {
0 ignored issues
show
catch (\Exception $e) { return null; } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
74
            return null;
75
        }
76
    }
77
78
    /**
79
     * Get the browser.
80
     *
81
     * @return string
82
     */
83 9
    public function getBrowser()
84
    {
85 9
        return $this->getUserAgent()->family;
86
    }
87
88
    /**
89
     * Get the user agent version.
90
     *
91
     * @return string
92
     */
93 9
    public function getUserAgentVersion()
94
    {
95 9
        $ua = $this->getUserAgent();
96
97 9
        return $this->prepareVersion([$ua->major, $ua->minor, $ua->patch]);
98
    }
99
100
    /**
101
     * Get the original user agent.
102
     *
103
     * @return string
104
     */
105 9
    public function getOriginalUserAgent()
106
    {
107 9
        return $this->parser->originalUserAgent;
0 ignored issues
show
The property originalUserAgent does not seem to exist in UAParser\Parser.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
108
    }
109
110
    /**
111
     * Get the user agent.
112
     *
113
     * @return \UAParser\Result\UserAgent
114
     */
115 9
    public function getUserAgent()
116
    {
117 9
        return $this->parser->ua;
0 ignored issues
show
The property ua does not seem to exist in UAParser\Parser.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
118
    }
119
120
    /**
121
     * Get the operating system.
122
     *
123
     * @return \UAParser\Result\OperatingSystem
124
     */
125 9
    public function getOperatingSystem()
126
    {
127 9
        return $this->parser->os;
0 ignored issues
show
The property os does not seem to exist in UAParser\Parser.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
128
    }
129
130
    /**
131
     * Get the device.
132
     *
133
     * @return \UAParser\Result\Device
134
     */
135
    public function getDevice()
136
    {
137
        return $this->parser->device;
0 ignored issues
show
The property device does not seem to exist. Did you mean deviceParser?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
138
    }
139
140
    /* -----------------------------------------------------------------
141
     |  Other Methods
142
     | -----------------------------------------------------------------
143
     */
144
145
    /**
146
     * Prepare the version.
147
     *
148
     * @param  array  $version
149
     *
150
     * @return string
151
     */
152 12
    protected function prepareVersion(array $version)
153
    {
154 12
        return implode('.', array_filter($version));
155
    }
156
}
157