Passed
Push — master ( 758032...380927 )
by Benjamin
28:34 queued 21:24
created

Info::init()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link      https://dukt.net/craft/analytics/
4
 * @copyright Copyright (c) 2018, Dukt
5
 * @license   https://dukt.net/craft/analytics/docs/license
6
 */
7
8
namespace dukt\analytics\models;
9
10
use craft\base\Model;
11
use craft\helpers\Json;
12
13
class Info extends Model
14
{
15
    // Properties
16
    // =========================================================================
17
18
    /**
19
     * @var int|null ID
20
     */
21
    public $id;
22
23
    /**
24
     * @var bool Force connect
25
     */
26
    public $forceConnect = false;
27
28
    /**
29
     * @var string|null Token
30
     */
31
    public $token;
32
33
    /**
34
     * @var \DateTime|null Date updated
35
     */
36
    public $dateUpdated;
37
38
    /**
39
     * @var \DateTime|null Date created
40
     */
41
    public $dateCreated;
42
43
    /**
44
     * @var string|null Uid
45
     */
46
    public $uid;
47
48
    // Public Methods
49
    // =========================================================================
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function init()
55
    {
56
        parent::init();
57
58
        // Make sure $forceConnect is going to be a boolean
59
        if (is_string($this->forceConnect)) {
0 ignored issues
show
introduced by
The condition is_string($this->forceConnect) is always false.
Loading history...
60
            $this->forceConnect = (bool)$this->forceConnect;
61
        }
62
63
        if (is_string($this->token)) {
64
            $this->token = Json::decode($this->token);
65
        }
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71
    public function rules()
72
    {
73
        return [
74
            [['id', 'edition'], 'number', 'integerOnly' => true],
75
        ];
76
    }
77
}
78