GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RecordTrait   A
last analyzed

Complexity

Total Complexity 25

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
c 1
b 0
f 0
dl 0
loc 109
rs 10
wmc 25

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setRecordUser() 0 7 2
A setRecordStatus() 0 9 2
F insertRecordSets() 0 46 17
A updateRecordSets() 0 14 4
1
<?php
2
/**
3
 * This file is part of the O2System PHP Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Reactor\Models\NoSql\Traits;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Class TraitRecord
20
 *
21
 * @package O2System\Reactor\Models\NoSql\Traits
22
 */
23
trait RecordTrait
24
{
25
    /**
26
     * Unix Timestamp Flag
27
     *
28
     * @access  protected
29
     * @type    bool
30
     */
31
    protected $isUnixTimestamp = false;
32
33
    /**
34
     * Default Record Status
35
     *
36
     * @access  protected
37
     * @type    string
38
     */
39
    protected $recordStatus = 'PUBLISH';
40
41
    /**
42
     * Default Record User
43
     *
44
     * @access  protected
45
     * @type    int
46
     */
47
    protected $recordUser = null;
48
49
    protected function setRecordUser($idUser)
50
    {
51
        if (is_numeric($idUser)) {
52
            $this->recordUser = $idUser;
53
        }
54
55
        return $this;
56
    }
57
58
    protected function setRecordStatus($status)
59
    {
60
        $status = strtoupper($status);
61
62
        if (in_array($status, ['UNPUBLISH', 'PUBLISH', 'DRAFT', 'DELETE', 'ARCHIVE'])) {
63
            $this->recordStatus = $status;
64
        }
65
66
        return $this;
67
    }
68
69
    protected function insertRecordSets(array &$sets)
70
    {
71
        if (is_null($this->recordUser) and function_exists('globals')) {
0 ignored issues
show
introduced by
The condition is_null($this->recordUser) is always false.
Loading history...
72
            if ($account = globals()->offsetGet('account')) {
73
                $this->recordUser = isset($account->id_user_account)
74
                    ? $account->id_user_account
75
                    : $account->id;
76
            }
77
        }
78
79
        $timestamp = $this->isUnixTimestamp === true ? strtotime(date('Y-m-d H:i:s')) : date('Y-m-d H:i:s');
80
81
        if ( ! isset($sets[ 'record_status' ])) {
82
            $sets[ 'record_status' ] = $this->recordStatus;
83
        }
84
85
        if (empty($this->primary_keys)) {
86
            $primary_key = isset($this->primary_key) ? $this->primary_key : 'id';
87
88
            if (empty($sets[ $primary_key ])) {
89
                if ( ! isset($sets[ 'record_create_user' ])) {
90
                    $sets[ 'record_create_user' ] = $this->recordUser;
91
                }
92
93
                if ( ! isset($sets[ 'record_create_timestamp' ])) {
94
                    $sets[ 'record_create_timestamp' ] = $timestamp;
95
                }
96
            }
97
        } else {
98
            foreach ($this->primary_keys as $primary_key) {
99
                if (empty($sets[ $primary_key ])) {
100
                    if ( ! isset($sets[ 'record_create_user' ])) {
101
                        $sets[ 'record_create_user' ] = $this->recordUser;
102
                    }
103
104
                    if ( ! isset($sets[ 'record_create_timestamp' ])) {
105
                        $sets[ 'record_create_timestamp' ] = $timestamp;
106
                    }
107
                }
108
            }
109
        }
110
111
        $sets[ 'record_update_user' ] = $this->recordUser;
112
113
        if ( ! isset($sets[ 'record_update_timestamp' ])) {
114
            $sets[ 'record_update_timestamp' ] = $timestamp;
115
        }
116
    }
117
118
    protected function updateRecordSets(array &$sets)
119
    {
120
        $sets[ 'record_status' ] = $this->recordStatus;
121
        $sets[ 'record_update_user' ] = $this->recordUser;
122
123
        $timestamp = $this->isUnixTimestamp === true ? strtotime(date('Y-m-d H:i:s')) : date('Y-m-d H:i:s');
124
125
        if ( ! isset($sets[ 'record_update_timestamp' ])) {
126
            $sets[ 'record_update_timestamp' ] = $timestamp;
127
        }
128
129
        if ($this->recordStatus === 'PUBLISH') {
130
            $sets[ 'record_delete_timestamp' ] = null;
131
            $sets[ 'record_delete_user' ] = null;
132
        }
133
    }
134
}