Test Failed
Pull Request — master (#5)
by Anton
02:48
created

Notification   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 7 1
A behaviors() 0 10 1
A getNotifiable() 0 4 1
1
<?php
2
3
4
namespace tuyakhov\notifications\models;
5
6
7
use tuyakhov\notifications\behaviors\ReadableBehavior;
8
use yii\behaviors\TimestampBehavior;
9
use yii\db\ActiveRecord;
10
use yii\db\Expression;
11
12
/**
13
 * Database notification model
14
 * @property $level string
15
 * @property $subject string
16
 * @property $notifiable_type string
17
 * @property $notifiable_id int
18
 * @property $body string
19
 * @property $read_at string
20
 * @property $notifiable
21
 * @method  void markAsRead()
22
 * @method  void markAsUnread()
23
 * @method  bool read()
24
 * @method  bool unread()
25
 */
26
class Notification extends ActiveRecord
27
{
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function rules()
33
    {
34
        return [
35
            [['level', 'notifiable_type', 'subject', 'body'], 'string'],
36
            ['notifiable_id', 'integer'],
37
        ];
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function behaviors()
44
    {
45
        return [
46
            [
47
                '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...
48
                'value' => new Expression('NOW()'),
49
            ],
50
            ReadableBehavior::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...
51
        ];
52
    }
53
54
    public function getNotifiable()
55
    {
56
        return $this->hasOne($this->notifiable_type, ['id' => 'notifiable_id']);
0 ignored issues
show
Documentation introduced by
The property notifiable_type does not exist on object<tuyakhov\notifica...ns\models\Notification>. 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...
Coding Style introduced by
Variable "notifiable_type" is not in valid camel caps format
Loading history...
57
    }
58
}