SsoData::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9
1
<?php
2
/**
3
 * Vanillaforums plugin for Craft CMS 3.x
4
 *
5
 * Single Sign On plugin for VanillaForums/jsConnect and CraftCMS
6
 *
7
 * @link      https://nystudio107.com/
8
 * @copyright Copyright (c) 2019 nystudio107
9
 */
10
11
namespace nystudio107\vanillaforums\models;
12
13
use nystudio107\vanillaforums\Vanillaforums;
14
15
use craft\base\Model;
16
use craft\behaviors\EnvAttributeParserBehavior;
17
18
use yii\behaviors\AttributeTypecastBehavior;
19
20
/**
21
 * @author    nystudio107
22
 * @package   Vanillaforums
23
 * @since     3.0.0
24
 */
25
class SsoData extends Model
26
{
27
    // Public Properties
28
    // =========================================================================
29
30
    /**
31
     * @var int Unique ID for this user
32
     */
33
    public $uniqueid;
34
35
    /**
36
     * @var string Display name for this user
37
     */
38
    public $name;
39
40
    /**
41
     * @var string Email address for this user
42
     */
43
    public $email;
44
45
    /**
46
     * @var string Ootional comma-delimited roles for this user
47
     */
48
    public $roles;
49
50
    /**
51
     * @var string URL to a photo for this user
52
     */
53
    public $photourl;
54
55
    // Public Methods
56
    // =========================================================================
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function rules()
62
    {
63
        return [
64
            [['uniqueid'], 'integer'],
65
            [['uniqueid'], 'default', 'value' => 0],
66
            [['name'], 'string'],
67
            [['name'], 'default', 'value' => ''],
68
            [['email'], 'email'],
69
            [['email'], 'default', 'value' => ''],
70
            [['roles'], 'string'],
71
            [['roles'], 'default', 'value' => ''],
72
            [['photourl'], 'url'],
73
            [['photourl'], 'default', 'value' => ''],
74
        ];
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80
    public function behaviors()
81
    {
82
        // Keep any parent behaviors
83
        $behaviors = parent::behaviors();
84
        // Add in the AttributeTypecastBehavior
85
        $behaviors['typecast'] = [
86
            'class' => AttributeTypecastBehavior::class,
87
            // 'attributeTypes' will be composed automatically according to `rules()`
88
        ];
89
        // If we're running Craft 3.1 or later, add in the EnvAttributeParserBehavior
90
        if (Vanillaforums::$craft31) {
91
            $behaviors['parser'] = [
92
                'class' => EnvAttributeParserBehavior::class,
93
                'attributes' => [
94
                ],
95
            ];
96
        }
97
98
        return $behaviors;
99
    }
100
}
101