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.
Passed
Push — master ( 86dce3...98cf71 )
by Nur
02:40
created

RecordTrait::insertRecordSets()   F

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 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\Sql\Traits;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Class TraitRecord
20
 *
21
 * @package O2System\Reactor\Models\Sql\Traits
22
 */
23
trait RecordTrait
24
{
25
    /**
26
     * Unix Timestamp Flag
27
     *
28
     * @access  protected
29
     * @type    bool
30
     */
31
    protected $unixTimestamp = 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
     * Record Ordering Flag
51
     *
52
     * @var bool
53
     */
54
    protected $recordOrdering = false;
55
56
    protected function setRecordUser($idUser)
57
    {
58
        if (is_numeric($idUser)) {
59
            $this->recordUser = $idUser;
60
        }
61
62
        return $this;
63
    }
64
65
    protected function setRecordStatus($status)
66
    {
67
        $status = strtoupper($status);
68
69
        if (in_array($status, ['UNPUBLISH', 'PUBLISH', 'DRAFT', 'DELETE', 'ARCHIVE'])) {
70
            $this->recordStatus = $status;
71
        }
72
73
        return $this;
74
    }
75
76
    protected function insertRecordSets(array &$sets)
77
    {
78
        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...
79
            if ($account = globals()->offsetGet('account')) {
80
                $this->recordUser = isset($account->id_user_account)
81
                    ? $account->id_user_account
82
                    : $account->id;
83
            }
84
        }
85
86
        $timestamp = $this->unixTimestamp === true ? strtotime(date('Y-m-d H:i:s')) : date('Y-m-d H:i:s');
87
88
        if ( ! isset($sets[ 'record_status' ])) {
89
            $sets[ 'record_status' ] = $this->recordStatus;
90
        }
91
92
        if (empty($this->primary_keys)) {
93
            $primary_key = isset($this->primary_key) ? $this->primary_key : 'id';
94
95
            if (empty($sets[ $primary_key ])) {
96
                if ( ! isset($sets[ 'record_create_user' ])) {
97
                    $sets[ 'record_create_user' ] = $this->recordUser;
98
                }
99
100
                if ( ! isset($sets[ 'record_create_timestamp' ])) {
101
                    $sets[ 'record_create_timestamp' ] = $timestamp;
102
                }
103
            }
104
        } else {
105
            foreach ($this->primary_keys as $primary_key) {
106
                if (empty($sets[ $primary_key ])) {
107
                    if ( ! isset($sets[ 'record_create_user' ])) {
108
                        $sets[ 'record_create_user' ] = $this->recordUser;
109
                    }
110
111
                    if ( ! isset($sets[ 'record_create_timestamp' ])) {
112
                        $sets[ 'record_create_timestamp' ] = $timestamp;
113
                    }
114
                }
115
            }
116
        }
117
118
        $sets[ 'record_update_user' ] = $this->recordUser;
119
120
        if ( ! isset($sets[ 'record_update_timestamp' ])) {
121
            $sets[ 'record_update_timestamp' ] = $timestamp;
122
        }
123
    }
124
125
    protected function updateRecordSets(array &$sets)
126
    {
127
        $sets[ 'record_status' ] = $this->recordStatus;
128
        $sets[ 'record_update_user' ] = $this->recordUser;
129
130
        $timestamp = $this->unixTimestamp === true ? strtotime(date('Y-m-d H:i:s')) : date('Y-m-d H:i:s');
131
132
        if ( ! isset($sets[ 'record_update_timestamp' ])) {
133
            $sets[ 'record_update_timestamp' ] = $timestamp;
134
        }
135
136
        if ($this->recordStatus === 'PUBLISH') {
137
            $sets[ 'record_delete_timestamp' ] = null;
138
            $sets[ 'record_delete_user' ] = null;
139
        }
140
    }
141
142
    /**
143
     * Process Row Ordering
144
     *
145
     * @access  public
146
     */
147
    protected function getRecordOrdering($table = null)
148
    {
149
        $table = isset($table) ? $table : $this->table;
150
151
        return $this->qb->countAllResults($table) + 1;
152
    }
153
}