Completed
Pull Request — master (#9)
by graychen
01:47
created

Queue::getStatus()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 1
crap 20
1
<?php
2
namespace graychen\yii2\queue\backend\models;
3
4
use Yii;
5
use yii\behaviors\TimestampBehavior;
6
use yii\db\ActiveRecord;
7
8
class Queue extends ActiveRecord
9
{
10
    /**
11
     * @inheritdoc
12
     */
13 2
    public static function tableName()
14
    {
15 2
        return '{{%queue}}';
16
    }
17
18
    /**
19
     * @inheritdoc
20
     */
21 4
    public function behaviors()
22
    {
23
        return [
24
            'timestamp' => [
25 4
                'class' => TimestampBehavior::className(),
26
            ]
27
        ];
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33 1
    public function rules()
34
    {
35
        return [
36 1
            [['queue_id', 'catalog', 'name', 'description'], 'required']
37
        ];
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43 1
    public function attributeLabels()
44
    {
45
        return [
46 1
            'id' => Yii::t('app/queue', 'ID'),
47 1
            'queue_id' => Yii::t('app/queue', '队列id'),
48 1
            'catalog' => Yii::t('app/queue', '类别'),
49 1
            'name' => Yii::t('app/queue', '任务名称'),
50 1
            'description' => Yii::t('app/queue', '详请信息'),
51 1
            'exec_time' => Yii::t('app/queue', '执行时间'),
52 1
            'status' => Yii::t('app/queue', '状态'),
53 1
            'created_at' => Yii::t('app/queue', '队列创建时间'),
54 1
            'updated_at' => Yii::t('app/queue', '队列修改时间'),
55 1
            'execution_time' => Yii::t('app/queue', '队列执行时间')
56
        ];
57
    }
58
59 1
    public function getExecutionTime()
60
    {
61 1
        return $this->exec_time+$this->created_at;
0 ignored issues
show
Documentation introduced by
The property exec_time does not exist on object<graychen\yii2\queue\backend\models\Queue>. 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...
Documentation introduced by
The property created_at does not exist on object<graychen\yii2\queue\backend\models\Queue>. 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...
62
    }
63
64
    public function getStatus($id)
65
    {
66
        if (Yii::$app->queue->isWaiting($id) || Yii::$app->queue->isReserved($id)) {
67
            $status=0;
68
        } elseif (Yii::$app->queue->isDone($id)) {
69
            $status=1;
70
        } else {
71
            $status=-1;
72
        }
73
        return $status;
74
    }
75
}
76