Test Failed
Push — master ( 48da91...4d2acf )
by Nicklas
01:59
created

User::userExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Nicklas\Comment\Modules;
4
5
/**
6
 * A database driven model.
7
 */
8
class User extends ActiveRecordModelExtender
9
{
10
11
        /**
12
     * @var string $tableName name of the database table.
13
     */
14
    protected $tableName = "ramverk1_users";
15
16
    /**
17
     * Columns in the table.
18
     *
19
     * @var integer $id primary key auto incremented.
20
     */
21
    public $id;
22
    public $name;
23
    public $email;
24
    public $pass;
25
    public $authority = "user";
26
    public $question;
27
28
29
    /**
30
     * Check if user exists
31
     *
32
     * @param string $name
33
     *
34
     * @return boolean true if user exists in database else false
35
     */
36
    public function userExists($name)
37
    {
38
        $user = $this->find("name", $name);
39
        return !$user ? false : true;
40
    }
41
    /**
42
     * Returns gravatar link
43
     *
44
     * @param string $email
0 ignored issues
show
Bug introduced by
There is no parameter named $email. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     *
46
     * @return string as gravatar link
47
     */
48
    public function setGravatar()
49
    {
50
        $this->img = $this->gravatar($this->email);
0 ignored issues
show
Bug introduced by
The property img 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...
51
    }
52
53
54
    /**
55
     * Set the pass.
56
     *
57
     * @param string $pass the pass to use.
58
     *
59
     * @return void
60
     */
61
    public function setPassword($pass)
62
    {
63
        $this->pass = password_hash($pass, PASSWORD_DEFAULT);
64
    }
65
66
    /**
67
     * Verify the name and the pass, if successful the object contains
68
     * all details from the database row.
69
     *
70
     * @param string $name  name to check.
71
     * @param string $pass the pass to use.
72
     *
73
     * @return boolean true if name and pass matches, else false.
74
     */
75
    public function verifyPassword($name, $pass)
76
    {
77
        $this->find("name", $name);
78
        return password_verify($pass, $this->pass);
79
    }
80
81
    /**
82
     * Verify the name and the anaswer, if successful the object contains
83
     * all details from the database row.
84
     *
85
     * @param string $name  name to check.
86
     * @param string $answer the answer.
87
     *
88
     * @return boolean true if name and pass matches, else false.
89
     */
90
    public function verifyQuestion($name, $answer)
91
    {
92
        $this->find("name", $name);
93
        return ($this->question == $answer);
94
    }
95
}
96