Passed
Push — master ( e5a117...444e05 )
by Paweł
09:40
created

Proxy::tableName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace app\models;
4
5
use app\components\ArrayHelper;
6
use yii\behaviors\TimestampBehavior;
7
use yii\db\ActiveRecord;
8
9
/**
10
 * This is the model class for table "proxy".
11
 *
12
 * @property int $id
13
 * @property string $ip
14
 * @property int $port
15
 * @property string $username
16
 * @property string $password
17
 * @property int $active
18
 * @property string $updated_at
19
 * @property string $created_at
20
 * @property string $reservation_uid
21
 * @property int $rests [int(11)]
22
 * @property string $rest_until [datetime]
23
 *
24
 * @property string $curlString
25
 */
26
class Proxy extends ActiveRecord
27
{
28
29
    public function getCurlString()
30
    {
31
        $url = "{$this->ip}:{$this->port}";
32
        if ($this->username && $this->password) {
33
            return "{$this->username}:{$this->password}@{$url}";
34
        }
35
36
        return $url;
37
    }
38
39
    public function behaviors()
40
    {
41
        return ArrayHelper::merge(parent::behaviors(), [
42
            'time' => TimestampBehavior::class,
43
        ]);
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public static function tableName()
50
    {
51
        return 'proxy';
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public function rules()
58
    {
59
        return [
60
            [['ip', 'port'], 'required'],
61
            [['ip'], 'ip'],
62
            [['port', 'rests'], 'integer'],
63
            [['updated_at', 'created_at', 'rest_until'], 'safe'],
64
            [['ip', 'username', 'password', 'reservation_uid'], 'string', 'max' => 255],
65
            [['active'], 'boolean'],
66
        ];
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function attributeLabels()
73
    {
74
        return [
75
            'id' => 'ID',
76
            'ip' => 'Ip',
77
            'port' => 'Port',
78
            'username' => 'Username',
79
            'password' => 'Password',
80
            'active' => 'Active',
81
            'updated_at' => 'Updated At',
82
            'created_at' => 'Created At',
83
        ];
84
    }
85
86
    /**
87
     * @inheritdoc
88
     * @return ProxyQuery the active query used by this AR class.
89
     */
90
    public static function find()
91
    {
92
        return new ProxyQuery(get_called_class());
93
    }
94
}
95