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 ( cf9260...b52382 )
by
unknown
03:19
created

RecordTrait::insertRecordSets()   F

Complexity

Conditions 18
Paths 516

Size

Total Lines 50
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 18
eloc 29
nc 516
nop 1
dl 0
loc 50
rs 1.3722
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\Sql\Traits;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Class TraitRecord
20
 *
21
 * @package O2System\Framework\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
    public function setRecordUser($idUser)
57
    {
58
        if (is_numeric($idUser)) {
59
            $this->recordUser = $idUser;
60
        }
61
62
        return $this;
63
    }
64
65
    public function setRecordStatus($status)
66
    {
67
        $status = strtoupper($status);
68
69
        if (in_array($status, ['UNPUBLISH', 'PUBLISH', 'DRAFT', 'DELETED', 'ARCHIVED'])) {
70
            $this->recordStatus = $status;
71
        }
72
73
        return $this;
74
    }
75
76
    protected function insertRecordSets(array &$sets)
77
    {
78
        $timestamp = $this->unixTimestamp === true ? strtotime(date('Y-m-d H:i:s')) : date('Y-m-d H:i:s');
79
80
        if ( ! isset($sets[ 'record_status' ])) {
81
            $sets[ 'record_status' ] = $this->recordStatus;
82
        }
83
84
        if (empty($this->primaryKeys)) {
85
            $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';
86
87
            if (isset($sets[ $primaryKey ])) {
88
                if (empty($sets[ $primaryKey ])) {
89
                    unset($sets[ $primaryKey ]);
90
                }
91
            }
92
93
            if (empty($sets[ $primaryKey ])) {
94
                if ( ! isset($sets[ 'record_create_user' ])) {
95
                    $sets[ 'record_create_user' ] = $this->recordUser;
96
                }
97
98
                if ( ! isset($sets[ 'record_create_timestamp' ])) {
99
                    $sets[ 'record_create_timestamp' ] = $timestamp;
100
                } elseif ($this->unixTimestamp) {
101
                    $sets[ 'record_create_timestamp' ] = strtotime($sets[ 'record_create_timestamp' ]);
102
                }
103
            }
104
        } else {
105
            foreach ($this->primaryKeys as $primaryKey) {
106
                if (empty($sets[ $primaryKey ])) {
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
                    } elseif ($this->unixTimestamp) {
114
                        $sets[ 'record_create_timestamp' ] = strtotime($sets[ 'record_create_timestamp' ]);
115
                    }
116
                }
117
            }
118
        }
119
120
        $sets[ 'record_update_user' ] = $this->recordUser;
121
122
        if ( ! isset($sets[ 'record_update_timestamp' ])) {
123
            $sets[ 'record_update_timestamp' ] = $timestamp;
124
        } elseif ($this->unixTimestamp) {
125
            $sets[ 'record_update_timestamp' ] = strtotime($sets[ 'record_update_timestamp' ]);
126
        }
127
    }
128
129
    protected function updateRecordSets(array &$sets)
130
    {
131
        $sets[ 'record_status' ] = $this->recordStatus;
132
        $sets[ 'record_update_user' ] = $this->recordUser;
133
134
        $timestamp = $this->unixTimestamp === true ? strtotime(date('Y-m-d H:i:s')) : date('Y-m-d H:i:s');
135
136
        if ( ! isset($sets[ 'record_update_timestamp' ])) {
137
            $sets[ 'record_update_timestamp' ] = $timestamp;
138
        }
139
    }
140
141
    /**
142
     * Process Row Ordering
143
     *
144
     * @access  public
145
     */
146
    protected function getRecordOrdering($table = null)
147
    {
148
        $table = isset($table) ? $table : $this->table;
149
150
        return $this->qb->countAllResults($table) + 1;
151
    }
152
}