UserIdentity::authenticate()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.439
c 0
b 0
f 0
cc 5
eloc 19
nc 8
nop 0
1
<?php
2
3
/**
4
 * UserIdentity represents the data needed to identity a user.
5
 * It contains the authentication method that checks if the provided
6
 * data can identity the user.
7
 * @property integer $uid
8
 */
9
class UserIdentity extends CUserIdentity
10
{
11
    private $uid;
12
    private $findEmail;
13
14
    /**
15
     * Authenticates a user.
16
     * @return boolean whether authentication succeeds.
17
     */
18
    public function authenticate()
19
    {
20
        if (strpos($this->username, "@")) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal @ does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
21
            $this->findEmail = true;
22
            $account = Account::model()->find('LOWER(email) = :email', [':email' => strtolower($this->username)]);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
23
        } else {
24
            $this->findEmail = false;
25
            $account = Account::model()->find('username = :username', [':username' => $this->username]);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
26
        }
27
28
        if ($account===null) {
29
            $this->errorCode = self::ERROR_USERNAME_INVALID;
30
        } elseif (!$account->validatePassword($this->password)) {
31
            $this->errorCode=self::ERROR_PASSWORD_INVALID;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
32
        } else {
33
            //check player
34
            if ($this->playerExists($account->id)) {
35
                $this->uid=$account->id;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 0 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
36
                $this->username=$account->username;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 0 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
37
                $this->errorCode=self::ERROR_NONE;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 0 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
38
            } else {
39
                $this->errorCode=3; //username exists without player
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
40
            }
41
        }
42
        return $this->errorCode==self::ERROR_NONE;
43
    }
44
45
    /**
46
     * @return integer the ID of the user record
47
     */
48
    public function getUid()
49
    {
50
        return $this->uid;
51
    }
52
    public function getFindEmail()
53
    {
54
        return $this->findEmail;
55
    }
56
57
    /**
58
     * @param integer $uid
59
     */
60 View Code Duplication
    private function playerExists($uid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
61
    {
62
        $foundUid = Yii::app()->db->createCommand()
63
            ->select('uid')
64
            ->from('main')
65
            ->where('uid=:uid', [':uid'=>$uid])
66
            ->queryScalar();
67
        return $foundUid > 0;
68
    }
69
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
70