Completed
Push — master ( 497ac1...5e4638 )
by Klochok
07:14
created

Reminder::getObjectName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 0
loc 13
ccs 0
cts 12
cp 0
crap 12
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace hipanel\models;
4
5
use hipanel\base\Model;
6
use hipanel\base\ModelTrait;
7
use Yii;
8
9
class Reminder extends Model
10
{
11
    use ModelTrait;
12
13
    public static $i18nDictionary = 'hipanel/reminder';
14
15
    const REMINDER_SCENARIO_CREATE = 'create';
16
    const REMINDER_SCENARIO_UPDATE = 'update';
17
    const REMINDER_SCENARIO_DELETE = 'delete';
18
19
    const REMINDER_TYPE_SITE = 'site';
20
    const REMINDER_TYPE_MAIL = 'mail';
21
22
    public static function reminderNextTimeOptions()
23
    {
24
        return [
25
            '15 minutes' => Yii::t('hipanel/reminder', '15m'),
26
            '30 minutes' => Yii::t('hipanel/reminder', '30m'),
27
            '1 hour' => Yii::t('hipanel/reminder', '1h'),
28
            '12 hour' => Yii::t('hipanel/reminder', '12h'),
29
            '1 day' => Yii::t('hipanel/reminder', '1d'),
30
        ];
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function rules()
37
    {
38
        return [
39
            [['id', 'object_id', 'client_id', 'state_id', 'type_id'], 'integer'],
40
            [['class', 'periodicity', 'from_time', 'till_time', 'next_time'], 'string'],
41
            [['to_site'], 'boolean'],
42
43
            // Create
44
            [['object_id', 'type', 'periodicity', 'from_time', 'message'], 'required', 'on' => self::REMINDER_SCENARIO_CREATE],
45
46
            // Update
47
            [['id'], 'required', 'on' => 'update'],
48
            [['object_id', 'state_id', 'type_id'], 'integer', 'on' => self::REMINDER_SCENARIO_UPDATE],
49
            [['from_time', 'next_time', 'till_time'], 'date', 'on' => self::REMINDER_SCENARIO_UPDATE],
50
51
            // Delete
52
            [['id'], 'required', 'on' => self::REMINDER_SCENARIO_DELETE]
53
        ];
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function attributeLabels()
60
    {
61
        return $this->mergeAttributeLabels([
62
            'periodicity' => Yii::t('hipanel/reminder', 'Periodicity'),
63
            'from_time' => Yii::t('hipanel/reminder', 'When the recall?'),
64
            'next_time' => Yii::t('hipanel/reminder', 'Next remind'),
65
            'till_time' => Yii::t('hipanel/reminder', 'Remind till'),
66
            'message' => Yii::t('hipanel/reminder', 'Message'),
67
        ]);
68
    }
69
70
    public function getObjectName()
71
    {
72
        $result = '';
73
        if ($this->class) {
0 ignored issues
show
Documentation introduced by
The property class does not exist on object<hipanel\models\Reminder>. 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...
74
            switch ($this->class) {
0 ignored issues
show
Documentation introduced by
The property class does not exist on object<hipanel\models\Reminder>. 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...
75
                case 'thread':
76
                    $result = 'ticket';
77
                    break;
78
            }
79
        }
80
81
        return $result;
82
    }
83
}
84