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::insertRecordSets()   F
last analyzed

Complexity

Conditions 17
Paths 352

Size

Total Lines 46
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 25
nc 352
nop 1
dl 0
loc 46
rs 2.4833
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This file is part of the O2System 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\Framework\Models\NoSql\Traits;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Class TraitRecord
20
 *
21
 * @package O2System\Framework\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
    // ------------------------------------------------------------------------
50
51
    /**
52
     * @param $idUser
53
     * @return $this
54
     */
55
    protected function setRecordUser($idUser)
56
    {
57
        if (is_numeric($idUser)) {
58
            $this->recordUser = $idUser;
59
        }
60
61
        return $this;
62
    }
63
64
    // ------------------------------------------------------------------------
65
66
    /**
67
     * @param $status
68
     * @return $this
69
     */
70
    protected function setRecordStatus($status)
71
    {
72
        $status = strtoupper($status);
73
74
        if (in_array($status, ['UNPUBLISH', 'PUBLISH', 'DRAFT', 'DELETE', 'ARCHIVE'])) {
75
            $this->recordStatus = $status;
76
        }
77
78
        return $this;
79
    }
80
81
    // ------------------------------------------------------------------------
82
83
    /**
84
     * @param array $sets
85
     */
86
    protected function insertRecordSets(array &$sets)
87
    {
88
        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...
89
            if ($account = globals()->offsetGet('account')) {
90
                $this->recordUser = isset($account->id_user_account)
91
                    ? $account->id_user_account
92
                    : $account->id;
93
            }
94
        }
95
96
        $timestamp = $this->isUnixTimestamp === true ? strtotime(date('Y-m-d H:i:s')) : date('Y-m-d H:i:s');
97
98
        if ( ! isset($sets[ 'record_status' ])) {
99
            $sets[ 'record_status' ] = $this->recordStatus;
100
        }
101
102
        if (empty($this->primary_keys)) {
103
            $primary_key = isset($this->primary_key) ? $this->primary_key : 'id';
104
105
            if (empty($sets[ $primary_key ])) {
106
                if ( ! isset($sets[ 'record_create_user' ])) {
107
                    $sets[ 'record_create_user' ] = $this->recordUser;
108
                }
109
110
                if ( ! isset($sets[ 'record_create_timestamp' ])) {
111
                    $sets[ 'record_create_timestamp' ] = $timestamp;
112
                }
113
            }
114
        } else {
115
            foreach ($this->primary_keys as $primary_key) {
116
                if (empty($sets[ $primary_key ])) {
117
                    if ( ! isset($sets[ 'record_create_user' ])) {
118
                        $sets[ 'record_create_user' ] = $this->recordUser;
119
                    }
120
121
                    if ( ! isset($sets[ 'record_create_timestamp' ])) {
122
                        $sets[ 'record_create_timestamp' ] = $timestamp;
123
                    }
124
                }
125
            }
126
        }
127
128
        $sets[ 'record_update_user' ] = $this->recordUser;
129
130
        if ( ! isset($sets[ 'record_update_timestamp' ])) {
131
            $sets[ 'record_update_timestamp' ] = $timestamp;
132
        }
133
    }
134
135
    // ------------------------------------------------------------------------
136
137
    /**
138
     * @param array $sets
139
     */
140
    protected function updateRecordSets(array &$sets)
141
    {
142
        $sets[ 'record_status' ] = $this->recordStatus;
143
        $sets[ 'record_update_user' ] = $this->recordUser;
144
145
        $timestamp = $this->isUnixTimestamp === true ? strtotime(date('Y-m-d H:i:s')) : date('Y-m-d H:i:s');
146
147
        if ( ! isset($sets[ 'record_update_timestamp' ])) {
148
            $sets[ 'record_update_timestamp' ] = $timestamp;
149
        }
150
151
        if ($this->recordStatus === 'PUBLISH') {
152
            $sets[ 'record_delete_timestamp' ] = null;
153
            $sets[ 'record_delete_user' ] = null;
154
        }
155
    }
156
}