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

Intermediary::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 5
dl 0
loc 22
rs 10
c 0
b 0
f 0
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\Relations\Maps;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Reactor\Models\Sql\Model;
19
20
/**
21
 * Class Intermediate
22
 *
23
 * @package O2System\Reactor\Models\Sql\Relations\Maps
24
 */
25
class Intermediary
26
{
27
    /**
28
     * Relation Model
29
     *
30
     * @var Model
31
     */
32
    public $relationModel;
33
34
    /**
35
     * Relation Table
36
     *
37
     * @var string
38
     */
39
    public $relationTable;
40
41
    /**
42
     * Relation Primary Key
43
     *
44
     * @var string
45
     */
46
    public $relationPrimaryKey;
47
48
    /**
49
     * Reference Table
50
     *
51
     * @var string
52
     */
53
    public $referenceTable;
54
55
    /**
56
     * Reference Primary Key
57
     *
58
     * @var string
59
     */
60
    public $referencePrimaryKey;
61
62
    /**
63
     * Pivot Table
64
     *
65
     * @var string
66
     */
67
    public $pivotTable;
68
69
    /**
70
     * Pivot Relation Key
71
     *
72
     * @var string
73
     */
74
    public $pivotRelationKey;
75
76
    /**
77
     * Pivot Reference Key
78
     *
79
     * @var string
80
     */
81
    public $pivotReferenceKey;
82
83
    // ------------------------------------------------------------------------
84
85
    /**
86
     * IntermediateMapper constructor.
87
     *
88
     * @param Model        $relationModel
89
     * @param string|Model $referenceModel
90
     * @param string|Model $intermediateModel
91
     * @param string|null  $pivotTable
92
     * @param string|null  $relationForeignKey
93
     * @param string|null  $referencePrimaryKey
94
     */
95
    public function __construct(
96
        Model $relationModel,
97
        $referenceModel,
98
        $pivotTable = null,
99
        $relationForeignKey = null,
0 ignored issues
show
Unused Code introduced by
The parameter $relationForeignKey is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

99
        /** @scrutinizer ignore-unused */ $relationForeignKey = null,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
        $referencePrimaryKey = null
0 ignored issues
show
Unused Code introduced by
The parameter $referencePrimaryKey is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

100
        /** @scrutinizer ignore-unused */ $referencePrimaryKey = null

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
    ) {
102
        // Map Relation Model
103
        $this->mapRelationModel($relationModel);
104
105
        // Map Reference Model
106
        $this->mapReferenceModel($referenceModel);
107
108
        // Map Intermediate Table
109
        $this->pivotTable = $this->relationTable . '_' . $this->referenceTable;
110
111
        if (isset($pivotTable)) {
112
            $this->pivotTable = $pivotTable;
113
        }
114
115
        $this->pivotRelationKey = $this->pivotTable . '.' . $this->pivotRelationKey;
116
        $this->pivotReferenceKey = $this->pivotTable . '.' . $this->pivotReferenceKey;
117
    }
118
119
    // ------------------------------------------------------------------------
120
121
    /**
122
     * Map Relation Model
123
     *
124
     * @param string|Model $relationModel
125
     *
126
     * @return void
127
     */
128
    private function mapRelationModel($relationModel)
129
    {
130
        if ($relationModel instanceof Model) {
131
            $this->relationModel = $relationModel;
132
            $this->relationTable = $this->relationModel->table;
133
            $this->relationPrimaryKey = $this->relationModel->primaryKey;
134
            $this->pivotRelationKey = $this->relationModel->primaryKey . '_' . $this->relationModel->table;
135
        } elseif (class_exists($relationModel)) {
136
            $this->relationModel = new $relationModel();
137
            $this->relationTable = $this->relationModel->table;
138
            $this->relationPrimaryKey = $this->relationModel->table . '.' . $this->relationModel->primaryKey;
139
            $this->pivotRelationKey = $this->relationModel->primaryKey . '_' . $this->relationModel->table;
140
        } else {
141
            $this->relationTable = $relationModel;
142
            $this->relationPrimaryKey = $this->relationTable . '.id';
143
            $this->pivotRelationKey = $this->relationTable . '.id_' . $this->relationTable;
144
        }
145
    }
146
147
    // ------------------------------------------------------------------------
148
149
    /**
150
     * Map Relation Model
151
     *
152
     * @param string|Model $referenceModel
153
     *
154
     * @return void
155
     */
156
    private function mapReferenceModel($referenceModel)
157
    {
158
        if ($referenceModel instanceof Model) {
159
            $this->referenceTable = $referenceModel->table;
160
            $this->referencePrimaryKey = $referenceModel->primaryKey;
161
            $this->pivotReferenceKey = $referenceModel->primaryKey . '_' . $this->referenceTable;
162
        } elseif (class_exists($referenceModel)) {
163
            $referenceModel = new $referenceModel();
164
            $this->referenceTable = $referenceModel->table;
165
            $this->referencePrimaryKey = $this->referenceTable . '.' . $referenceModel->primaryKey;
166
            $this->pivotReferenceKey = $referenceModel->primaryKey . '_' . $this->referenceTable;
167
        } else {
168
            $this->referenceTable = $referenceModel;
169
            $this->referencePrimaryKey = $this->referenceTable . '.id';
170
            $this->pivotReferenceKey = 'id_' . $this->referenceTable;
171
        }
172
    }
173
}