Completed
Pull Request — master (#17)
by zacksleo
03:34 queued 17s
created

Queue::getStatus()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 5.2596

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 4
cts 7
cp 0.5714
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 1
crap 5.2596
1
<?php
2
3
namespace graychen\yii2\queue\backend\models;
4
5
use graychen\yii2\queue\backend\Module;
6
use Yii;
7
use yii\behaviors\TimestampBehavior;
8
use yii\db\ActiveRecord;
9
10
class Queue extends ActiveRecord
11
{
12
    /**
13
     * @inheritdoc
14
     */
15 5
    public static function tableName()
16
    {
17 5
        return '{{%queue}}';
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23 6
    public function behaviors()
24
    {
25
        return [
26
            'timestamp' => [
27 6
                'class' => TimestampBehavior::className(),
28
            ]
29
        ];
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 4
    public function rules()
36
    {
37
        return [
38 4
            [['queue_id', 'catalog', 'name', 'description'], 'required']
39
        ];
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45 2
    public function attributeLabels()
46
    {
47
        return [
48 2
            'id' => Module::t('queue', 'ID'),
49 2
            'queue_id' => Module::t('queue', 'Queue ID'),
50 2
            'catalog' => Module::t('queue', 'Catalog'),
51 2
            'name' => Module::t('queue', 'Name'),
52 2
            'description' => Module::t('queue', 'Description'),
53 2
            'exec_time' => Module::t('queue', 'Exec Time'),
54 2
            'status' => Module::t('queue', 'Status'),
55 2
            'created_at' => Module::t('queue', 'Created At'),
56 2
            'updated_at' => Module::t('queue', 'Updated At'),
57
        ];
58
    }
59
60 1
    public function getExecutionTime()
61
    {
62 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...
63
    }
64
65 1
    public function getStatus($id)
66
    {
67 1
        if (Yii::$app->queue->isWaiting($id) || Yii::$app->queue->isReserved($id)) {
68 1
            $status = 0;
69
        } elseif (Yii::$app->queue->isDone($id)) {
70
            $status = 1;
71
        } else {
72
            $status = -1;
73
        }
74 1
        return $status;
75
    }
76
}
77