Page::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 1
1
<?php
2
3
namespace app\modules\page\models;
4
5
use Yii;
6
use yii\behaviors\TimestampBehavior;
7
use yii\db\ActiveRecord;
8
9
/**
10
 * This is the model class for table "pages".
11
 *
12
 * @property integer $id
13
 * @property string $key
14
 * @property string $title
15
 * @property string $content
16
 * @property string $description
17
 * @property string $created_at
18
 * @property string $updated_at
19
 */
20
class Page extends ActiveRecord
21
{
22
    /**
23
     * @inheritdoc
24
     */
25 4 View Code Duplication
    public function behaviors()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        return [
28
            'timestamp' => [
29 4
                'class' => TimestampBehavior::className(),
30
                'attributes' => [
31 4
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
32
                ],
33 4
                'value' => date('Y-m-d H:i:s'),
34 4
            ],
35
        ];
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41 6
    public static function tableName()
42
    {
43 6
        return 'pages';
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49 1
    public function rules()
50
    {
51
        return [
52 1
            [['created_at', 'updated_at'], 'safe'],
53
            [['content'], 'string'],
54
            ['title', 'string', 'max' => 64],
55
            [['key', 'description'], 'string', 'max' => 255],
56
            [['key'], 'unique'],
57
        ];
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63 3 View Code Duplication
    public function attributeLabels()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        return [
66 3
            'id' => Yii::t('page', 'ID'),
67 3
            'key' => Yii::t('page', 'Key'),
68 3
            'title' => Yii::t('page', 'Title'),
69 3
            'content' => Yii::t('page', 'Content'),
70 3
            'description' => Yii::t('page', 'Description'),
71 3
            'created_at' => Yii::t('page', 'Created At'),
72 3
            'updated_at' => Yii::t('page', 'Updated At'),
73
        ];
74
    }
75
76
    /**
77
     * Find page by key
78
     *
79
     * @param $key
80
     * @return $this|null
81
     */
82 3
    public static function findByKey($key)
83
    {
84 3
        return static::findOne(['key' => $key]);
85
    }
86
}
87