user::GetPlayerSummaries()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
$user = new user;
3
4
class user
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...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
5
{
6
    public function GetPlayerSummaries($steamid)
7
    {
8
        $settings = require('config/settings.php');
9
        $response = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $settings['steamAPI'] . '&steamids=' . $steamid);
10
        $json = json_decode($response);
11
        return $json->response->players[0];
12
    }
13
14
    public function signIn()
15
    {
16
        $settings = require('config/settings.php');
17
        if ($settings['steamlogin']) {
18
            require_once 'openid.php';
19
            $openid = new LightOpenID($settings['url']);
20
            if (!$openid->mode) {
0 ignored issues
show
Documentation introduced by
The property mode does not exist on object<LightOpenID>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
21
                $openid->identity = 'http://steamcommunity.com/openid';
0 ignored issues
show
Documentation introduced by
The property $identity is declared private in LightOpenID. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
22
                header('Location: ' . $openid->authUrl());
23
            } elseif ($openid->mode == 'cancel') {
0 ignored issues
show
Documentation introduced by
The property mode does not exist on object<LightOpenID>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
24
                print ('User has canceled authentication!');
25
            } else {
26
                if ($openid->validate()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $openid->validate() of type false|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
27
                    preg_match("/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/", $openid->identity, $matches);
0 ignored issues
show
Documentation introduced by
The property $identity is declared private in LightOpenID. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
28
                    $_SESSION['playerid'] = $matches[1];
29
30
                    $db_connection = masterConnect();
31
32
                    $sql = "SELECT user_name, user_email, user_level, user_profile, permissions, user_password_hash, user_id
33
                            FROM users WHERE playerid = '" . $_SESSION['playerid'] . "';";
34
                    $result_of_login_check = $db_connection->query($sql);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $result_of_login_check exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
35
36
                    if ($result_of_login_check->num_rows == 1) {
37
                        $result_row = $result_of_login_check->fetch_object();
38
                        if ($result_row->user_level <> 0) {
39
                            $_SESSION['user_name'] = $result_row->user_name;
40
                            $_SESSION['user_level'] = $result_row->user_level;
41
                            $_SESSION['user_profile'] = $result_row->user_profile;
42
                            $_SESSION['user_email'] = $result_row->user_email;
43
                            $_SESSION['user_id'] = $result_row->user_id;
44
                            $_SESSION['permissions'] = json_decode($result_row->permissions, true);
45 View Code Duplication
                            if (isset($result_row->items)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
                                $_SESSION['items'] = $result_row->items;
47
                            } else {
48
                                $_SESSION['items'] = $settings['items'];
49
                            }
50
                            if (isset($_POST['lang'])) {
51
                                $_SESSION['lang'] = $_POST['lang'];
52
                            }
53
                            $_SESSION['user_login_status'] = 1;
54
                            $_SESSION['steamsignon'] = false; //used to determine if its a single sign on with no account
55
                            multiDB();
56
57
                            logAction($_SESSION['user_name'], 'Successful Steam Login (' . $_SERVER['REMOTE_ADDR'] . ')', 2);
58 View Code Duplication
                        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
                            $this->errors[] = "User is banned.";
0 ignored issues
show
Bug introduced by
The property errors does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
60
                            logAction($_POST['user_name'], 'Steam Login Failed - Banned User (' . $_SERVER['REMOTE_ADDR'] . ')', 3);
61
                        }
62
                    } else {
63
                        if ($settings['annonlogin']) {
64
                            $permissions = require('config/permissions.php');
65
                            $steam = $this->GetPlayerSummaries($_SESSION['playerid']);
66
                            $_SESSION['user_name'] = $steam->personaname;
67
                            $_SESSION['user_level'] = 1;
68
                            $_SESSION['user_profile'] = $steam->avatarmedium;
69
                            $_SESSION['permissions'] = $permissions[1];
70
                            $_SESSION['items'] = $settings['items'];
71
                            $_SESSION['user_login_status'] = 1;
72
                            $_SESSION['profile_link'] = $steam->profileurl;
73
                            $_SESSION['steamsignon'] = true; //used to determine if its a single sign on with no account
74
                            multiDB();
75
76
                            logAction($_SESSION['user_name'], 'Successful Steam Login (' . $_SERVER['REMOTE_ADDR'] . ')', 2);
77
                        } else {
78
                            errorMessage(7);
0 ignored issues
show
Bug introduced by
The call to errorMessage() misses a required argument $lang.

This check looks for function calls that miss required arguments.

Loading history...
Unused Code introduced by
The call to the function errorMessage() seems unnecessary as the function has no side-effects.
Loading history...
79
                        }
80
                    }
81
                    header('Location: ' . $settings['url']);
82
                    exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method signIn() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
83
                } else {
84
                    print ('Error');
85
                }
86
            }
87
        }
88
    }
89
}
90
91
if (isset($_GET['login'])) {
92
    $user->signIn();
93
}
94
if ($settings['steamlogin']) {
95
    print ('<form action="?login" method="post"><input type="image"
96
    src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_noborder.png"/>
97
    </form>');
98
}