Issues (1256)

models/LoginAttempt.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace app\models;
4
5
use yii\db\ActiveRecord;
0 ignored issues
show
This use statement conflicts with another class in this namespace, app\models\ActiveRecord. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use yii\behaviors\TimestampBehavior;
7
8
/**
9
 * This is the model class for table "login_attempts".
10
 *
11
 * @property integer $id
12
 * @property string $key
13
 * @property integer $amount
14
 * @property integer $reset_at
15
 * @property integer $updated_at
16
 * @property integer $created_at
17
 *
18
 * @package app\models
19
 */
20
class LoginAttempt extends ActiveRecord
21
{
22
    /**
23
     * @inheritdoc
24
     */
25
    public static function tableName()
26
    {
27
        return 'login_attempts';
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function behaviors()
34
    {
35
        return [
36
            TimestampBehavior::class,
37
        ];
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function rules()
44
    {
45
        return [
46
            [
47
                [
48
                    'key'
49
                ],
50
                'required'
51
            ],
52
            [
53
                [
54
                    'amount',
55
                    'reset_at',
56
                    'updated_at',
57
                    'created_at'
58
                ],
59
                'integer'
60
            ],
61
            [
62
                [
63
                    'key'
64
                ],
65
                'string',
66
                'max' => 255
67
            ],
68
        ];
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function attributeLabels()
75
    {
76
        return [
77
            'id' => 'ID',
78
            'key' => 'Key',
79
            'amount' => 'Amount',
80
            'reset_at' => 'Reset At',
81
            'updated_at' => 'Updated At',
82
            'created_at' => 'Created At',
83
        ];
84
    }
85
}
86