Completed
Push — master ( 0ada32...f780f4 )
by graychen
02:30 queued 51s
created

Queue::tableName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
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(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
28
            ]
29 6
        ];
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 4
    public function rules()
36
    {
37
        return [
38 4
            [['queue_id', 'catalog', 'name', 'description'], 'required']
39 4
        ];
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 2
        ];
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)) {
68 1
            $status = 0;
69 1
        } elseif (Yii::$app->queue->isReserved($id)) {
70
            $status = 2;
71
        } elseif (Yii::$app->queue->isDone($id)) {
72
            $status = 1;
73
        } else {
74
            $status = -1;
75
        }
76 1
        return $status;
77
    }
78
}
79